[iOS] CurrentItem does not work when PeekAreaInsets is set - fix#29995
[iOS] CurrentItem does not work when PeekAreaInsets is set - fix#29995PureWeen merged 2 commits intodotnet:inflight/candidatefrom
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR addresses an issue in CarouselViewHandler2 where the CurrentItem calculation malfunctions when PeekAreaInsets is set. The updated logic adjusts the content width used for computing the page index by subtracting the section margins.
- Adjusted calculation for determining the carousel page index
- Fixed CurrentItem positioning when PeekAreaInsets is applied
| @@ -337,7 +337,7 @@ public static UICollectionViewLayout CreateCarouselLayout( | |||
| return; | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
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.
| // 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. |
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
jsuarezruiz
left a comment
There was a problem hiding this comment.
Could include a related test?
Done |
|
/rebase |
6f1a09c to
cbac323
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
| App.WaitForElement("CarouselView"); | ||
| App.ScrollRight("CarouselView"); | ||
| App.ScrollRight("CarouselView"); | ||
| App.WaitForElement("Blue Monkey"); |
There was a problem hiding this comment.
Could also test rotating the device? That should impact env.Container.ContentSize.Width.
| } | ||
|
|
||
| var page = (offset.X + sectionMargin) / env.Container.ContentSize.Width; | ||
| var page = (offset.X + sectionMargin) / (env.Container.ContentSize.Width - sectionMargin * 2); |
There was a problem hiding this comment.
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?
…is set
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Issues Fixed
Fixes #28524
Screen.Recording.2025-06-14.at.12.16.00.mov
Screen.Recording.2025-06-14.at.12.15.02.mov