Bug? Modal dialogs do NOT prevent the dialog hidden behind them from receiving Keyboard Input

Hi, I have been testing a Xamarin Forms application with an Android simulator (GenyMotion), and have noticed some disturbing behavior -

When using the PushModalAsync method to display a modal login dialog, I am using the PC keyboard's tab key to tab between the entry controls on the login dialog.

What is happening though is that controls on the parent page are receiving focus! When I have focus on one of the controls (user name entry) and press tab, it should go to the password entry control, but it is not! It is instead placing focus on a control on the hidden parent page. I can tell this because even though you cannot see the hidden control, if I enter some text, and then login, I can see the text I entered on the entry control on the parent page.

I appreciate that it may not be observed on actual devices, but its very disturbing that (even with a simulator) it is possible for controls on the parent dialog to receive focus when you are displaying a modal dialog.

Surely this is a bug, and should not be possible. Has anyone else seen this bug?

Answers

  • RyanHatfieldOldRyanHatfieldOld USMember, Insider ✭✭✭

    I've got a Asus transformer with a full keyboard, if you post some example code I can run it on there and see if it exists on real devices.

  • PhilipParkerPhilipParker USMember

    Hi Ryan, thanks for the help much appreciated.

    If you post the following into a Xamarin Forms project as its App class you can clearly see the issue (at least for me). I've set the opacity of the modal login page to 0.7 so that you can see when pressing the tab key ( a few times) focus being placed on the parent page's entry field. At which point you can type text into the parent pages entry field. This happens with or without changing the opacity. Changing the opacity just makes it easier to see the issue.

    You're even with this able to press the parent page's 'Show modal dialog button' while within the modal dialog (tab to the button while in the modal dialog, then press enter on the keyboard). This is worse still - if you then click on the modal login dialog's 'Close modal dialog' button, the system generates a runtime exception on the call to PopModalAsync.

    Anyway, here's the sample code:

    public class App
    {
        public static Page GetMainPage()
        {   
            ContentPage rootPage = new ContentPage();
    
            ContentPage loginPage = new ContentPage
            {
                Opacity = 0.7,
                Content = new StackLayout
                {
                    Padding = new Thickness(0, 250, 0, 0),
                    Children =
                    {
                        new Entry { Placeholder = "User Name" },
                        new Entry { Placeholder = "Password" },
                        new Button 
                        { 
                            Text = "Close modal dialog",
                            Command = new Command(() => rootPage.Navigation.PopModalAsync()) 
                        }
                    }
                }
            };
    
            rootPage.Content = new StackLayout
            {
                Children =
                {
                    new Entry { Placeholder = "Root page entry - should not get focus" },
                    new Button
                    { 
                        Text = "Show modal dialog",
                        Command = new Command(() => rootPage.Navigation.PushModalAsync(loginPage))
                    }
                }
            };
    
            return new NavigationPage(rootPage);
        }
    }
    
  • PhilipParkerPhilipParker USMember

    bump

  • PhilipParkerPhilipParker USMember

    bump. anyone else seen this? confirmation of issue from xamarin ?

  • IgorHudolinIgorHudolin USMember

    In my test application I have a problem when I do PushModalAsync of the page with Entry and try to enter text in that Entry the application becomes very unresponsive, like I could enter one character in 10 seconds. When I call the same Page with PushAsync everything works OK. Will do some more digging if I can find the problem

  • IgorHudolinIgorHudolin USMember
    edited July 2014

    I did some more testing and I found that if I do PushModalAsync of the page with Entry and the parent has ListView on it the entry becomes unresponsive.

    Here is my test code.

    public static Page GetMainPage ()
    {   
        return new  NavigationPage(new TestPage(false));
    }
    
    public TestPage (bool entry)
    {
        StackLayout l = new StackLayout {
            BackgroundColor = Color.White,
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
            Orientation = StackOrientation.Vertical
        };
    
        if (entry) {
            Entry e = new Entry ();
            l.Children.Add (e);
        } else {
            ListView v = new ListView ();
            l.Children.Add (v);
        }
    
        Button b = new Button ();
        b.Clicked += HandleClicked;
        l.Children.Add (b);
        this.Content = l;
    }
    
    void HandleClicked (object sender, EventArgs e)
    {
        this.Navigation.PushModalAsync (new TestPage(true));
    }
    
Sign In or Register to comment.