Bug 32213 - On Windows, ScrollToAsync does not take into account the presence of the Toolbar
Summary: On Windows, ScrollToAsync does not take into account the presence of the Toolbar
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 2.0.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-07-21 11:47 UTC by John Hardman
Modified: 2017-06-16 14:59 UTC (History)
6 users (show)

Tags: Windows WinRT ScrollView ScrollToAsync Toolbar iOS
Is this bug a regression?: ---
Last known good build:


Attachments
Screen recording showing problem on XF 2.0 (1.12 MB, application/octet-stream)
2016-01-05 11:36 UTC, John Hardman
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 NOT_REPRODUCIBLE

Description John Hardman 2015-07-21 11:47:50 UTC
On Windows, with a form that contains multiple Entry views (and other views) in a ScrollView, using ScrollToAsync to make the last Entry visible fails to make it visible if a Toolbar is present. It seems ScrollToAsync does not take into account the presence of the Toolbar, and leaves the Entry behind the toolbar, even though the user can type into the Entry.
Comment 1 Chris King 2015-07-22 13:31:59 UTC
Thanks for submitting this bug. Do you have small reproduction of this bug? If so, could you please attach it?

Warm regards,
XFT
Comment 2 John Hardman 2015-12-10 23:33:44 UTC
Hi Chris.
It's not the ScrollToAsync that's the issue. It's more that the Page itself does not layout its Content in the space that's available above the toolbar.
The code below is a slightly tweaked version of a piece of code that Xamarin created to try to repro 34909 (not one of the bugs I reported). If you run this on Windows RT, and press the "Add item" button a couple of times, you will find that you cannot scroll the page to get to the "Add item" or "Remove item" buttons. The ScrollView goes behind the Toolbar, making the bottom of it inaccessible. Unless there is something else the code should do, I suspect that the layout engine should adjust the space available for the Page Content, to take into account the presence of the Toolbar.

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 }
            };

            ToolbarItem toolbarItem = new ToolbarItem
            {
                ClassId = "MyApp_ClassId_ToolbarItem",
                Order = ToolbarItemOrder.Primary,
                Priority = 0,
                StyleId = "MyApp_ToolbarItem",
                Text = "Ok"
            };

            this.ToolbarItems.Add(toolbarItem);

            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;

                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 3 John Hardman 2015-12-14 18:48:43 UTC
Changing back to New (as per previoud guidelines) as information provided above.
Comment 4 John Miller [MSFT] 2016-01-04 17:05:17 UTC
@John,

I was not able to reproduce this with Xamarin.Forms 2.0.0. 

Please confirm: http://screencast.com/t/NArSN4l9
Comment 5 John Hardman 2016-01-05 10:17:34 UTC
@JohnMiller,

Yes, the problem still exists using XF 2.0

My packages.config contains:
<package id="Xamarin.Forms" version="2.0.0.6490" targetFramework="win81" />

Your screencast is not showing the toolbar. If you rectify that, you will see the problem.

This is the code, exactly as I use it to demonstrate the issue. This is called from the constructor for the page class, which inherits from ContentPage.

        private static int numberOfButtons = 3;
        StackLayout layout;
        Button addItem, removeItem;
        ScrollView scrollView;

        private void CreateDummyPage_ScrollingNotHappeningOnWindows()
        {
            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 }
            };

            ToolbarItem toolbarItem = new ToolbarItem
            {
                ClassId = "MyApp_ClassId_ToolbarItem",
                Order = ToolbarItemOrder.Primary,
                Priority = 0,
                StyleId = "MyApp_ToolbarItem",
                Text = "Ok"
            };

            this.ToolbarItems.Add(toolbarItem);

            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;

                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 6 John Hardman 2016-01-05 11:36:08 UTC
Created attachment 14442 [details]
Screen recording showing problem on XF 2.0

Please find attached screen recording. As the number of buttons increases, it becomes impossible to scroll to the buttons at the bottom of the collection. This happens when there is a toolbar visible on Windows.
Comment 7 John Hardman 2016-01-06 11:03:11 UTC
It would appear that on Windows, the toolbar uses the BottomAppBar. However, the Xamarin layout manager does not seem to take into account the presence of the BottomAppBar. When the BottomAppBar is visible, I would expect the Xamarin layout manager to adjust the size available to the Page Content, so that any ScrollView within the Content behaves as expected. However, as that doesn't seem to happen right now (which I believe to be a bug), it is impossible to scroll to the end of a ScrollView, as the final items are hidden behind the BottomAppBar.
Comment 8 John Hardman 2016-01-06 11:04:00 UTC
Updated the version number to 2.0.0 (although the problem was also present  before 2.0.0)
Comment 9 E.Z. Hart [MSFT] 2016-02-08 19:42:08 UTC
(In reply to John Hardman from comment #8)
> Updated the version number to 2.0.0 (although the problem was also present 
> before 2.0.0)

John,

I've tried to reproduce the behavior in your screencast using the code you posted above and version 2.0.0.6490, but so far I haven't had any luck (with or without the toolbar visible). It's possible I'm missing something - could you attach your full repro project?
Comment 10 Jason Smith [MSFT] 2016-04-11 09:07:49 UTC
Thank you for your bug report. As we have not received the information requested, we cannot properly triage your bug and are marking it resolved. If you have the requested reproduction please re-open the bug :)

Warm regards,
Xamarin Forms Team
Comment 11 John Hardman 2016-09-13 14:31:54 UTC
The same problem happens on iOS. See http://forums.xamarin.com/discussion/77096/how-to-prevent-scrollview-going-behind-secondary-toolbar-items#latest for explanation and screenshot.
Comment 12 John Hardman 2016-09-13 14:32:21 UTC
I should have mentioned that on iOS, it's when using secondary toolbaritems.
Comment 13 David Ortinau [MSFT] 2017-06-16 14:59:40 UTC
I'm not able to reproduce this using 2.3.4. If this issue is still present on the current stable, please reopen the issue with a reproduction project and full environment details.