Bug 26121 - Android - ListView.ScrollTo doesn't work when ListView inside TabbedPage
Summary: Android - ListView.ScrollTo doesn't work when ListView inside TabbedPage
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms (show other bugs)
Version: 1.3.1
Hardware: Other Other
: Normal normal
Target Milestone: 1.3.3
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-01-16 16:00 UTC by daniel.luberda
Modified: 2015-02-03 12:52 UTC (History)
5 users (show)

Tags:
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:
Status:
VERIFIED FIXED

Description daniel.luberda 2015-01-16 16:00:12 UTC
BUG 1:
STEPS: 
1. Run app
2. Switch to Second tab
3. Switch to First tab
4. Manually swipe the ListView to the beginning
5. Switch to Second tab 
6. 3. Switch to First tab

ScrollTo doesn't work anymore!!! 

BUG 2:
1. Change in code
listView.ScrollTo(collection.Last(), ScrollToPosition.MakeVisible, false);
to 
listView.ScrollTo(collection.Last(), ScrollToPosition.End, false);

2. Run app - error occurs!

BUG 3:
- ListView.ScrollTo is animated if animated bool set to false! 




SOURCE: 

using System;

using Xamarin.Forms;
using System.Collections.ObjectModel;
using System.Linq;

namespace XamarinTest
{
	public class XamarinListViewScrollToBug : TabbedPage
	{
		public XamarinListViewScrollToBug()
		{
			this.Children.Add(new XamarinListViewScrollToBugPage1());

			this.Children.Add(new XamarinListViewScrollToBugPage2());
		}
	}

	public class XamarinListViewScrollToBugPage1 : ContentPage
	{
		ListView listView;

		public XamarinListViewScrollToBugPage1()
		{
			Title = "Page1";

			listView = new ListView() {
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand,
				HasUnevenRows = true, 
				ItemsSource = collection,
				ItemTemplate = new DataTemplate(typeof(CellTemplate)) 
			};

			Content = listView;

			FillTheList();
		}

		ObservableCollection<Tuple<string>> collection = new ObservableCollection<Tuple<string>>();

		protected override void OnAppearing()
		{
			base.OnAppearing();
			Console.WriteLine("SCROLLING TO THE END OF THE LIST");
			//TODO not working correctly
			listView.ScrollTo(collection.Last(), ScrollToPosition.MakeVisible, false);
			//TODO error!!!!
			//listView.ScrollTo(collection.Last(), ScrollToPosition.End, false);
		}

		void FillTheList()
		{
			collection.Clear();

			for (int i = 0; i < 100; i++)
			{
				var item = new Tuple<string>(
					string.Format("{0} {0} {0} {0} {0} {0}", i)
				);


				collection.Add(item);
			}
		}

		class CellTemplate : ViewCell
		{
			public CellTemplate()
			{
				Label cellLabel = new Label() {
					HorizontalOptions = LayoutOptions.FillAndExpand,
				};

				cellLabel.SetBinding(Label.TextProperty, new Binding("Item1", BindingMode.OneWay));

				StackLayout root = new StackLayout() {
					Children = 
					{
						cellLabel
					}
					};

				View = root;
			}
		}
	}

	public class XamarinListViewScrollToBugPage2 : ContentPage
	{
		public XamarinListViewScrollToBugPage2()
		{
			Title = "Page2";
		}
	}
}
Comment 1 daniel.luberda 2015-01-16 16:02:49 UTC
The second bug error is:

System.Diagnostics.Debugger.Mono_UnhandledException (ex={System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.Forms.Platform.Android.ListViewRenderer.OnScrollToRequested (object,Xamarin.Forms.ScrollToRequestedEventArgs) <IL 0x00128, 0x005aa>
at Xamarin.Forms.Platform.Android.ListViewRenderer.OnLayout (bool,int,int,int,int) <IL 0x00047, 0x00117>
at Xamarin.Forms.Platform.Android.FormsViewGroup.n_OnLayout_ZIIII (intptr,intptr,bool,int,int,int,int) <IL 0x00012, 0x00083>
at (wrapper dynamic-method) object.196a5b5b-5bdf-4f1c-8323-e2fb7c2375cb (intptr,intptr,bool,int,int,int,int) <IL 0x0002f, 0x0004b>
}) in 


Don't forget to change tab to second tab and then back
Comment 2 Rajneesh Kumar 2015-01-19 07:24:29 UTC
I have checked this issue and able to reproduce this. To reproduce this issue I have followed the steps and instruction provided in bug description. I have used code provided in bug description in my test case.
Sample URL: https://www.dropbox.com/s/lt 
Steps I followed:

1. Download sample app and open in XS.
2. Android as startup project.
3. Build and deploy it on emulator, it deploy successfully.
4. Switch to Second tab
5. Switch to First tab
6. Manually swipe the ListView to the beginning
7. Switch to Second tab 
8. 3. Switch to First tab

Observed that ScrollTo doesn't work anymore,  I also observed that if I comment Line 62 and uncomment line no 64 in MyPage.cs file [In attached test case]. getting exception. Here is the screencast for the same:http://www.screencast.com/t/jMFqpCAGFlR8

==Supplement info==
Exception details: https://gist.github.com/Rajneesh360Logica/908e35af50242efe7eb4
Application Output: https://gist.github.com/Rajneesh360Logica/66034a2081c59c2c2f87
Build Output: https://gist.github.com/Rajneesh360Logica/acef29537d5236408bae
Ide Logs: https://gist.github.com/Rajneesh360Logica/4f9f47e1c0457b1be3f6
Android tools Log: https://gist.github.com/Rajneesh360Logica/8cd47ad5016ece20dc6f
Device Log: https://gist.github.com/Rajneesh360Logica/f2d01b7c2de7785414bd

Environment Info:

Xamarin.Forms: 1.3.1.6296

=== Xamarin Studio ===

Version 5.7.1 (build 13)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Xamarin.Android ===

Version: 4.20.0.28 (Business Edition)
Android SDK: /Users/MM/Desktop/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    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.iOS ===

Version: 8.6.1.9 (Business Edition)
Hash: d8e6436
Branch: 
Build date: 2015-01-18 17:38:20-0500

=== Xamarin.Mac ===

Version: 1.12.0.4 (Business Edition)

=== Build Information ===

Release ID: 507010013
Git revision: 8e357d6be321e716f361ebc9591e4cee7f217c21
Build date: 2015-01-15 14:23:22-05
Xamarin addins: a6842a7727f64e956f942b8160f7835c9d9076a4

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.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 3 Jason Smith [MSFT] 2015-02-02 16:22:55 UTC
Should be fixed in 1.3.3-pre1
Comment 4 Rajneesh Kumar 2015-02-03 09:18:36 UTC
I have checked this issue with the following builds: 

Xamarin.Forms Version: 1.3.3.6318-pre1
Xamarin Studio Version 5.7.1 (build 16)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
Mono 3.12.0 ((detached/a813491)
GTK+ 2.24.23 (Raleigh theme)
Package version: 312000068
Xamarin.Android Version: 4.20.0.28 (Business Edition)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
=== Build Information ===
Release ID: 507010016
Git revision: f12fcaf4707ab436bee2df6263eb5333197b262c
Build date: 2015-02-01 21:06:05-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0
Operating System Mac OS X 10.9.5
Darwin MacMini.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

Now, I  observed that ScrollTo is working fine. I also observed that if I comment Line 62 and uncomment line no 64 in MyPage.cs file [In attached test case]. not getting any type of error/exception. Here is the screencast for the same: http://www.screencast.com/t/cDKN8M9c

This issue has been fixed, hence closing this issue.