ScrollView auto scrolls on keyboard visible?

I can see that the ScrollView automatically scrolls up to keep the Entry I clicked on visible when the onscreen keyboard opens. Is there a way to further control this behavior? There is a Login button just below the Entry I clicked on that I also want to stay visible so the user can just click Login instead of having to further scroll up.

Posts

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    wrap your content in a ScrollView

  • @StephaneDelcroix‌
    Did you even read the question at all before responding?

  • StephaneDelcroixStephaneDelcroix USInsider, Beta ✭✭✭✭

    I read in diagonal, sorry. I missed the point of the question. No there's no way to control that scrolling for now.

  • @StephaneDelcroix‌ Thanks for the quick response. I love Xamarin.Forms, but it is these little things that make it hard to feel comfortable using it for a production app. I still feel like I have more control with MvvmCross. I have no doubt it will get better over time.

  • Chris.CastrianniChris.Castrianni USUniversity ✭✭

    Ok, I know this is going to sound only marginally believable, but...

    Has anyone tried the standard ScrollView-wrapped content approach discussed in this thread to keep the focused control visible when the on-screen keyboard appears on a landscape iPad with the home button on the left? The whole page scrolls off the screen leaving only a blank screen. Surprisingly, when the home button is on the right and the keyboard appears, it seems to work correctly.

  • CraigDunnCraigDunn USXamarin Team Xamurai

    Do you have a specific example @ChrisCastrianni‌ that we can try to reproduce?

  • Chris.CastrianniChris.Castrianni USUniversity ✭✭

    You bet. I was able to distill my scenario down to the following fairly simple repro case. Again, if the home button is on the left, when the MyEntry field is given focus, forcing the keyboard to appear, the content on the screen immediately scrolls off leaving a blank page and the keyboard. However, if the home button is on the right, giving focus to the MyEntry field behaves as I would expect.

    I am using Xamarin.Forms v1.2.2.6243.

    [Register("AppDelegate")]
    public partial class AppDelegate : UIApplicationDelegate
    {
        UIWindow window;
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Forms.Init();
            window = new UIWindow(UIScreen.MainScreen.Bounds)
            {
                RootViewController = new NavigationPage(new MainPage()).CreateViewController()
            };
            window.MakeKeyAndVisible();
            return true;
        }
    }
    
    public class MainPage : ContentPage
    {
        protected override void OnAppearing()
        {
            base.OnAppearing();
            Navigation.PushModalAsync(new TestPage());
        }
    }
    
    public class TestPage : ContentPage
    {
        public TestPage()
        {
            var myEntry = new Entry
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center,
                Placeholder = "MyEntry",
                WidthRequest = 200,
                HeightRequest = 50
            };
            Content = new ScrollView { Content = myEntry };
        }
    }
    
  • CraigDunnCraigDunn USXamarin Team Xamurai

    Okay so that's very weird - it behaves differently for me too, depending on whether it's on the left or right edge!

    Also, to confirm what I'm seeing, this only happens when the page is rendered as a modal (eg. using this call in OnAppearing)

     Navigation.PushModalAsync(new TestPage());
    

    but not if the page is set to be the root... when I create the set the page up with either of these two:

    RootViewController = new NavigationPage(new TestPage()).CreateViewController()
    // OR
    RootViewController = new TestPage().CreateViewController()
    

    then the ScrollView/Entry behaves as you'd expect (ie. it doesn't disappear!). Is that the same thing you have seen? Either way, it seems like the case above it definitely a bug ~ would you mind adding it to bugzilla so it can be investigated further (the advantage of this is that you'll also be emailed as it gets updated).

    This isn't a solution to the problem, but have you considered an alternative approach to popping up a modal window in OnAppearing? There are different ways to show a login screen, for example, in the LoginDemo. Just a thought.

  • Chris.CastrianniChris.Castrianni USUniversity ✭✭

    Thanks again @CraigDunn. I have added it to Bugzilla here.

    Yes, we considered using a technique similar to that employed by the LoginDemo. In fact, we actually prefer that technique. Unfortunately, using that technique (i.e. swapping RootViewControllers) can end up displaying duplicate Alerts and crashing the app with an InvalidOperationException as discussed in this bug.

    Using the LoginDemo solution, if I Login properly, then Logout, then click Login without providing credentials, you get the duplicate alerts and subsequent crash.

  • CraigDunnCraigDunn USXamarin Team Xamurai

    If you are able to easily reproduce that duplicate alerts & crash, I'd encourage you to add a simple reproduction to that bug. I thought that was fixed in the latest release of 1.2.2.

  • Hey guys,

    This looks like a pretty simple bug to solve but it's opened for 3 months so far without any interactions.

    You know what would be a great thing? To open-source the Xamarin.Forms code. Why not? Specially after this huge Microsoft move on this direction. There are so many simple bugs and missing features that the community could easily fix/implement on Forms. The scrolling capabilities of Xamarin.Forms are almost null, it's such a very important and simple feature, I just don't know why it hasn't been implemented yet. For example, you just can't manually scroll a ScrollView on Forms, you have to implement an event and a renderer for each platform. Awful.

    Xamarin folks told us on this year's Evolve that Forms is a top priority for the company but the last version (1.2.3) has been released like months ago.

    Why don't you guys think about it?

  • DemiVisionDemiVision USMember ✭✭

    The behavior is also broken for me (regardless of left or right landscape). Some Entry fields scroll to the top correctly. But ones lower on the screen scroll off screen entirely. And the top ones scroll even though they do not need to scroll at all (which looks really weird). Is there a way to override this behavior (or turn it off entirely if I know the Entry is already in view)? Preferably an option without custom renderers :)

    I love Xamarin.Forms, but this is another example of the annoying little things that keep it from really having commercial quality UI polish :(

  • ChristianDanielChristianDaniel DEMember
    edited February 2015

    Confirmed on my site too. I would expect, that a Xamarin guy help us finding a workaround. Maybe with a custom renderer or whatever. Now, i have a customers project and need to update the whole project to the new framework, spend a lot of time fixing the "new" bugs that come with the new bits, just to fix that "little" issue.

    We are not saving any time by using Xamarin right now, because we are always looking for workarounds for these little weired behaviors. I am really pissed right now! I am asking myself: Did they hear about Unittests at Xamarin Team???

  • DemiVisionDemiVision USMember ✭✭

    Open sourcing Xamarin.Forms would definitely be awesome! A lot of these annoying bugs would be fixed very quickly. I still have hope though that Xamarin will continue to polish these issues, but it seems to be very slow moving. I also have several issues with MasterDetailPage, NavigationPage, etc. Anyone from Xamarin listening? Please help!

  • mramra USMember ✭✭

    The problem also appears with Navigation.PushAsync(...).
    When I tap into the Entry Field the keyboard opened and the ScrollView scrolls down to bottom and then scrolls back to the top where the Entry Field is placed...

    Can I set the automatic focus behaviour off for the Entry Field??

    Thanks

Sign In or Register to comment.