Skip to content

Commit 35d48bf

Browse files
Shalini-AshokanPureWeen
authored andcommitted
[iOS] Fix CarouselView proper bounce-back behavior when Loop=false (#29318)
* Fixed the bounce back issue on carousal view 2 * Added test case * Removed unwanted lines
1 parent 20a70da commit 35d48bf

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

src/Controls/src/Core/Handlers/Items2/iOS/LoopObservableItemsSource2.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public int LoopCount
5959
get
6060
{
6161
var newCount = ItemCount;
62-
if (newCount > 0)
62+
if (Loop && newCount > 0)
6363
{
6464
newCount = ItemCount + 2;
6565
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System.Collections.ObjectModel;
2+
3+
namespace Maui.Controls.Sample.Issues;
4+
[Issue(IssueTracker.Github, 29261, "CarouselViewHandler2 for iOS does not properly bounce back when reaching the end with Loop=false", PlatformAffected.iOS)]
5+
public class Issue29261 : ContentPage
6+
{
7+
public Issue29261()
8+
{
9+
var verticalStackLayout = new VerticalStackLayout();
10+
var carouselItems = new ObservableCollection<string>
11+
{
12+
"First Item",
13+
"Middle Item",
14+
"Last Item",
15+
};
16+
17+
CarouselView2 carousel = new CarouselView2
18+
{
19+
ItemsSource = carouselItems,
20+
AutomationId = "carouselview",
21+
HeightRequest = 200,
22+
Loop = false,
23+
ItemTemplate = new DataTemplate(() =>
24+
{
25+
var grid = new Grid
26+
{
27+
Padding = 10
28+
};
29+
30+
var label = new Label
31+
{
32+
VerticalOptions = LayoutOptions.Center,
33+
HorizontalOptions = LayoutOptions.Center,
34+
FontSize = 18,
35+
};
36+
label.SetBinding(Label.TextProperty, ".");
37+
grid.Children.Add(label);
38+
return grid;
39+
}),
40+
HorizontalOptions = LayoutOptions.Fill,
41+
};
42+
43+
var label = new Label
44+
{
45+
Text = $"CarouselView Position - {carousel.Position}",
46+
AutomationId = "positionLabel",
47+
HorizontalOptions = LayoutOptions.Center,
48+
};
49+
50+
carousel.PositionChanged += (s, e) =>
51+
{
52+
label.Text = $"CarouselView Position - {carousel.Position}";
53+
};
54+
55+
verticalStackLayout.Children.Add(carousel);
56+
verticalStackLayout.Children.Add(label);
57+
Content = verticalStackLayout;
58+
}
59+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#if TEST_FAILS_ON_CATALYST
2+
// On Catalyst, Swipe actions not supported in Appium.
3+
using NUnit.Framework;
4+
using UITest.Appium;
5+
using UITest.Core;
6+
7+
namespace Microsoft.Maui.TestCases.Tests.Issues;
8+
public class Issue29261 : _IssuesUITest
9+
{
10+
public override string Issue => "CarouselViewHandler2 for iOS does not properly bounce back when reaching the end with Loop=false";
11+
12+
public Issue29261(TestDevice device)
13+
: base(device)
14+
{ }
15+
16+
[Test]
17+
[Category(UITestCategories.CarouselView)]
18+
public void VerifyCarouselViewBounceTest()
19+
{
20+
App.WaitForElement("carouselview");
21+
App.SwipeRightToLeft("carouselview");
22+
App.SwipeRightToLeft("carouselview");
23+
App.SwipeRightToLeft("carouselview");
24+
var text = App.FindElement("positionLabel").GetText();
25+
Assert.That(text, Is.EqualTo("CarouselView Position - 2"));
26+
}
27+
}
28+
#endif

0 commit comments

Comments
 (0)