-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS] CurrentItem does not work when PeekAreaInsets is set - fix #29995
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -339,7 +339,7 @@ public static UICollectionViewLayout CreateCarouselLayout( | |
| return; | ||
| } | ||
|
|
||
| var page = (offset.X + sectionMargin) / env.Container.ContentSize.Width; | ||
| var page = (offset.X + sectionMargin) / (env.Container.ContentSize.Width - sectionMargin * 2); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| { | ||
|
|
||
| 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> |
| 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"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also test rotating the device? That should impact |
||
| } | ||
| } | ||
| #endif | ||
There was a problem hiding this comment.
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.