Bug 54087 - ListView.ScrollTo Android broken and inconsistent behavior
Summary: ListView.ScrollTo Android broken and inconsistent behavior
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.3
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Chris King
Depends on:
Reported: 2017-03-28 06:09 UTC by Chase Long
Modified: 2017-03-29 19:25 UTC (History)
3 users (show)

Tags: listview scrollto ac
Is this bug a regression?: ---
Last known good build:

Solution demonstrating the problems (216.26 KB, application/zip)
2017-03-28 06:09 UTC, Chase Long

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Chase Long 2017-03-28 06:09:41 UTC
Created attachment 20930 [details]
Solution demonstrating the problems

# ListView.ScrollTo is broken on Android with animated: false in certain use cases
Call ListView.ScrollTo ASAP after its BindingContext is set. This refers to the call in MainPage.xaml.cs -> OnBindingContextChanged override.

* On Android, scroll doesn't work at all with animated: false
* On Android, scroll works with animated: true
* On iOS, scroll works in both cases

The documentation at https://developer.xamarin.com/api/member/Xamarin.Forms.ListView.ScrollTo/p/System.Object/Xamarin.Forms.ScrollToPosition/System.Boolean/ should specify what will happen when calls are made to ScrollTo before the ListView is rendered.
I am assuming it has not been rendered before the ScrollTo call in this example, but I am not 100% sure.
The source code of Xamarin.Forms.Platform.Android.ListViewRenderer includes a field "_pendingScrollTo". At a glance, it seems the ScrollTo request should be stored until the ListView is rendered, and then the scroll should happen.

Tested on Xamarin.Forms and

# Inconsistent ListView.ScrollTo behavior with ScrollToPosition.MakeVisible
Different effects depending on platform and whether ScrollTo is called with animated: true or false.

* Android, animated - Scrolls until the item is at the END of the visible area. If the item is already visible, then this does nothing.
* Android, not animated - Scrolls until the item is at the START of the visible area. If the item is already visible, then this scrolls until the item is at the START of the visible area.
* iOS, animated - Scrolls until the item is at the END of the visible area. If the item is already visible, then this does nothing.
* iOS, not animated - Scrolls until the item is at the END of the visible area. If the item is already visible, then this does nothing.

Also, the documentation at https://developer.xamarin.com/api/field/Xamarin.Forms.ScrollToPosition.MakeVisible/ should specify if the item will be at the start or end of the visible area after scroll.
It currently does not specify.

Tested on Xamarin.Forms and
Comment 1 Paul DiPietro [MSFT] 2017-03-28 13:59:05 UTC
Also tested against the and there is an inconsistency in the Android behavior.
Comment 2 Chris King 2017-03-28 20:20:02 UTC
The reproduction works on latest XF for Android ListView scrolling when clicking on "Scroll to 30 Not Animated"; the listview brings 30 into view without animating. I'll ask that amend the document to state that ScrollTo simply makes the item visible and not specify the exact location.
Comment 3 Chase Long 2017-03-28 20:22:32 UTC
@Chris King, that's not the only problem. Calling ScrollTo in OnBindingContext with animated: false just does not scroll at all on Android, but it does on iOS. Please change this back to confirmed instead of fixed.
Comment 4 Chase Long 2017-03-28 20:24:51 UTC
To clarify, that's the whole first section I'm talking about. It's separate from the inconsistent behavior when clicking the buttons.
Comment 5 Chase Long 2017-03-29 02:07:15 UTC
@Chris King I'm reopening this. Reply if you want me to make a separate bug for the remaining problems, instead.
Comment 6 Chris King 2017-03-29 15:36:10 UTC
Yes, please open separate bugs for each issue where each bug has the smallest reproduction code necessary to exemplify the issue.
Comment 7 Chase Long 2017-03-29 19:25:55 UTC
Opened https://bugzilla.xamarin.com/show_bug.cgi?id=54241 for the remaining issues.