KEMBAR78
[iOS] Support for KeepLastItemInView for CollectionView2 on iOS by kubaflo · Pull Request #31104 · dotnet/maui · GitHub
Skip to content

Conversation

@kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Aug 10, 2025

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

Before After
Screen.Recording.2025-04-01.at.01.17.56.mov
Screen.Recording.2025-04-01.at.01.15.22.mov
<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>

@Copilot Copilot AI review requested due to automatic review settings August 10, 2025 10:53
@kubaflo kubaflo requested a review from a team as a code owner August 10, 2025 10:53
@kubaflo kubaflo requested review from mattleibow and rmarinho August 10, 2025 10:53
@dotnet-policy-service dotnet-policy-service bot added the community ✨ Community Contribution label Aug 10, 2025
@kubaflo kubaflo self-assigned this Aug 10, 2025
Copy link
Contributor

Copilot AI left a 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 to ItemsLayout 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

@kubaflo kubaflo force-pushed the cv2-keep-last-item-in-view branch from 2f22a84 to 77c753f Compare August 10, 2025 10:54
@kubaflo kubaflo changed the title Add KeepLastItemInView support for CollectionView on iOS [iOS] Support for KeepLastItemInView for CollectionView2 on iOS Aug 10, 2025
@PureWeen PureWeen added this to the .NET 9 SR11 milestone Aug 11, 2025
@FlavioGoncalves-Cayas
Copy link

Looking forward to test this, but cannot get the artifacts when the build does not finish?

@kubaflo
Copy link
Contributor Author

kubaflo commented Aug 13, 2025

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 😄

@jfversluis
Copy link
Member

/azp run MAUI-public

@jfversluis jfversluis moved this from Todo to Ready To Review in MAUI SDK Ongoing Aug 13, 2025
@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jfversluis
Copy link
Member

Beep boop 🤖

@FlavioGoncalves-Cayas let us know the results whenever the build finishes, thanks!

@jfversluis jfversluis added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label Aug 13, 2025
@FlavioGoncalves-Cayas
Copy link

There's not artifact produced when it fails like it did right?

@rmarinho
Copy link
Member

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.
@kubaflo kubaflo force-pushed the cv2-keep-last-item-in-view branch from 77c753f to 04c0543 Compare September 2, 2025 22:29
@jfversluis
Copy link
Member

jfversluis commented Sep 4, 2025

/azp run MAUI-UITests-public

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jfversluis
Copy link
Member

@kubaflo test failures unfortunately :(

@kubaflo
Copy link
Contributor Author

kubaflo commented Sep 6, 2025

@jfversluis fixed

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@github-project-automation github-project-automation bot moved this from Ready To Review to Approved in MAUI SDK Ongoing Sep 8, 2025
@jfversluis jfversluis changed the base branch from main to inflight/current September 8, 2025 10:19
@jfversluis jfversluis merged commit 1712dae into dotnet:inflight/current Sep 8, 2025
76 of 78 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Sep 8, 2025
PureWeen pushed a commit that referenced this pull request Sep 8, 2025
<!-- 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>
```
PureWeen pushed a commit that referenced this pull request Sep 8, 2025
<!-- 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>
```
@FlavioGoncalves-Cayas
Copy link

Did this go into SR11? If not, is there still a version I can test this with?

@MartyIX
Copy link
Contributor

MartyIX commented Oct 2, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-controls-collectionview CollectionView, CarouselView, IndicatorView collectionview-cv2 community ✨ Community Contribution

Projects

Status: Done

6 participants