-
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
[iOS] Support for KeepLastItemInView for CollectionView2 on iOS #31104
Conversation
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
ItemsUpdatingScrollModeproperty toItemsLayoutto 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 |
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? |
|
Yeah @FlavioGoncalves-Cayas the Windows release finished and created the nupkg you can download here |
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.
77c753f to
04c0543
Compare
|
/azp run MAUI-UITests-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
@kubaflo test failures unfortunately :( |
|
@jfversluis fixed |
|
Azure Pipelines successfully started running 1 pipeline(s). |
<!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issues Fixed Fixes #28716 Fixes #31085 |Before|After| |--|--| |<video src="https://github.com/user-attachments/assets/f94e034a-99d4-4846-9fa0-bb8f2d547bdc" width="300px"/>|<video src="https://github.com/user-attachments/assets/797fb522-cffe-4566-a301-4a035093b0b5" width="300px"/>| ```xaml <Grid RowDefinitions="Auto, *"> <Button Text="Add Item" Clicked="Button_Clicked" HorizontalOptions="Center" VerticalOptions="Center"/> <CollectionView ItemsUpdatingScrollMode="KeepLastItemInView" Grid.Row="1" x:Name="cv"> <CollectionView.ItemTemplate> <DataTemplate> <Grid ColumnDefinitions="*,Auto"> <Label Text="{Binding Text}" HeightRequest="100" VerticalOptions="Center"/> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </Grid> ```
<!-- Please let the below note in for people that find this PR --> > [!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](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! <!-- !!!!!!! MAIN IS THE ONLY ACTIVE BRANCH. MAKE SURE THIS PR IS TARGETING MAIN. !!!!!!! --> ### Issues Fixed Fixes #28716 Fixes #31085 |Before|After| |--|--| |<video src="https://github.com/user-attachments/assets/f94e034a-99d4-4846-9fa0-bb8f2d547bdc" width="300px"/>|<video src="https://github.com/user-attachments/assets/797fb522-cffe-4566-a301-4a035093b0b5" width="300px"/>| ```xaml <Grid RowDefinitions="Auto, *"> <Button Text="Add Item" Clicked="Button_Clicked" HorizontalOptions="Center" VerticalOptions="Center"/> <CollectionView ItemsUpdatingScrollMode="KeepLastItemInView" Grid.Row="1" x:Name="cv"> <CollectionView.ItemTemplate> <DataTemplate> <Grid ColumnDefinitions="*,Auto"> <Label Text="{Binding Text}" HeightRequest="100" VerticalOptions="Center"/> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> </Grid> ```
|
Did this go into SR11? If not, is there still a version I can test this with? |
|
I can see this PR in https://github.com/dotnet/maui/pull/31525/commits which means it should be in the next release (.NET 9 SR12). You can test using a nightly build. |
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