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));
      }
        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));
        }
Esempio n. 3
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));
        }