Skip to content

Commit b16945f

Browse files
authored
[iOS] CurrentItem does not work when PeekAreaInsets is set - fix (#29995)
* [CarouselViewHandler2] CurrentItem does not work when PeekAreaInsets is set * Added a UITest
1 parent 8faf90c commit b16945f

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public static UICollectionViewLayout CreateCarouselLayout(
343343
return;
344344
}
345345

346-
var page = (offset.X + sectionMargin) / env.Container.ContentSize.Width;
346+
var page = (offset.X + sectionMargin) / (env.Container.ContentSize.Width - sectionMargin * 2);
347347

348348
if (Math.Abs(page % 1) > (double.Epsilon * 100) || cv2Controller.ItemsSource.ItemCount <= 0)
349349
{
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
x:Class="Maui.Controls.Sample.Issues.Issue28524">
5+
<Grid RowDefinitions="*,Auto">
6+
<CarouselView
7+
PeekAreaInsets="25"
8+
AutomationId="CarouselView"
9+
x:Name="CarouselView">
10+
<CarouselView.ItemsLayout>
11+
<LinearItemsLayout
12+
Orientation="Horizontal"
13+
SnapPointsType="MandatorySingle"/>
14+
</CarouselView.ItemsLayout>
15+
<CarouselView.ItemTemplate>
16+
<DataTemplate>
17+
<Grid>
18+
<Label
19+
HorizontalOptions="Center"
20+
VerticalOptions="Center"
21+
Text="{Binding}"/>
22+
</Grid>
23+
</DataTemplate>
24+
</CarouselView.ItemTemplate>
25+
<CarouselView.ItemsSource>
26+
<x:Array Type="{x:Type x:String}">
27+
<x:String>Baboon</x:String>
28+
<x:String>Capuchin Monkey</x:String>
29+
<x:String>Blue Monkey</x:String>
30+
</x:Array>
31+
</CarouselView.ItemsSource>
32+
</CarouselView>
33+
34+
<Label Grid.Row="1"
35+
Text="{Binding Source={x:Reference CarouselView}, Path=CurrentItem, StringFormat='CurrentItem={0}'}"/>
36+
</Grid>
37+
</ContentPage>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Maui.Controls.Sample.Issues;
2+
3+
[Issue(IssueTracker.Github, 28524, "[iOS] CurrentItem does not work when PeekAreaInsets is set", PlatformAffected.iOS)]
4+
public partial class Issue28524 : ContentPage
5+
{
6+
public Issue28524()
7+
{
8+
InitializeComponent();
9+
}
10+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#if ANDROID || IOS
2+
using NUnit.Framework;
3+
using UITest.Appium;
4+
using UITest.Core;
5+
6+
namespace Microsoft.Maui.TestCases.Tests.Issues;
7+
8+
public class Issue28524 : _IssuesUITest
9+
{
10+
public Issue28524(TestDevice device) : base(device) { }
11+
12+
public override string Issue => "[iOS] CurrentItem does not work when PeekAreaInsets is set";
13+
14+
[Test]
15+
[Category(UITestCategories.CarouselView)]
16+
public void CurrentItemShouldWork()
17+
{
18+
App.WaitForElement("CarouselView");
19+
App.ScrollRight("CarouselView");
20+
App.ScrollRight("CarouselView");
21+
App.WaitForElement("Blue Monkey");
22+
}
23+
}
24+
#endif

0 commit comments

Comments
 (0)