Skip to content

Unintended scrolling occurs when deleting and adding data bound to CollectionView on iOS. #20281

@cat0363

Description

@cat0363

Description

Below is the screen layout to reproduce this issue.

<Grid RowDefinitions="44,*">
    <Button x:Name="btnAdd" Text="Add Item" TextColor="White" BackgroundColor="Blue" Clicked="btnAdd_Clicked" />
    <CollectionView x:Name="cvTestList" Grid.Row="1" ItemsLayout="VerticalList" ItemSizingStrategy="MeasureAllItems">
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <Grid HeightRequest="60">
                    <Label Text="{Binding ItemName}" TextColor="Black" VerticalOptions="Center" HorizontalOptions="Start" />
                </Grid>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
</Grid>

The ViewModel bound to CollectionView is the following class.

public class ViewModelTest
{
    public string ItemName { get; set; }
}

To reproduce the problem, scroll the CollectionView to the end and then press the Add Item button.
When you press the Add Item button, data is added using the following steps.

  1. Removes two pieces of data from the end of the data bound to the CollectionView.
  2. Add three pieces of data to the end of the data bound to the CollectionView.

The following is the process when you press the add item button.

private void btnAdd_Clicked(object sender, EventArgs e)
{
    for (int i = 0; i < 2; i++)
    {
        pTestList.RemoveAt(pTestList.Count - 1);
    }
    for (int i = 0; i < 3; i++)
    {
        pTestList.Add(new ViewModelTest() { ItemName = "Item " + string.Format("{0:D3}", pTestList.Count + 1) });
    }
}

I am adding some data in a roundabout way, but this is the minimum code to reproduce the problem, so please forgive me.
The code that actually caused the problem has a complicated way of adding data, but this is the minimum code to reproduce the problem.

As of 2., the scrollbar position does not move on Android, but the scrollbar position does move on iOS.

Below is a verification video.

[iOS]

_iOS.mp4

[Android]

_Android.mp4

After pressing the Add Item button, it scrolls upwards on iOS, but not on Android.

Steps to Reproduce

The steps to reproduce are as follows.

  1. Launch the app uploaded to github with the device on iOS.
  2. Scroll the CollectionView to the end.
  3. Press the Add Item button.

In step 3, the position of the CollectionView's scroll bar will move on iOS.
In step 3, the position of the CollectionView's scrollbar does not move on Android.
Both behave differently.

In step3, I expected the scrollbar position to not move on iOS like it does on Android.

Link to public reproduction project repository

https://github.com/cat0363/Maui-IssueCollectionViewScroll.git

Version with bug

8.0.6

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 17.0

Did you find any workaround?

None

Relevant log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-controls-collectionviewCollectionView, CarouselView, IndicatorViewplatform/ioss/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions