Bug 60976 - [ANDROID] Long time to layout ListView causing stutter in Master drawer closing animation
Summary: [ANDROID] Long time to layout ListView causing stutter in Master drawer closi...
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-12-04 20:18 UTC by Jon Goldberger [MSFT]
Modified: 2017-12-05 19:06 UTC (History)
1 user (show)

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


Attachments
Test Project (268.65 KB, application/zip)
2017-12-04 20:18 UTC, Jon Goldberger [MSFT]
Details


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:
RESOLVED ANSWERED

Description Jon Goldberger [MSFT] 2017-12-04 20:18:03 UTC
Created attachment 25903 [details]
Test Project

## Description

When switching to a detail page that has a ListView with a non-trivial, though not very complex, ViewCell, the layout of the ListView takes long enough to cause a "stutter" in the drawer closing animation. This is only apparent on older devices runnning Android JellyBean. Was tested on:

https://www.gsmarena.com/samsung_galaxy_tab_2_7_0_p3100-4543.php ( by me)
http://www.wepoy.com/product_view_24.html ( by reporting customer)


## Steps to reproduce

1. Open the attached test project

2. Deploy to device similar to those noted above.

3. Open the Menu drawer and select the EmptyPage. Note that drawer closes with smooth animation.

4. Open the Menu drawer and select the ContactsCS Page.

expected result: Menu drawer will close with smooth animation.

actual result: menu drawer stays open until ListView is loaded and then closes with no animation. 



## Notes

The issue ultimately seems to be the amount of time it is taking to layout the page with the ListView. Seeing that there was some issue with bindings generator being fired multiple times ( bug #60699), even though that was only reported for Android API 24+, I changed all of the bindings in the ViewCell to use static text instead. This did not change the page loading time that I could notice, IOW the issue persisted. 

I tried simplifying the ViewCell layout so there was only one Label, and though this improved the issue there was still a "stutter" during the menu close animation.

Also in the OnItemSelected event handler in MainPageCS, the reporting customer was changing the detail page with this code:

> Detail.Navigation.InsertPageBefore(page, Detail.Navigation.NavigationStack[0]);
> await Detail.Navigation.PopToRootAsync(false);

Changing the above to:
Detail = new NavigationPage(page);

did seem to mitigate the issue as well, but a "stutter" is still experienced.

the reporting customer is caching all of the detail pages and tying to re-use them in order to try to workaround this issue, but I believe this won't help as the page will still get laid out when it appears, and it does seem that the layout is what is taking a while. The test project is using this caching mechanism. Not using the cached pages did not make a noticeable difference. 

I also believe that the page loading is causing the animation for the drawer closing to stutter since all of that work needs to be done on the UI thread. I was able to avoid the stutter by delaying the page load by doing something like the following in OnItemSelected:

> masterPage.ListView.SelectedItem = null; // Original project called this at the end of the OnItemSelected handler. 
> IsPresented = false;                     // Moved it to before the page change so the animation could start before the page change
>
> await Task.Run( async () => {
>     await Task.Delay(150);
>     Device.BeginInvokeOnMainThread(() =>{
>         Detail = new NavigationPage(page);
>     });
> }); 

The above allows the drawer close animation to complete smoothly, but then the detail page is blank until the page is laid out. so all this effectively does is allow the animation to complete before the page layout interrupts the UI thread.
 

I did not note this issue on any simulator or newer devices


## Environment

Test project using Forms 2.4.0.38779 but I tested on 2.5.0 and did not see any difference.

=== Visual Studio Community 2017 for Mac ===

Version 7.2.2 (build 11)
Installation UUID: f86726f2-bd5d-4610-867e-44e82f306ca2
Runtime:
	Mono 5.4.1.6 (2017-06/1f4613aa1ac) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 504010006

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	2.0.0
	1.1.1
	1.0.4
	1.0.0
SDK: /usr/local/share/dotnet/sdk/2.0.0/Sdks
SDK Versions:
	2.0.0
	1.0.1
	1.0.0-preview2-003121
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.5.6
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 9.1 (13532)
Build 9B55

=== Xamarin.iOS ===

Version: 11.3.0.47 (Visual Studio Community)
Hash: 51128b8c
Branch: xcode9.1
Build date: 2017-10-31 22:42:13-0400

=== Xamarin.Android ===

Version: 8.0.2.1 (Visual Studio Community)
Android SDK: /Users/jongoldberger/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		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)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)
		7.0   (API level 24)
		7.1   (API level 25)
		8.0   (API level 26)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 26.0.2
SDK Build Tools Version: 26.0.2

Java SDK: /usr
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin.Mac ===

Version: 3.8.1.0 (Visual Studio Community)

=== Xamarin Inspector ===

Version: 1.3.2
Hash: 461f09a
Branch: 1.3-release
Build date: Tue, 03 Oct 2017 18:26:57 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 702020011
Git revision: b604c37c5a4a2f0919b45ffbe2aaad9fe040af31
Build date: 2017-11-01 08:31:43-04
Xamarin addins: d57dc14cbd4eb166ee62bab585965ab78d3650bc
Build lane: monodevelop-lion-d15-4

=== Operating System ===

Mac OS X 10.13.1
Darwin 17.2.0 Darwin Kernel Version 17.2.0
    Fri Sep 29 18:27:05 PDT 2017
    root:xnu-4570.20.62~3/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

Internet of Things (IoT) development (Preview) 7.1
Comment 2 Samantha Houts [MSFT] 2017-12-05 01:03:23 UTC
Thank you for your submission. At this time, all new reports should be made on the Xamarin.Forms GitHub Issues repository. Please resubmit this report at https://github.com/xamarin/Xamarin.Forms/issues. This Bugzilla report will now be closed and will not be monitored.