dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.2k stars 1.75k forks source link

CollectionView.Scrolled event offset isn't correctly reset when items change on Android #21708

Open nshtinkov opened 6 months ago

nshtinkov commented 6 months ago

Description

When changing the contents of the CollectionView.ItemsSource while scrolled down into the list, ItemsViewScrolledEventArgs.VerticalOffset is not correctly updated in Android.

Offset "0" should be at the start of the collection; instead the start offsets changes as items are added/removed. It manifests only when the collection is scrolled to after the position of the added/deleted items.

This issue was known and fixed in Xamarin.Forms: https://github.com/xamarin/Xamarin.Forms/issues/7993 . It has reappeared in MAUI.

The repro app is adapted from the Xamarin issue.

Steps to Reproduce

  1. Start repro app on Android (device or simulator).
  2. Use "Fill" button to populate the list
  3. Scroll down the list
  4. Use "Empty" button to clear the list.
  5. Use "Fill" button again.
  6. Scroll down and up the list; the start offset is not 0 as it should be. image

Link to public reproduction project repository

https://github.com/nshtinkov/MauiScrollOffsetAndroidBug

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 13

Did you find any workaround?

Replacing the ItemsSource collection after change seems to work, e.g. in the repro app:

        private void EmptyButton_OnClicked(object sender, EventArgs e)
        {
            _items.Clear();
            Items = new ReadOnlyObservableCollection<int>(_items);
        }

Relevant log output

No response

Zhanglirong-Winnie commented 6 months ago

Verified this issue with Visual Studio 17.10.0 Preview 2(8.0.7 & 8.0.14 & 8.0.0-rc.2.9530). Can repro on android platform with sample project.

nshtinkov commented 1 month ago

The bug is still there in 8.0.90.