Skip to content
Merged
Show file tree
Hide file tree
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 @@ -320,7 +320,13 @@ void UpdateInitialPosition()
Carousel.Position = position;
}
else
{
position = Carousel.Position;
if (Carousel.Loop && position == 0)
{
itemCount = ItemsViewAdapter.ItemsSource.Count;
}
}

_oldPosition = position;

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue17283.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue17283">

<VerticalStackLayout Padding="30,0"
Spacing="25"
VerticalOptions="Center">
<CarouselView x:Name="CarouselView"
HeightRequest="200"
BackgroundColor="AliceBlue"
ItemsSource="{Binding Items}"
Loop="True"
Position="{Binding Position, Mode=TwoWay}">
<CarouselView.ItemTemplate>
<DataTemplate>
<VerticalStackLayout HeightRequest="200" VerticalOptions="Center">
<Label FontSize="32"
HorizontalTextAlignment="Center"
AutomationId="{Binding .}"
Text="{Binding .}"
VerticalTextAlignment="Center" />
</VerticalStackLayout>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
<Button AutomationId="reloadItemsButton" Command="{Binding ReloadItemsCommand}" Text="Reload Items" />
<Button AutomationId="goToLastItemButton" Command="{Binding GoToLastItemCommand}" Text="Go to last item" />
</VerticalStackLayout>

</ContentPage>
63 changes: 63 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue17283.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 17283, "[Android] CarouselView doesn't scroll to the right Position after changing the ItemSource with Loop enabled", PlatformAffected.Android)]
public partial class Issue17283 : ContentPage
{
public Issue17283()
{
InitializeComponent();
BindingContext = new Issue17283ViewModel();
}
}

public class Issue17283ViewModel : INotifyPropertyChanged
{
ObservableCollection<string> _items;
public ObservableCollection<string> Items
{
get => _items;
set
{
_items = value;
OnPropertyChanged();
}
}

int _position;
public int Position
{
get => _position;
set
{
_position = value;
OnPropertyChanged();
}
}

public Command ReloadItemsCommand { get; set; }
public Command GoToLastItemCommand { get; set; }

public Issue17283ViewModel()
{
Items = new ObservableCollection<string> { "1", "2", "3", "4", "5" };
ReloadItemsCommand = new Command(ReloadItems);
GoToLastItemCommand = new Command(() => Position = Items.Count - 1);
}

async void ReloadItems()
{
var currentPosition = Position;
Items = new ObservableCollection<string> { "1", "2", "3", "4", "5last" };
await Task.Delay(300);
Position = currentPosition;
}
public event PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if !MACCATALYST
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
internal class Issue17283 : _IssuesUITest
{
public override string Issue => "[Android] CarouselView doesn't scroll to the right Position after changing the ItemSource with Loop enabled";

public Issue17283(TestDevice testDevice) : base(testDevice) { }

[Test]
[Category(UITestCategories.CarouselView)]
[FailsOnWindows("Currently fails on Windows; see https://github.com/dotnet/maui/issues/24482")]
public void CarouselViewShouldScrollToRightPosition()
{
App.WaitForElement("goToLastItemButton");
App.Click("goToLastItemButton");
App.WaitForElement("5");
App.Click("reloadItemsButton");
App.WaitForElement("5last");
VerifyScreenshot();
}
}
}
#endif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.