public override int FindTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) { if (CurrentTargetPosition == -1) { CurrentTargetPosition = base.FindTargetSnapPosition(layoutManager, velocityX, velocityY); return(CurrentTargetPosition); } var increment = 1; if (layoutManager.CanScrollHorizontally()) { if (velocityX < 0) { increment = -1; } } else if (layoutManager.CanScrollVertically()) { if (velocityY < 0) { increment = -1; } } if (IsLayoutReversed(layoutManager)) { increment = increment * -1; } CurrentTargetPosition = CurrentTargetPosition + increment; return(CurrentTargetPosition); }
public override int[] CalculateDistanceToFinalSnap(RecyclerView.LayoutManager layoutManager, AView targetView) { var orientationHelper = CreateOrientationHelper(layoutManager); var isHorizontal = layoutManager.CanScrollHorizontally(); var rtl = isHorizontal && IsLayoutReversed(layoutManager); var distance = rtl ? -orientationHelper.GetDecoratedStart(targetView) : orientationHelper.TotalSpace - orientationHelper.GetDecoratedEnd(targetView); return(isHorizontal ? new[] { -distance, 1 } : new[] { 1, -distance }); }
protected bool IsAtLeastHalfVisible(AView view, RecyclerView.LayoutManager layoutManager) { var orientationHelper = CreateOrientationHelper(layoutManager); var reversed = IsLayoutReversed(layoutManager); var isHorizontal = layoutManager.CanScrollHorizontally(); // Find the size of the view (including margins, etc.) var size = orientationHelper.GetDecoratedMeasurement(view); var portionInViewPort = VisiblePortion(view, orientationHelper, reversed && isHorizontal); // Is the first visible view at least halfway on screen? return(portionInViewPort >= size / 2); }
public override int[] CalculateDistanceToFinalSnap(RecyclerView.LayoutManager layoutManager, View targetView) { int[] result = new int[2]; result[0] = layoutManager.CanScrollHorizontally() ? DistanceToStart(targetView, GetHorizontalHelper(layoutManager)) : 0; result[1] = layoutManager.CanScrollVertically() ? DistanceToStart(targetView, GetVerticalHelper(layoutManager)) : 0; return(result); }
public override int FindTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) { var itemCount = layoutManager.ItemCount; //reset CurrentTargetPosition if ItemCount Changed is requested //We could be adding a item before the CurrentTargetPosition if (_previousCount != itemCount) { CurrentTargetPosition = -1; _previousCount = itemCount; } if (CurrentTargetPosition == -1) { CurrentTargetPosition = base.FindTargetSnapPosition(layoutManager, velocityX, velocityY); return(CurrentTargetPosition); } var increment = 1; if (layoutManager.CanScrollHorizontally()) { if (velocityX < 0) { increment = -1; } } else if (layoutManager.CanScrollVertically()) { if (velocityY < 0) { increment = -1; } } if (IsLayoutReversed(layoutManager)) { increment *= -1; } if (CurrentTargetPosition == itemCount - 1 && increment == 1) { return(CurrentTargetPosition); } CurrentTargetPosition = CurrentTargetPosition + increment; return(CurrentTargetPosition); }
public override View FindSnapView(RecyclerView.LayoutManager layoutManager) { if (!(layoutManager is LinearLayoutManager)) { return(base.FindSnapView(layoutManager)); } OrientationHelper helper = layoutManager.CanScrollHorizontally() ? GetHorizontalHelper(layoutManager) : GetVerticalHelper(layoutManager); var startView = GetStartView(layoutManager, helper, out int viewPosition); // System.Diagnostics.Debug.WriteLine($"DEBUG_SCROLL: FindSnapView ( viewPosition: {viewPosition} )"); return(startView); }
protected int[] CalculateDistanceToFinalSnap(RecyclerView.LayoutManager layoutManager, AView targetView, int direction = 1) { var orientationHelper = CreateOrientationHelper(layoutManager); var isHorizontal = layoutManager.CanScrollHorizontally(); var rtl = isHorizontal && IsLayoutReversed(layoutManager); var size = orientationHelper.GetDecoratedMeasurement(targetView); var hiddenPortion = size - VisiblePortion(targetView, orientationHelper, rtl); var distance = (rtl ? hiddenPortion : -hiddenPortion) * direction; return(isHorizontal ? new[] { distance, 1 } : new[] { 1, distance }); }
public override View FindSnapView(RecyclerView.LayoutManager layoutManager) { if (!(layoutManager is LinearLayoutManager)) { return(base.FindSnapView(layoutManager)); } OrientationHelper helper = layoutManager.CanScrollHorizontally() ? GetHorizontalHelper(layoutManager) : GetVerticalHelper(layoutManager); var startView = GetStartView(layoutManager, helper, out int viewPosition); InternalLogger.Info($"FindSnapView ( viewPosition: {viewPosition} )"); ReleaseIsBusy(startView); return(startView); }
protected static OrientationHelper CreateOrientationHelper(RecyclerView.LayoutManager layoutManager) { return(layoutManager.CanScrollHorizontally() ? OrientationHelper.CreateHorizontalHelper(layoutManager) : OrientationHelper.CreateVerticalHelper(layoutManager)); }