Bug 28277 - [iOS] ListView.ScrollTo does not work correctly when cells are of varying sizes
Summary: [iOS] ListView.ScrollTo does not work correctly when cells are of varying sizes
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 1.4.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Rui Marinho
Depends on:
Reported: 2015-03-20 16:48 UTC by Cody Beyer (MSFT)
Modified: 2018-01-03 10:54 UTC (History)
25 users (show)

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

a (28.22 KB, application/x-zip-compressed)
2015-05-28 18:27 UTC, Chris King

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 Cody Beyer (MSFT) 2015-03-20 16:48:10 UTC
### Description

The following test case contains two listviews, one populated by items of varying sizes, the other populated by items of the same size. When you add an item, it is expected that the list scroll to the end. This works well in the view which is populated by equal sized items, but the listview does not properly scroll to the end in the view with the differently sized items

### Video


### Test Case


### Steps To Reproduce

1. Open linked project
2. Deploy to iOS Simulator
3. Add items a lot in the first page
4. scroll to the top
5. add item
6. notice that you do not scroll to the end
7. go to page two
8. repeat steps 3-5
9. notice you do scroll to the end

### Expected Results

Both pages should behave in a similar manner

### Actual Results

Page two scrolls to the end when you add new items, page one does not

### Versions

=== Xamarin Studio ===

Version 5.8 (build 443)
Installation UUID: d1ae49a4-0e18-4c19-800a-f97c5cf348b0
	Mono 3.12.1 ((detached/b7764aa)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312010000

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: ccfcd59
Build date: 2015-03-10 02:20:32-0400

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/beyerc/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 508000443
Git revision: 73883239470cbe8e261c94d95f7c3d0452fd393b
Build date: 2015-03-10 07:22:51-04
Xamarin addins: a2ff7b617f09d9c45d8bbf3d010b5db0d7d36100

=== Operating System ===

Mac OS X 10.10.2
Darwin Codys-MBP 14.1.0 Darwin Kernel Version 14.1.0
    Thu Feb 26 19:26:47 PST 2015
    root:xnu-2782.10.73~1/RELEASE_X86_64 x86_64
Comment 1 Udham Singh 2015-03-24 11:56:10 UTC
I have checked this issue with the help of sample app and steps given in bug description and able to reproduce the reported behaviour. Please refer the screencast : http://www.screencast.com/t/LfqtO4lAeL

System Log : https://gist.github.com/Udham1/812cac4864a83a99851e
Ide Log : https://gist.github.com/Udham1/ed5d1d38030df9377b8b

Environment info : 

Xamarin.Forms :

=== Xamarin Studio ===

Version 5.8.2 (build 5)
Installation UUID: ce927b2a-2c07-44c5-b186-09cfdafba6dc
	Mono 3.12.1 ((detached/0849ec7)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312010003

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: f5d0c5e
Build date: 2015-03-20 06:51:49-0400

=== Build Information ===

Release ID: 508020005
Git revision: 541c06a4f6c95383333375d56fd6c23ce48cb916
Build date: 2015-03-20 09:23:08-04
Xamarin addins: 02510c4990dee3475c282b3182d588975a63ff07

=== Operating System ===

Mac OS X 10.9.5
Darwin Xamarin76s-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 2 Chris King 2015-05-28 18:27:41 UTC
Created attachment 11380 [details]
Comment 3 Jason Smith [MSFT] 2015-08-03 10:58:31 UTC
Should be fixed in 1.4.5-pre1
Comment 4 Parmendra Kumar 2015-08-10 07:35:52 UTC
I have checked this issue with Xamarin.Forms 1.5.0-pre1 and I am getting two different behavior. I have checked this issue with attached sample project in comment #2

1. Page one doesn't scroll every time to the end when user add new items.

Screencast:  http://www.screencast.com/t/B1d13zm8tN

2. Sometimes, If user add new items the scroll go to end and show a blank screen.

Screencast:  http://www.screencast.com/t/AE3WNFhe8

Hence reopen this issue.

Please follow the screencast and let me know if have missed anything.
Could you please let me know should I file a new bug?
Comment 5 Luke Cashion-Lozell 2015-09-16 22:36:15 UTC
This is definitely still broken. I've installed today in my project and ScrollTo scrolls about 2/3rds of the way down and stops.

If I switch the ListView to HasUnevenRows=false it scrolls just fine.

I've tried scrolling after a 25-250ms delay, on and off the main thread, but no difference.

This is what I'm using:

lstChatMessages.ScrollTo(chatMessages.Last(), ScrollToPosition.End, true);

Here is the definition for chatMessages which is set to the ListView.ItemsSource.

private List<ChatMessage> chatMessages;
Comment 6 Balakrishnan 2016-03-18 17:50:10 UTC
I am also facing the same issue with Xamarin.Forms 2.0.5782.

Is there any fix or workaround available?.
Comment 7 Ray Kelly 2016-04-08 17:43:16 UTC
Also, when using uneven rows, the screen shifts up and then back down when using ScrollTo.  This does not happen when unevenrows=false.   So when adding several items in a listview and calling scrolling to the bottom each time, the screen jumps up and down each time.   Anyone else see this or know how to work around it?
Comment 8 alan.spires 2016-04-08 17:48:27 UTC
Using a delay seems to work.

        public static void ScrollToWithDelay(this ListView lv, object item, ScrollToPosition position, bool animated = true)
            Device.StartTimer(TimeSpan.FromMilliseconds(50), () =>
                    try {
                        lv.ScrollTo(item, position,animated);
                    } catch (Exception ex) {

                    return false;
Comment 9 Ray Kelly 2016-04-08 18:30:24 UTC
dirty dirty :).  Hopefully they can fix that as well. Thanks!
Comment 10 Jason Smith [MSFT] 2016-04-08 19:10:19 UTC
iOS 9 now has the required features to allow us to make this work.
Comment 11 Ray Kelly 2016-04-13 20:41:15 UTC
I should also add, that when you have rows of varying size.  Just adding a row makes the list jump up when you are scrolled to the bottom.  I cant believe how broken this ListView is.  Even custom renderers cannot get around this issue, I am dead in the water until this gets fixed.
Comment 12 Mike 2016-04-29 13:30:47 UTC
Any update on when this might be addressed?
Comment 13 adrianknight89 2016-05-18 22:27:16 UTC
I'm having this problem with and without uneven rows in the latest XF release. ListView is probably the most important control yet it's broken in a stupid way such as this. Can we please get this fixed asap?
Comment 14 adrianknight89 2016-05-20 02:19:56 UTC
This appears to me to be a Xamarin.iOS bug rather than a Forms bug. 

Xamarin.Forms.Platform.iOS.ListViewRenderer's Control.ScrollToRow(NSIndexPath.FromRowSection(index, 0), position, e.ShouldAnimate); is sending the correct parameters to the iOS assembly.
Comment 15 adrianknight89 2016-05-21 16:05:35 UTC
I take it back. Xamarin.iOS is fine. 

This may be a Forms issue, but I was able to get ScrollTo to function fine for me by setting HasUnevenRows to true AND removing RowHeight from the listview.
Comment 16 John Hardman 2016-06-03 14:35:10 UTC
This is not just an iOS problem. I am finding that ScrollTo fails when uneven rows are used on Android, WinRT 8.1 and UWP, when using XF
Comment 17 François M 2016-07-26 14:59:43 UTC
ScrollTo doesn't work on iOS but does on UWP.
This is for a ListView with UnevenRows = true
Comment 18 John Miller [MSFT] 2016-08-12 14:31:19 UTC
I've been testing the attached sample with XF and while the Add Item does appear to scroll the end, it behaves strangely. It looks like it's reloading all the rows and then going to the end. This might explain why there is such a strange visual animation when adding an item. 


It's just as visible when just clicking Scroll to End when we are already at the end. I'll follow up as I learn more.
Comment 19 John Miller [MSFT] 2016-08-12 16:03:01 UTC
I've not been able to reproduce the issue with the attached sample. I'm testing with and it does scroll to the bottom when adding an item: http://screencast.com/t/Xny1XEDl

However, it does have an unexpected animation which I think should be filed in a new bug for investigation. If anyone has a way to reproduce ScrollTo not working with varying height cells, please upload a new sample. Changing to NEEDINFO until we have this.
Comment 20 John Miller [MSFT] 2016-08-12 16:22:41 UTC
Filed https://bugzilla.xamarin.com/show_bug.cgi?id=43313 per my suggestion in Comment #19.
Comment 21 Ray Kelly 2016-08-22 13:27:33 UTC
How do you run the attached demo?  I get the following error trying to build it.

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0006	Metadata file 'C:\Projects\TestListView\TestListView\TestListView\bin\Debug\TestListView.dll' could not be found	TestListView.iOS	C:\Projects\TestListView\TestListView.iOS\CSC	1	Active
Comment 22 Ray Kelly 2016-08-22 13:52:37 UTC
Sorry, the error above was a build order issue.
Comment 23 Jimmy [MSFT] 2017-01-09 23:09:55 UTC
I was able to reproduce the original issue with Forms 1.4.0 using the attached repro project. However after updating to Forms 2.3.3 the issue appears to be fixed.

If you continue experiencing this issue with the latest version please attach an updated repro project and re-open this report.
Comment 24 chris hu 2017-09-18 19:22:11 UTC
Hi Xamarin Team,
Can we not just simply mark issues as resolved if no progress made or hard to reproduce? This issue is still happening at least in Xamarin.Forms2.3.3.180 and on Android platform too. 
This happens when the last row height is taller than its previous row. Based on my observation, Xamarin.Forms ListView seems to remember the last recorded Row Height(which is the previous shorter row) and use that height value to scroll to the end of list. In this case, if the last row's taller height is not taken into scrolling calculation. 

I will create a new bug case for this since I can not reopen this bug case.