xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] [Android] CollectionView loses scroll position when virtualized inside of a CarouselPage #10692

Open JMNewsome opened 4 years ago

JMNewsome commented 4 years ago

Description

Steps to Reproduce

  1. Put a CollectionView inside of a carousel page
  2. Navigate about 2 pages away, navigate back
  3. Scroll position of the CollectionView is lost

Expected Behavior

Position of the CollectioView offset should be what it was when it was navigated away from

Actual Behavior

Position of the CollectionView offset is reset back to 0

Basic Information

Screenshots

Reproduction Link

[Android] CollectionView inside CarouselPage losing position.zip

Workaround

boris-df commented 4 years ago

The CarousselView itself is loosing it's scrollposition too! I have a CarouselView with 17 items (via binding) and set the CurrentItem to the 16th item -> works fine when initialising the view/page first

then: Navigate back and forth -> Now the carousselView shows the first item (position 0)

Strange thing: when debugging inside the OnAppearing of the page, the CarousselView has the correct properties set for "CurrenPosition" and "CurrentItem" - But it's not showing them.

Because of having the correct properties set, nothing seems to help to workaround that issue. i've tried to set CurrentItem again (and via binding the CurrentItem to send an OnPropertyChanged again) - same for CurrentPosition - same for calling ScrollTo ... It seems that the controls thinks it is already at the correct destination so it doesn't have to do anything... but it's switched to the first position - without giving an Event or anything :(

boris-df commented 4 years ago

The CarousselView itself is loosing it's scrollposition too! I have a CarouselView with 17 items (via binding) and set the CurrentItem to the 16th item -> works fine when initialising the view/page first

then: Navigate back and forth -> Now the carousselView shows the first item (position 0)

Strange thing: when debugging inside the OnAppearing of the page, the CarousselView has the correct properties set for "CurrenPosition" and "CurrentItem" - But it's not showing them.

Because of having the correct properties set, nothing seems to help to workaround that issue. i've tried to set CurrentItem again (and via binding the CurrentItem to send an OnPropertyChanged again) - same for CurrentPosition - same for calling ScrollTo ... It seems that the controls thinks it is already at the correct destination so it doesn't have to do anything... but it's switched to the first position - without giving an Event or anything :(

Edit: Xamarin.Forms 4.6.0.726

The CarousselView itself is loosing it's scrollposition too! I have a CarouselView with 17 items (via binding) and set the CurrentItem to the 16th item -> works fine when initialising the view/page first

then: Navigate back and forth -> Now the carousselView shows the first item (position 0)

Strange thing: when debugging inside the OnAppearing of the page, the CarousselView has the correct properties set for "CurrenPosition" and "CurrentItem" - But it's not showing them.

Because of having the correct properties set, nothing seems to help to workaround that issue. i've tried to set CurrentItem again (and via binding the CurrentItem to send an OnPropertyChanged again) - same for CurrentPosition - same for calling ScrollTo ... It seems that the controls thinks it is already at the correct destination so it doesn't have to do anything... but it's switched to the first position - without giving an Event or anything :(

Edit: Xamarin.Forms 4.6.0.726

boris-df commented 4 years ago

Edit: Xamarin.Forms 4.6.0.726

"fixed" with 4.6.0.772 - At least the last position is restored when pushing the page again But you can see (and have to wait) that this happens! It seems like the CarouselView is still switching to the first item and then "automagically" scrolling to the last selected item (with animation!)

I would expect the Page / CarouselView to look like i left it when i open the page again

samhouts commented 4 years ago

I would have said that this is because the ViewPager OffscreenPageLimit is too small, but that doesn't seem to be the case:

https://github.com/xamarin/Xamarin.Forms/blob/7a52542d50797ccc69ae1d8dd84259190d96bdb4/Xamarin.Forms.Platform.Android/Renderers/CarouselPageRenderer.cs#L87

We must be thwarting it somewhere.