protected override void ScrollTo(ScrollToRequestEventArgs args)
        {
            var position = DetermineTargetPosition(args);

            if (_carouselViewLoopManager == null)
            {
                return;
            }
            //Special case here
            //We could have a race condition where we are scrolling our collection to center the first item
            //And at the same time the user is requesting we go to a particular item
            if (position == -1 && Carousel.Loop)
            {
                _carouselViewLoopManager.AddPendingScrollTo(args);
                return;
            }

            if (args.IsAnimated)
            {
                ScrollHelper.AnimateScrollToPosition(position, args.ScrollToPosition);
            }
            else
            {
                ScrollHelper.JumpScrollToPosition(position, args.ScrollToPosition);
            }
        }
        void UpdateInitialPosition()
        {
            int itemCount = 0;
            int position;

            if (Carousel.CurrentItem != null)
            {
                var carouselEnumerator = Carousel.ItemsSource.GetEnumerator();
                var items = new List <object>();

                while (carouselEnumerator.MoveNext())
                {
                    items.Add(carouselEnumerator.Current);
                    itemCount++;
                }

                position          = items.IndexOf(Carousel.CurrentItem);
                Carousel.Position = position;
            }
            else
            {
                position = Carousel.Position;
            }

            _oldPosition = position;

            SetCurrentItem(_oldPosition);

            var index = Carousel.Loop ? LoopedPosition(itemCount) + _oldPosition : _oldPosition;

            ScrollHelper.JumpScrollToPosition(index, Xamarin.Forms.ScrollToPosition.Center);
            _gotoPosition = -1;
        }
Example #3
0
        void UpdateInitialPosition()
        {
            int position  = 0;
            var items     = Carousel.ItemsSource as IList;
            var itemCount = items?.Count ?? 0;

            if (Carousel.CurrentItem != null || items == null)
            {
                for (int n = 0; n < itemCount; n++)
                {
                    if (items[n] == Carousel.CurrentItem)
                    {
                        position = n;
                        break;
                    }
                }

                Carousel.Position = position;
            }
            else
            {
                position = Carousel.Position;
            }

            _oldPosition = position;

            SetCurrentItem(_oldPosition);

            var index = Carousel.Loop ? itemCount * 5000 + _oldPosition : _oldPosition;

            ScrollHelper.JumpScrollToPosition(index, Xamarin.Forms.ScrollToPosition.Center);
        }
Example #4
0
        protected virtual void ScrollTo(ScrollToRequestEventArgs args)
        {
            var position = DetermineTargetPosition(args);

            if (args.IsAnimated)
            {
                ScrollHelper.AnimateScrollToPosition(position, args.ScrollToPosition);
            }
            else
            {
                ScrollHelper.JumpScrollToPosition(position, args.ScrollToPosition);
            }
        }