Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[windows] Fix Updating the initial position #23709

Merged
merged 1 commit into from
Jul 19, 2024
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 @@ -2,6 +2,7 @@
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using Microsoft.Maui.Controls.Platform;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
Expand Down Expand Up @@ -187,7 +188,13 @@ public static void MapCurrentItem(CarouselViewHandler handler, CarouselView caro

public static void MapPosition(CarouselViewHandler handler, CarouselView carouselView)
{
handler.UpdatePosition();
// If the initial position hasn't been set, we have a UpdateInitialPosition call on CarouselViewHandler
// that will handle this so we want to skip this mapper call. We need to wait for the LIstView to be ready
if (handler.InitialPositionSet)
{
handler.UpdatePosition();
}

}

public static void MapIsBounceEnabled(CarouselViewHandler handler, CarouselView carouselView)
Expand All @@ -210,6 +217,9 @@ public static void MapLoop(CarouselViewHandler handler, CarouselView carouselVie
handler.UpdateLoop();
}

internal bool InitialPositionSet { get; private set; }


void UpdateIsBounceEnabled()
{
if (_scrollViewer != null)
Expand Down Expand Up @@ -337,7 +347,7 @@ int GetItemPositionInCarousel(object item)
return -1;
}

void UpdateCarouselViewInitialPosition()
void UpdateInitialPosition()
{
if (ListViewBase == null)
{
Expand All @@ -348,7 +358,7 @@ void UpdateCarouselViewInitialPosition()
{
if (Element.Loop)
{
var item = ListViewBase.Items[0];
var item = ItemsView.CurrentItem ?? ListViewBase.Items.FirstOrDefault();
_loopableCollectionView.CenterMode = true;
ListViewBase.ScrollIntoView(item);
_loopableCollectionView.CenterMode = false;
Expand All @@ -358,6 +368,8 @@ void UpdateCarouselViewInitialPosition()
UpdateCurrentItem();
else
UpdatePosition();

InitialPositionSet = true;
}
}

Expand Down Expand Up @@ -563,7 +575,7 @@ void InitialSetup()
UpdateItemsSource();
UpdateSnapPointsType();
UpdateSnapPointsAlignment();
UpdateCarouselViewInitialPosition();
UpdateInitialPosition();
}

void InvalidateItemSize()
Expand Down
Loading