-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[iOS] Support for KeepLastItemInView for CollectionView2 on iOS #31104
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
base: main
Are you sure you want to change the base?
Conversation
Hey there @@kubaflo! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
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.
Pull Request Overview
This PR implements KeepLastItemInView
support for CollectionView on iOS to address scroll behavior when new items are added to the collection. The implementation ensures that when new items are added to a CollectionView, the scroll position automatically moves to keep the last item visible.
Key changes:
- Added
ItemsUpdatingScrollMode
property toItemsLayout
to track scroll behavior - Modified layout factory methods to pass through the scroll mode configuration
- Implemented automatic scrolling to last item in
CustomUICollectionViewCompositionalLayout
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
src/Controls/src/Core/Items/ItemsLayout.cs |
Adds internal ItemsUpdatingScrollMode property to track scroll behavior |
src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs |
Updates layout creation methods to accept and handle ItemsUpdatingScrollMode parameter |
src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs |
Maps ItemsUpdatingScrollMode from ItemsView to ItemsLayout |
src/Controls/tests/TestCases.HostApp/Issues/Issue28716.xaml |
Creates test UI with three CollectionViews demonstrating the feature |
src/Controls/tests/TestCases.HostApp/Issues/Issue28716.xaml.cs |
Implements code-behind with data binding and command for adding items |
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28716.cs |
Adds automated UI test to verify the functionality works correctly |
|
||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[Issue(IssueTracker.Github, 28720, "Support for KeepLastItemInView for CV2", PlatformAffected.iOS)] |
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.
The issue number in the attribute (28720) does not match the filename (Issue28716). This should be 28716 to maintain consistency.
[Issue(IssueTracker.Github, 28720, "Support for KeepLastItemInView for CV2", PlatformAffected.iOS)] | |
[Issue(IssueTracker.Github, 28716, "Support for KeepLastItemInView for CV2", PlatformAffected.iOS)] |
Copilot uses AI. Check for mistakes.
} | ||
else | ||
{ | ||
collectionView.ScrollToItem(lastIndexPath, UICollectionViewScrollPosition.Right, true); |
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.
The scroll position logic assumes left-to-right layout direction. For right-to-left languages or when FlowDirection is RightToLeft, scrolling to UICollectionViewScrollPosition.Right may not provide the expected behavior of showing the 'last' item from the user's perspective.
collectionView.ScrollToItem(lastIndexPath, UICollectionViewScrollPosition.Right, true); | |
// Adjust scroll position for RTL layouts | |
var layoutDirection = collectionView.EffectiveUserInterfaceLayoutDirection; | |
var scrollPosition = layoutDirection == UIUserInterfaceLayoutDirection.RightToLeft | |
? UICollectionViewScrollPosition.Left | |
: UICollectionViewScrollPosition.Right; | |
collectionView.ScrollToItem(lastIndexPath, scrollPosition, true); |
Copilot uses AI. Check for mistakes.
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.
@kubaflo I think this might make sense?
Implements ItemsUpdatingScrollMode.KeepLastItemInView for CollectionView on iOS by updating layout creation and scroll logic. Adds internal ItemsUpdatingScrollMode property to ItemsLayout. Includes new test case and UI test for issue dotnet#28720 to verify correct behavior.
2f22a84
to
77c753f
Compare
Looking forward to test this, but cannot get the artifacts when the build does not finish? |
Yeah we need to trigger a build to generate artifacts. Luckily I know the best /azp triggerer @jfversluis who will do it for us 😄 |
/azp run MAUI-public |
Azure Pipelines successfully started running 1 pipeline(s). |
Beep boop 🤖 @FlavioGoncalves-Cayas let us know the results whenever the build finishes, thanks! |
There's not artifact produced when it fails like it did right? |
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 #28716
Fixes #31085
Screen.Recording.2025-04-01.at.01.17.56.mov
Screen.Recording.2025-04-01.at.01.15.22.mov