+ internal bool IsChildNearlyVisble(View child, float offset = 0)
+ {
+ if (ScreenPosition.X - offset < child.ScreenPosition.X + child.SizeWidth &&
+ ScreenPosition.X + SizeWidth + offset > child.ScreenPosition.X &&
+ ScreenPosition.Y - offset < child.ScreenPosition.Y + child.SizeHeight &&
+ ScreenPosition.Y + SizeHeight + offset > child.ScreenPosition.Y)
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override View GetNextFocusableView(View currentFocusedView, View.FocusDirection direction, bool loopEnabled)
+ {
+ bool isHorizontal = (ScrollingDirection == Direction.Horizontal);
+ float targetPosition = -(ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
+ float stepDistance = (stepScrollDistance != 0 ? stepScrollDistance : (isHorizontal ? Size.Width * 0.25f : Size.Height * 0.25f));
+
+ bool forward = ((isHorizontal && direction == View.FocusDirection.Right) ||
+ (!isHorizontal && direction == View.FocusDirection.Down) ||
+ (direction == View.FocusDirection.Clockwise));
+ bool backward = ((isHorizontal && direction == View.FocusDirection.Left) ||
+ (!isHorizontal && direction == View.FocusDirection.Up) ||
+ (direction == View.FocusDirection.CounterClockwise));
+
+ View nextFocusedView = FocusManager.Instance.GetNearestFocusableActor(this, currentFocusedView, direction);
+
+ // Move out focus from ScrollableBase.
+ // FIXME: Forward, Backward is unimplemented other components.
+ if (direction == View.FocusDirection.Forward ||
+ direction == View.FocusDirection.Backward ||
+ (nextFocusedView == null &&
+ ((forward && maxScrollDistance - targetPosition < 0.1f) ||
+ (backward && targetPosition < 0.1f))))
+ {
+ var next = FocusManager.Instance.GetNearestFocusableActor(this.Parent, this, direction);
+ Debug.WriteLineIf(focusDebugScrollableBase, $"Focus move [{direction}] out from ScrollableBase! Next focus target {next}:{next?.ID}");
+ return next;
+ }
+
+ if (focusDebugScrollableBase)
+ {
+ global::System.Text.StringBuilder debugMessage = new global::System.Text.StringBuilder("=========================================================\n");
+ debugMessage.Append($"GetNextFocusableView On: {this}:{this.ID}\n");
+ debugMessage.Append($"----------------Current: {currentFocusedView}:{currentFocusedView?.ID}\n");
+ debugMessage.Append($"-------------------Next: {nextFocusedView}:{nextFocusedView?.ID}\n");
+ debugMessage.Append($"--------------Direction: {direction}\n");
+ debugMessage.Append("=========================================================");
+ Debug.WriteLineIf(focusDebugScrollableBase, debugMessage);
+ }
+
+ if (nextFocusedView != null)
+ {
+ if (null != FindDescendantByID(nextFocusedView.ID))
+ {
+ if (IsChildNearlyVisble(nextFocusedView, stepDistance) == true)
+ {
+ ScrollToChild(nextFocusedView, true);
+ return nextFocusedView;
+ }
+ }
+ }
+
+ if (forward || backward)
+ {
+ // Fallback to current focus or scrollableBase till next focus visible in scrollable.
+ if (null != currentFocusedView && null != FindDescendantByID(currentFocusedView.ID))
+ {
+ nextFocusedView = currentFocusedView;
+ }
+ else
+ {
+ Debug.WriteLineIf(focusDebugScrollableBase, "current focus view is not decendant. return ScrollableBase!");
+ return this;
+ }
+
+ if (forward)
+ {
+ targetPosition += stepDistance;
+ targetPosition = targetPosition > maxScrollDistance ? maxScrollDistance : targetPosition;
+
+ }
+ else if (backward)
+ {
+ targetPosition -= stepDistance;
+ targetPosition = targetPosition < 0 ? 0 : targetPosition;
+ }
+
+ ScrollTo(targetPosition, true);
+
+ Debug.WriteLineIf(focusDebugScrollableBase, $"ScrollTo :({targetPosition})");
+ }
+
+ Debug.WriteLineIf(focusDebugScrollableBase, $"return end : {nextFocusedView}:{nextFocusedView?.ID}");
+ return nextFocusedView;
+ }
+
+ /// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ protected override bool AccessibilityScrollToChild(View child)
+ {
+ if (child == null)
+ {
+ return false;
+ }
+
+ if (ScrollingDirection == Direction.Horizontal)
+ {
+ if (child.ScreenPosition.X + child.Size.Width <= this.ScreenPosition.X)
+ {
+ if (SnapToPage)
+ {
+ PageSnap(PageFlickThreshold + 1);
+ }
+ else
+ {
+ ScrollTo((float)(child.ScreenPosition.X - ContentContainer.ScreenPosition.X), false);
+ }
+ }
+ else if (child.ScreenPosition.X >= this.ScreenPosition.X + this.Size.Width)
+ {
+ if (SnapToPage)
+ {
+ PageSnap(-(PageFlickThreshold + 1));
+ }
+ else
+ {
+ ScrollTo((float)(child.ScreenPosition.X + child.Size.Width - ContentContainer.ScreenPosition.X - this.Size.Width), false);
+ }
+ }
+ }
+ else
+ {
+ if (child.ScreenPosition.Y + child.Size.Height <= this.ScreenPosition.Y)
+ {
+ if (SnapToPage)
+ {
+ PageSnap(PageFlickThreshold + 1);
+ }
+ else
+ {
+ ScrollTo((float)(child.ScreenPosition.Y - ContentContainer.ScreenPosition.Y), false);
+ }
+ }
+ else if (child.ScreenPosition.Y >= this.ScreenPosition.Y + this.Size.Height)
+ {
+ if (SnapToPage)
+ {
+ PageSnap(-(PageFlickThreshold + 1));
+ }
+ else
+ {
+ ScrollTo((float)(child.ScreenPosition.Y + child.Size.Height - ContentContainer.ScreenPosition.Y - this.Size.Height), false);
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /// <inheritdoc/>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public override bool OnWheel(Wheel wheel)
+ {
+ if (wheel == null)
+ {
+ return false;
+ }
+
+ float currentScrollPosition = -(ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
+ ScrollTo(currentScrollPosition + (wheelScrollDistance * wheel.Z), false);
+
+ return true;
+ }
+
+ private bool OnWheelEvent(object o, WheelEventArgs e)
+ {
+ return OnWheel(e?.Wheel);
+ }