Bug 34909 - Scroll View doesn't show newly added stack layout children without calling scrolltoasync.
Summary: Scroll View doesn't show newly added stack layout children without calling sc...
Status: RESOLVED NORESPONSE
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.4.4
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Samantha Houts [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2015-10-15 14:00 UTC by Andy
Modified: 2016-01-12 19:32 UTC (History)
3 users (show)

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


Attachments
Unable to Reproduce (3.57 MB, application/zip)
2015-10-15 15:22 UTC, Michael
Details
Unable to reproduce 2 (3.61 MB, application/zip)
2015-11-20 17:02 UTC, Samantha Houts [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 NORESPONSE

Description Andy 2015-10-15 14:00:00 UTC
Make a scroll view that contains a stack layout. Dynamically add and remove content to that stack layout. Eventually, the scroll view will not show any of the contents. A call to ScrollView.ScrollToAsync(0,0,false) does cause it to start showing again. This is not noted anywhere and took days to figure out. When using Android Marshmallow API 23 to build, the stack layout contents are never visible without a call to ScrollToAsync.
Comment 1 Michael 2015-10-15 15:22:30 UTC
Created attachment 13351 [details]
Unable to Reproduce

I was unable to reproduce the behavior descibed. The attached sample displays a Stacklayout in a ScrollView. The StackLayout is initially loaded with 10 buttons. You can add and remove buttons and the ScrollView works as expected with all content displayed. I did not have to use ScrollView.ScrollToAsync to make the content appear. 

If you can provide us with a sample that reproduce this behavior or modify the sample I have attached, that would be greatly appreciated.

This was tested using Xamarin.Forms 1.5.0 package

Build information:
Xamarin Studio
Version 5.9.7 (build 9)
Installation UUID: 189a3270-f284-4fad-a71a-49d491a41a47
Runtime:
	Mono 4.0.4 ((detached/d481017)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400040004

Apple Developer Tools
Xcode 7.0.1 (8228)
Build 7A1001

Xamarin.iOS
Version: 9.0.1.20 (Enterprise Edition)
Hash: d8e9592
Branch: master
Build date: 2015-09-18 23:22:05-0400

Xamarin.Android
Version: 5.1.6.7 (Enterprise Edition)
Android SDK: /Users/michaelw/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		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)
		5.1    (API level 22)
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: 2.0.2.111 (Enterprise Edition)

Build Information
Release ID: 509070009
Git revision: 31fa64709030b3edb971237780a452a4c69943c4
Build date: 2015-09-17 11:44:37-04
Xamarin addins: b105d33d8cd72911ff2cf3ee0b7715d37e5f19a6

Operating System
Mac OS X 10.10.5
Darwin michaelw-mac.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 2 Michael 2015-10-15 15:23:01 UTC
This was also tested against Xamarin.Forms pacakage 1.4.4
Comment 3 Andy 2015-10-15 16:43:59 UTC
We have two scroll views inside of an absolute layout. They are never visible at the same time, but the fix that we've had to implement is in fact not the call to scroll. It is a call to absoluteLayout.RaiseChild(scrollViewNeeded)  (even though the scroll view is already in the proper position in the layout).

The most consistent way to to repro it is to have the scroll view become visible on a button press. If you boot the app, then put it to sleep, then awaken the app from the home screen by clicking its icon, then click the button that shows the scroll view (whew a lot of steps) the content will not be seen. For us, this reproduces the issue every single time.
Comment 4 Samantha Houts [MSFT] 2015-11-20 17:02:25 UTC
Created attachment 13923 [details]
Unable to reproduce 2

Andy,

I altered the attached project to match your description, but I was unable to reproduce the issue you described with 1.4.4 or 1.5.0. The ScrollView appears, and its children are visible as expected, even when I sleep the app and reopen it.

Please try this new project and let me know if you experience the same issue with it. If not, I think we'll need to see a sample project from you that exhibits the behavior.

Also, can you tell me if this issue is happening with a particular emulator or device? 

Thank you!!
Comment 5 John Hardman 2015-12-05 16:23:12 UTC
I can confirm from my own work that ScrollToAsync is required in this scenario - I had to add it to get my own app to behave as expected. However, I am not aware of any documentation that says that a ScrollView should scroll to a newly added view in a StackLayout content. If that expectation is documented then this is a bug.

(note that I am just about to raise a related bug on Windows Phone 8.1 RT, where the ScrollToAsync implemented here fails to scroll - watch out for this if you are also building for Windows targets).
Comment 6 Samantha Houts [MSFT] 2015-12-08 18:43:17 UTC
(In reply to John Hardman from comment #5)

Do you have a project that you can share with us that can help us reproduce the behavior in Android?

Thanks!
Comment 7 John Hardman 2015-12-09 00:23:33 UTC
Sorry Samantha - on re-reading the description, I think I misinterpreted it on my first reading. When I get some time I will create a sample for bug 36651, which may be usable (or easily adaptable) to check this one (34909) as well.
Comment 8 John Hardman 2015-12-09 00:34:54 UTC
Actually Samantha, 34909 might need clarification.

The one line description for 34909 ("Scroll View doesn't show newly added stack layout children without calling scrolltoasync.") matches what I found, and which my repro for 36651 can be used to demonstrate on any platform, including Android.

36651 demonstrates a bug in Xamarin.Forms for Windows where the scroll fails to happen even though ScrollToAsync is called. The fact that ScrollToAsync is required for that simple scenario IMHO may not be a bug (unless it's actually documented that adding a child to a stack layout in a scroll view should result in scrolling, which I don't think it should due to the performance and UX implications).

However, having said that, the more detailed description for 34909 involves criteria that vary from that one liner. This is why I think clarification may be required for 34909.

My repro for 36551 should be easily adaptable to perform the extra steps, but those are steps not required for my 36551 repro.
Comment 9 John Hardman 2015-12-10 22:51:51 UTC
For me, your original "Unable to Reproduce" attachment demonstrates the problem described by the bug title
"Bug 34909 - Scroll View doesn't show newly added stack layout children without calling scrolltoasync."
I execute your code and it doesn't scroll on Android. I don't think that's a bug.

I have tweaked your original code to make it clearer what is happening. The tweaked version is at the bottom of this comment. With the ScrollToAsync commented out, no scrolling happens when the new buttons are added. With the ScrollToAsync not commented out, the scrolling happens.
This is as I would expect (on Android anyway) - not a bug. (Although there is an issue on Windows, which I have raised as 36651).

As mentioned previously, that title doesn't quite match the more detailed description:
"Make a scroll view that contains a stack layout. Dynamically add and remove content to that stack layout. Eventually, the scroll view will not show any of the contents. A call to ScrollView.ScrollToAsync(0,0,false) does cause it to start showing again. This is not noted anywhere and took days to figure out. When using Android Marshmallow API 23 to build, the stack layout contents are never visible without a call to ScrollToAsync."

I also created some code that implements that first more detailed description, but it worked as I would expect on Android.

I haven't tried reproducing the even more detailed second description (the AbsoluteLayout etc). That's more work than I have time for.



using System;

using Xamarin.Forms;

namespace ZyaMusic_ScrollViewBug
{
    public class LandingPage : ContentPage
    {
        private static int numberOfButtons = 3;
        StackLayout layout;
        Button addItem, removeItem;
        ScrollView scrollView;

        public LandingPage()
        {
            layout = new StackLayout();
            for (var i = 0; i < 10; i++)
            {
                layout.Children.Add(new Button { Text = "This is a button" });
            }

            addItem = new Button { Text = "Add Item" };
            removeItem = new Button { Text = "Remove Item" };
            scrollView = new ScrollView { Content = layout };

            Content = new StackLayout
            {
                Children = { scrollView, addItem, removeItem }
            };

            addItem.Clicked += (object sender, EventArgs e) =>
            {
                Button lastButton = null;
                for (int i = 0; i < numberOfButtons; ++i)
                {
                    lastButton = new Button
                    {
                        Text = String.Format("This is button #{0}", i)
                    };
                    layout.Children.Add(lastButton);
                }
                ++numberOfButtons;


                // The following line needs to be uncommented to have scrolling work (only testing on Android today)

                //scrollView.ScrollToAsync(lastButton, ScrollToPosition.End, false);
            };
            removeItem.Clicked += (object sender, EventArgs e) =>
            {
                if (layout.Children.Count != 0)
                    layout.Children.RemoveAt(layout.Children.Count - 1);
            };
        }
    }
}
Comment 10 Jason Smith [MSFT] 2016-01-12 19:32:28 UTC
No response from reporter