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

[iOS] CarouselView with CarouselViewHandler2 make app crash when Loop="False" and user scroll to the last position - fix #26868

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -49,7 +49,7 @@ public override UICollectionViewCell GetCell(UICollectionView collectionView, NS
return cell;
}

public override nint GetItemsCount(UICollectionView collectionView, nint section) => LoopItemsSource.LoopCount;
public override nint GetItemsCount(UICollectionView collectionView, nint section) => LoopItemsSource.Loop ? LoopItemsSource.LoopCount : LoopItemsSource.ItemCount;

void InitializeCarouselViewLoopManager()
{
Expand Down
29 changes: 29 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue26863.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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.Issue26863"
x:Name="This">

<VerticalStackLayout BindingContext="{Binding Source={Reference This}}">
<Button AutomationId="button"
x:Name="button"
IsVisible="false"
Text="Click me"
Command="{Binding ScrollToCommand}"/>
<CarouselView
HeightRequest="200"
ItemsSource="{Binding List}"
HorizontalOptions="Fill"
x:Name="CV"
Loop="False">
<CarouselView.ItemTemplate>
<DataTemplate>
<Label HorizontalOptions="Fill"
AutomationId="{Binding .}"
Text="{Binding .}"/>
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</VerticalStackLayout>

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

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 26863, "CarouselView with CarouselViewHandler2 make app crash", PlatformAffected.iOS)]
public partial class Issue26863 : ContentPage
{
public Issue26863()
{
InitializeComponent();
}

public ObservableCollection<string> List { get; } = new();
public Command ScrollToCommand => new(() => CV.ScrollTo(2, 0, animate: true));

protected override void OnAppearing()
{
List.Clear();
List.Add("item1");
List.Add("item2");
List.Add("item3");
button.IsVisible = true;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue26863 : _IssuesUITest
{
public Issue26863(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "CarouselView with CarouselViewHandler2 make app crash";

[Test]
[Category(UITestCategories.CarouselView)]
public void AppShouldNotCrashOnScrollingCarouselViewWithoutLoop()
{
App.WaitForElement("button");
App.Click("button");

//The test passes if no crash is observed
}
}
}
Loading