Skip to content
Merged
Changes from all 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 @@ -509,54 +509,49 @@ async Task UpdateInitialPosition()
return;
}

int position = carousel.Position;
var currentItem = carousel.CurrentItem;

if (currentItem != null)
{
// Sometimes the item could be just being removed while we navigate back to the CarouselView
var positionCurrentItem = ItemsSource.GetIndexForItem(currentItem).Row;
if (positionCurrentItem != -1)
{
position = positionCurrentItem;
}
}

var projectedPosition = NSIndexPath.FromItemSection(position, _section);

if (LoopItemsSource.Loop)
{
//We need to set the position to the correct position since we added 1 item at the beginning
projectedPosition = GetScrollToIndexPath(position);
}

var uICollectionViewScrollPosition = IsHorizontal ? UICollectionViewScrollPosition.CenteredHorizontally : UICollectionViewScrollPosition.CenteredVertically;

await Task.Delay(100).ContinueWith((t) =>
await Task.Delay(100).ContinueWith(_ =>
{
MainThread.BeginInvokeOnMainThread(() =>
{
if (!IsViewLoaded)
{
return;
}

InitialPositionSet = true;

if (ItemsSource is null || ItemsSource.ItemCount == 0)
{
return;
}

int position = carousel.Position;
var currentItem = carousel.CurrentItem;

if (currentItem != null)
{
// Sometimes the item could be just being removed while we navigate back to the CarouselView
var positionCurrentItem = ItemsSource.GetIndexForItem(currentItem).Row;
if (positionCurrentItem != -1)
{
position = positionCurrentItem;
}
}

var projectedPosition = LoopItemsSource.Loop
? GetScrollToIndexPath(position) // We need to set the position to the correct position since we added 1 item at the beginning
: NSIndexPath.FromItemSection(position, _section);

var uICollectionViewScrollPosition = IsHorizontal ? UICollectionViewScrollPosition.CenteredHorizontally : UICollectionViewScrollPosition.CenteredVertically;

CollectionView.ScrollToItem(projectedPosition, uICollectionViewScrollPosition, false);

//Set the position on VirtualView to update the CurrentItem also
SetPosition(position);

UpdateVisualStates();
});

});

}

void UpdateVisualStates()
Expand Down
Loading