Bug 30651 - ListView jumps around while scrolling after items are added to its source
Summary: ListView jumps around while scrolling after items are added to its source
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.4.2
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Rui Marinho
Depends on:
Reported: 2015-06-01 20:04 UTC by alan.spires
Modified: 2015-08-11 12:57 UTC (History)
7 users (show)

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

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 alan.spires 2015-06-01 20:04:03 UTC
When items are added to the ListView's source after it's initial seed scrolling become erratic when scrolling backwards.

To Recreate.....

Open the app and scroll down for a little while, this will populate new items as you reach the bottom of the ListView.
Slowly start scrolling backwards/upwards and you will eventually see the ListView scroll start to jump around. 

The jump seems to appear when the previous cell first comes into view but I could be mistaken on that.

This only appears to happen after adding items. But is making something as simple as a "Load More" at the bottom of a list view impossible.

I have tested this with static and dynamic row heights and the problem exists with all scenarios. Ive included a link to a github project that demonstrates this issue. Thanks!


PS this could be what bug ID 28061 is referring to as well.
Comment 1 Marko 2015-07-03 07:51:05 UTC
I found the solution to this problem (but you need to set the height of the ViewCell manually or use the provided ViewCells): The ListViewRenderer.UnevenListViewDataSource (it's an internal method, so this can only be fixed by Xamarin or if you have magic hax0r skills like me) does not implement the EstimatedHeight method, therefore the height is not set for the Cells (even if you set the height for the ViewCell manually), that are in the source list, but not visible. To fix this, this method must be added:

		public override nfloat EstimatedHeight (UITableView tableView, NSIndexPath indexPath)
			return GetHeightForRow (tableView, indexPath);

Comment 2 alan.spires 2015-07-03 14:57:00 UTC
Nice... You got a code example that i could test?
Comment 3 Marko 2015-07-04 07:02:01 UTC
Sorry, I have no code available. This method involves patching/hacking the Xamarin.Forms.Platform.iOS.dll, so it can only be fixed by Xamarin.
Comment 4 alan.spires 2015-07-21 15:30:10 UTC
Any hints what release this might end up on? Thanks!
Comment 5 Rui Marinho 2015-07-21 17:31:35 UTC
We are trying to get this fix in 1.4.5
Comment 6 Jason Smith [MSFT] 2015-08-03 10:58:17 UTC
Should be fixed in 1.4.5-pre1
Comment 7 alan.spires 2015-08-05 18:50:54 UTC
Please see an updated github project that demonstrates this behavior is still happening... Thanks

Comment 8 alan.spires 2015-08-05 19:08:43 UTC
Run Project, tap button to add more rows.
Scroll to bottom.
Scroll to top to see the jumping behavior.
Comment 9 Rui Marinho 2015-08-06 07:04:28 UTC
i took look at the new reproduction on github, it looks like you now set a Random height to the viewCell OnBindingContextChanged, different from the 1st example right?
Comment 10 Rui Marinho 2015-08-06 08:26:42 UTC
Do you really need the Renderer for the cell or was this just a try? You can remove and cells should size as expected.

About the scrolling issue we have a way to fix it but we are looking at the performance implications to figure a solution.
Comment 11 alan.spires 2015-08-06 11:23:22 UTC
Ok so I updated the project again to help clarify what I am seeing regarding cell sizing. A quick description...

1. The project has uneven rows set to true, the height is not being set anywhere and the renderer is commented out.

2. To simulate a datasource that returns diff strings for diff records in a database a random string generator was put in that creates strings of varying lengths. These varying lengths is what creates the "uneven rows"

3. Based off what I am hearing this should now work fine in 1.5, if you run the project you will see that row heights are way off.

4. If you uncomment the renderer and run the project you will see row heights get corrected, albeit very crudely. 

Please let me know your thoughts, and thanks!
Comment 12 david 2015-08-06 19:22:25 UTC
Forgive me for butting in, but I think your test project isn't realistic. In
your test, because each ViewCell gets recycled as the list scrolls up and down, and your ViewCell just assigns a random number to the cell's height, each cell is going to get a different height each time it comes on screen, which will cause the list to recalculate its height and do its layout again.

Most lists don't change the height of their cells as they scroll. A more
realistic test would assign random heights to the ViewModel before displaying
the list, then look up each row's height in the ViewModel based on its index in the list.
Comment 13 alan.spires 2015-08-06 19:37:26 UTC
I updated the project this morning to be more realistic. It sounds like you are on a previous commit on the test project.