Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class MauiCarouselRecyclerView : MauiRecyclerView<CarouselView, ItemsView
CarouselViewLoopManager _carouselViewLoopManager;
int _oldPosition;
int _gotoPosition = -1;
int _scrollToCounter = 0;
bool _noNeedForScroll;
bool _initialized;
bool _isVisible;
Expand Down Expand Up @@ -183,6 +184,8 @@ public override void ScrollTo(ScrollToRequestEventArgs args)
if (_carouselViewLoopManager == null)
return;

_scrollToCounter++;

// 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
Expand Down Expand Up @@ -224,6 +227,7 @@ void CollectionItemsSourceChanged(object sender, System.Collections.Specialized.
var carouselPosition = Carousel.Position;
var currentItemPosition = observableItemsSource.GetPosition(Carousel.CurrentItem);
var count = observableItemsSource.Count;
var savedScrollToCounter = _scrollToCounter;

bool removingCurrentElement = currentItemPosition == -1;
bool removingLastElement = e.OldStartingIndex == count;
Expand Down Expand Up @@ -273,9 +277,13 @@ void CollectionItemsSourceChanged(object sender, System.Collections.Specialized.
GetDispatcher()
.Dispatch(() =>
{

SetCurrentItem(carouselPosition);
UpdatePosition(carouselPosition);
// If someone called explicit ScrollTo before the dispatched
// callback was delivered then don't override it.
if (_scrollToCounter == savedScrollToCounter)
{
SetCurrentItem(carouselPosition);
UpdatePosition(carouselPosition);
}

//If we are adding or removing the last item we need to update
//the inset that we give to items so they are centered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
double targetHeight = _height();

if (!double.IsInfinity(targetWidth))
targetWidth = (int)Context.FromPixels(targetWidth);
targetWidth = Context.FromPixels(targetWidth);

if (!double.IsInfinity(targetHeight))
targetHeight = (int)Context.FromPixels(targetHeight);
targetHeight = Context.FromPixels(targetHeight);

if (Content.VirtualView.Handler is IPlatformViewHandler pvh)
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading