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 @@ -339,7 +339,7 @@ public static UICollectionViewLayout CreateCarouselLayout(
return;
}

Copy link

Copilot AI Jun 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a brief inline comment to clarify why sectionMargin is subtracted twice from the container width, which will help future maintainers understand the intention behind this calculation.

Suggested change
// Calculate the current page index based on the offset and container width.
// Subtract sectionMargin * 2 to account for the margins on both sides of the container.

Copilot uses AI. Check for mistakes.
var page = (offset.X + sectionMargin) / env.Container.ContentSize.Width;
var page = (offset.X + sectionMargin) / (env.Container.ContentSize.Width - sectionMargin * 2);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could have negative page calculations causing crashes? For example, using a big value for PeekAreaInsets (like 250). Not usual scenario, but, could we protect it?


if (Math.Abs(page % 1) > (double.Epsilon * 100) || cv2Controller.ItemsSource.ItemCount <= 0)
{
Expand Down
37 changes: 37 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28524.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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.Issue28524">
<Grid RowDefinitions="*,Auto">
<CarouselView
PeekAreaInsets="25"
AutomationId="CarouselView"
x:Name="CarouselView">
<CarouselView.ItemsLayout>
<LinearItemsLayout
Orientation="Horizontal"
SnapPointsType="MandatorySingle"/>
</CarouselView.ItemsLayout>
<CarouselView.ItemTemplate>
<DataTemplate>
<Grid>
<Label
HorizontalOptions="Center"
VerticalOptions="Center"
Text="{Binding}"/>
</Grid>
</DataTemplate>
</CarouselView.ItemTemplate>
<CarouselView.ItemsSource>
<x:Array Type="{x:Type x:String}">
<x:String>Baboon</x:String>
<x:String>Capuchin Monkey</x:String>
<x:String>Blue Monkey</x:String>
</x:Array>
</CarouselView.ItemsSource>
</CarouselView>

<Label Grid.Row="1"
Text="{Binding Source={x:Reference CarouselView}, Path=CurrentItem, StringFormat='CurrentItem={0}'}"/>
</Grid>
</ContentPage>
10 changes: 10 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue28524.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 28524, "[iOS] CurrentItem does not work when PeekAreaInsets is set", PlatformAffected.iOS)]
public partial class Issue28524 : ContentPage
{
public Issue28524()
{
InitializeComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#if ANDROID || IOS
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue28524 : _IssuesUITest
{
public Issue28524(TestDevice device) : base(device) { }

public override string Issue => "[iOS] CurrentItem does not work when PeekAreaInsets is set";

[Test]
[Category(UITestCategories.CarouselView)]
public void CurrentItemShouldWork()
{
App.WaitForElement("CarouselView");
App.ScrollRight("CarouselView");
App.ScrollRight("CarouselView");
App.WaitForElement("Blue Monkey");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also test rotating the device? That should impact env.Container.ContentSize.Width.

}
}
#endif
Loading