Skip to content

Conversation

kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Mar 31, 2025

Issues Fixed

Fixes #28716
Fixes #18029
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 March 31, 2025 23:22
@kubaflo kubaflo requested a review from a team as a code owner March 31, 2025 23:22
Copy link
Contributor

@Copilot 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 adds support for the ItemsUpdatingScrollMode property "KeepLastItemInView" for CollectionView on iOS. Key changes include updating the LayoutFactory2 methods to accept the new parameter, modifying the custom UICollectionViewCompositionalLayout to enforce scrolling behavior, and updating the ItemsViewHandler2 and CollectionViewHandler2 to pass the new parameter.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs Updated method signatures to include ItemsUpdatingScrollMode and added logic in the custom layout to scroll to the last item
src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs Replaced the previous direct assignment with a call to UpdateLayout for propagating ItemsUpdatingScrollMode
src/Controls/src/Core/Handlers/Items2/CollectionViewHandler2.iOS.cs Updated layout factory calls to pass the ItemsUpdatingScrollMode parameter
Comments suppressed due to low confidence (3)

src/Controls/src/Core/Handlers/Items2/iOS/LayoutFactory2.cs:12

  • The method signature now includes the new parameter 'itemsUpdatingScrollMode', which is a breaking change in the public API. Please ensure related documentation and tests are updated accordingly.
public static UICollectionViewLayout CreateList(LinearItemsLayout linearItemsLayout, LayoutGroupingInfo groupingInfo, LayoutHeaderFooterInfo headerFooterInfo, ItemsUpdatingScrollMode itemsUpdatingScrollMode)

src/Controls/src/Core/Handlers/Items2/ItemsViewHandler2.iOS.cs:120

  • Replacing the direct assignment of ItemsUpdatingScrollMode with an UpdateLayout() call may introduce side effects; ensure that tests cover the correct propagation of ItemsUpdatingScrollMode.
handler.UpdateLayout();

src/Controls/src/Core/Handlers/Items2/CollectionViewHandler2.iOS.cs:157

  • Ensure tests verify that the ItemsUpdatingScrollMode value is correctly propagated to the layout factory, including in fallback scenarios.
var itemsUpdatingScrollMode = ItemsView.ItemsUpdatingScrollMode;

{
base.FinalizeCollectionViewUpdates();

if (_itemsUpdatingScrollMode == ItemsUpdatingScrollMode.KeepLastItemInView)
Copy link
Preview

Copilot AI Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overriding FinalizeCollectionViewUpdates to scroll to the last item is a significant behavior change; please ensure tests verify the accuracy of this scrolling behavior.

Copilot uses AI. Check for mistakes.

@rmarinho
Copy link
Member

rmarinho commented Apr 1, 2025

/azp run

@dotnet dotnet deleted a comment from dotnet-policy-service bot Apr 1, 2025
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

}
else
{
collectionView.ScrollToItem(lastIndexPath, UICollectionViewScrollPosition.Right, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should look at RTL here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that the current implementation already supports RTL. I've included it in the UITest to be sure

Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test ? Also can we make sure if RTL is on it scrolls correctly

Thanks

@kubaflo
Copy link
Contributor Author

kubaflo commented Apr 2, 2025

Can we add a test ? Also can we make sure if RTL is on it scrolls correctly

Thanks

sure!

Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rmarinho rmarinho added this to the .NET 9 SR6 milestone Apr 7, 2025
@rmarinho rmarinho moved this from Todo to Changes Requested in MAUI SDK Ongoing Apr 7, 2025
@dotnet dotnet deleted a comment from azure-pipelines bot Apr 7, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR6, .NET 9 SR7 Apr 8, 2025
@rmarinho rmarinho added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label Apr 9, 2025
@kubaflo
Copy link
Contributor Author

kubaflo commented Apr 9, 2025

@rmarinho I've added a commit that fixes it for cv1

@kubaflo kubaflo changed the title [iOS] Support for KeepLastItemInView for CV2 [iOS] Fixed KeepLastItemInView for CV1 and added support for KeepLastItemInView for CV2 Apr 9, 2025
@karthikraja-arumugam
Copy link
Contributor

This also fixes issue #18029

@rmarinho
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

rmarinho
rmarinho previously approved these changes Apr 14, 2025
@github-project-automation github-project-automation bot moved this from Changes Requested to Approved in MAUI SDK Ongoing Apr 14, 2025
@rmarinho rmarinho linked an issue Apr 14, 2025 that may be closed by this pull request
Copy link
Member

@PureWeen PureWeen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-project-automation github-project-automation bot moved this from Approved to Changes Requested in MAUI SDK Ongoing Apr 18, 2025
@kubaflo
Copy link
Contributor Author

kubaflo commented Apr 19, 2025

test failure seems consistent https://dev.azure.com/xamarin/public/_build/results?buildId=140014&view=ms.vss-test-web.build-test-results-tab&runId=4027466&resultId=100127&paneView=debug

LayoutPassesShouldNotIncrease

@albyrock87 I've modified your UI test. Could you please have a look at this pr and let me know if I should have modified the test?

@kubaflo kubaflo force-pushed the cv2-KeepLastItemInView branch from 78132f5 to 12b4197 Compare April 19, 2025 23:40
@albyrock87
Copy link
Contributor

test failure seems consistent https://dev.azure.com/xamarin/public/_build/results?buildId=140014&view=ms.vss-test-web.build-test-results-tab&runId=4027466&resultId=100127&paneView=debug

LayoutPassesShouldNotIncrease

@albyrock87 I've modified your UI test. Could you please have a look at this pr and let me know if I should have modified the test?

Now my question is: you haven't touched 25671.xaml in any way, so how is it possible that the performance changed so much? 25671 is not using the flag you're fixing here, so I would expect no changes there.

Also, CV2 has a major performance decrease which seems even more strange.

@PureWeen PureWeen requested a review from rmarinho April 22, 2025 22:13
@PureWeen PureWeen modified the milestones: .NET 9 SR7, .NET 9 SR8 May 8, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR8, .NET 9 SR9 Jun 2, 2025
@kubaflo kubaflo force-pushed the cv2-KeepLastItemInView branch from 12b4197 to ba5f11c Compare June 3, 2025 14:45
@PureWeen PureWeen modified the milestones: .NET 9 SR9, .NET 9 SR10 Jul 3, 2025
@PureWeen PureWeen modified the milestones: .NET 9 SR10, .NET 9 SR11 Aug 4, 2025
kubaflo added a commit to kubaflo/maui that referenced this pull request Aug 10, 2025
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 added a commit to kubaflo/maui that referenced this pull request Aug 10, 2025
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
Copy link
Contributor Author

kubaflo commented Aug 10, 2025

Closed in favour of #31104

@kubaflo kubaflo closed this Aug 10, 2025
@github-project-automation github-project-automation bot moved this from Changes Requested to Done in MAUI SDK Ongoing Aug 10, 2025
kubaflo added a commit to kubaflo/maui that referenced this pull request Aug 10, 2025
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 added a commit to kubaflo/maui that referenced this pull request Sep 2, 2025
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.
@github-actions github-actions bot locked and limited conversation to collaborators Sep 10, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView collectionview-cv2 community ✨ Community Contribution platform/ios
Projects
Status: Done
5 participants