private View getStartView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper)
      {
          var linearLayoutManager = (LinearLayoutManager)layoutManager;

          var firstChildIndex = linearLayoutManager.FindFirstVisibleItemPosition();

          if (firstChildIndex == RecyclerView.NoPosition)
          {
              return(null);
          }

          subject.OnNext(linearLayoutManager.FindFirstCompletelyVisibleItemPosition() + 1);
          var lastItemIndex = linearLayoutManager.ItemCount - 1;
          var isLastItem    = linearLayoutManager.FindLastCompletelyVisibleItemPosition() == lastItemIndex;

          if (isLastItem)
          {
              return(null);
          }

          var firstView    = layoutManager.FindViewByPosition(firstChildIndex);
          var decoratedEnd = helper.GetDecoratedEnd(firstView);
          var threshold    = helper.GetDecoratedMeasurement(firstView) / 2;

          if (decoratedEnd >= threshold && decoratedEnd > 0)
          {
              return(firstView);
          }

          return(layoutManager.FindViewByPosition(firstChildIndex + 1));
      }
Exemplo n.º 2
0
        public override void CollectAdjacentPrefetchPositions(int dx, int dy, RecyclerView.State state, ILayoutPrefetchRegistry layoutPrefetchRegistry)
        {
            try
            {
                base.CollectAdjacentPrefetchPositions(dx, dy, state, layoutPrefetchRegistry);

                int delta = Orientation == Horizontal ? dx : dy;
                if (ChildCount == 0 || delta == 0)
                {
                    return;
                }

                int  layoutDirection = delta > 0 ? 1 : -1;
                View child           = GetChildClosest(layoutDirection);
                int  currentPosition = GetPosition(child) + layoutDirection;
                int  scrollingOffset;

                if (layoutDirection == 1)
                {
                    scrollingOffset = MOrientationHelper.GetDecoratedEnd(child) - MOrientationHelper.EndAfterPadding;
                    for (int i = currentPosition + 1; i < currentPosition + MAdditionalAdjacentPrefetchItemCount + 1; i++)
                    {
                        if (i >= 0 && i < state.ItemCount)
                        {
                            layoutPrefetchRegistry.AddPosition(i, Java.Lang.Math.Max(0, scrollingOffset));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Exemplo n.º 3
0
            public void AssignFromView(View referenceChild, int position)
            {
                Coordinate = LayoutFillingStartsFromEnd
                    ? OrientationHelper.GetDecoratedEnd(referenceChild) + OrientationHelper.TotalSpaceChange
                    : OrientationHelper.GetDecoratedStart(referenceChild);

                Position = position;
            }
Exemplo n.º 4
0
        protected override int VisiblePortion(AView view, OrientationHelper orientationHelper, bool rtl)
        {
            if (rtl)
            {
                return(orientationHelper.TotalSpace - orientationHelper.GetDecoratedStart(view));
            }

            return(orientationHelper.GetDecoratedEnd(view));
        }
        private View GetStartView(
            RecyclerView.LayoutManager layoutManager,
            OrientationHelper helper,
            out int viewPosition)
        {
            viewPosition = -1;
            if (!(layoutManager is LinearLayoutManager manager))
            {
                return(base.FindSnapView(layoutManager));
            }

            int firstChild = manager.FindFirstVisibleItemPosition();

            bool isLastItem = manager.FindLastCompletelyVisibleItemPosition() == layoutManager.ItemCount - 1;

            if (isLastItem)
            {
                if (WeakNativeView.TryGetTarget(out var target))
                {
                    target.CurrentSnapIndex = layoutManager.ItemCount - 1;

                    // System.Diagnostics.Debug.WriteLine($">>>>>> CurrentSnapIndex: {target.CurrentSnapIndex}");
                }

                return(null);
            }

            if (firstChild == RecyclerView.NoPosition)
            {
                return(null);
            }

            View child = layoutManager.FindViewByPosition(firstChild);

            if (helper.GetDecoratedEnd(child) >= helper.GetDecoratedMeasurement(child) / 2 &&
                helper.GetDecoratedEnd(child) > 0)
            {
                viewPosition = firstChild;
                return(child);
            }

            viewPosition = firstChild + 1;
            return(layoutManager.FindViewByPosition(firstChild + 1));
        }
Exemplo n.º 6
0
        private View GetStartView(
            RecyclerView.LayoutManager layoutManager,
            OrientationHelper helper,
            out int viewPosition)
        {
            viewPosition = -1;
            if (!(layoutManager is LinearLayoutManager manager))
            {
                return(base.FindSnapView(layoutManager));
            }

            int firstChild = manager.FindFirstVisibleItemPosition();

            bool isLastItem = manager.FindLastCompletelyVisibleItemPosition() == layoutManager.ItemCount - 1;

            if (firstChild == RecyclerView.NoPosition || isLastItem)
            {
                return(null);
            }

            View child = layoutManager.FindViewByPosition(firstChild);

            if (helper.GetDecoratedEnd(child) >= helper.GetDecoratedMeasurement(child) / 2 &&
                helper.GetDecoratedEnd(child) > 0)
            {
                viewPosition = firstChild;
                return(child);
            }

            if (manager.FindLastCompletelyVisibleItemPosition() == layoutManager.ItemCount - 1)
            {
                return(null);
            }

            viewPosition = firstChild + 1;
            return(layoutManager.FindViewByPosition(firstChild + 1));
        }