示例#1
0
        void IMauiCarouselRecyclerView.UpdateFromCurrentItem()
        {
            var currentItemPosition = ItemsViewAdapter.ItemsSource.GetPosition(Carousel.CurrentItem);
            var carouselPosition    = Carousel.Position;

            if (_gotoPosition == -1 && currentItemPosition != carouselPosition)
            {
                _gotoPosition = currentItemPosition;
                ItemsView.ScrollTo(currentItemPosition, position: Microsoft.Maui.Controls.ScrollToPosition.Center, animate: Carousel.AnimateCurrentItemChanges);
            }
        }
        void UpdateCurrentItem()
        {
            if (CollectionViewSource == null)
            {
                return;
            }

            var currentItemPosition = GetItemPositionInCarousel(ItemsView.CurrentItem);

            if (currentItemPosition < 0 || currentItemPosition >= ItemCount)
            {
                return;
            }

            ItemsView.ScrollTo(currentItemPosition, position: ScrollToPosition.Center, animate: ItemsView.AnimateCurrentItemChanges);
        }
示例#3
0
        void IMauiCarouselRecyclerView.UpdateFromPosition()
        {
            if (!_initialized)
            {
                _carouselViewLoopManager.AddPendingScrollTo(new ScrollToRequestEventArgs(Carousel.Position, -1, Microsoft.Maui.Controls.ScrollToPosition.Center, false));
            }

            var itemCount        = ItemsViewAdapter?.ItemsSource.Count ?? 0;
            var carouselPosition = Carousel.Position;

            if (itemCount == 0)
            {
                //we are trying to set a position but our Collection doesn't have items still
                _oldPosition = carouselPosition;
                return;
            }


            if (carouselPosition >= itemCount || carouselPosition < 0)
            {
                throw new IndexOutOfRangeException($"Can't set CarouselView to position {carouselPosition}. ItemsSource has {itemCount} items.");
            }

            if (carouselPosition == _gotoPosition)
            {
                _gotoPosition = -1;
            }

            if (_noNeedForScroll)
            {
                _noNeedForScroll = false;
                return;
            }

            var centerPosition = GetCarouselViewCurrentIndex(carouselPosition);

            if (_gotoPosition == -1 && !Carousel.IsDragging && !Carousel.IsScrolling && centerPosition != carouselPosition)
            {
                _gotoPosition = carouselPosition;

                ItemsView.ScrollTo(carouselPosition, position: Microsoft.Maui.Controls.ScrollToPosition.Center, animate: Carousel.AnimatePositionChanges);
            }
            SetCurrentItem(carouselPosition);
        }
示例#4
0
 void ScrollToIndex(int index)
 {
     _itemsView.ScrollTo(index, position: _currentScrollToPosition, animate: _animateSwitch.IsToggled);
 }
示例#5
0
 void ScrollToItem(object item)
 {
     _itemsView.ScrollTo(item, position: _currentScrollToPosition, animate: _animateSwitch.IsToggled);
 }