Bug 45723 - Entry / Editor and a Button. Tapping the button dismisses the keyboard
Summary: Entry / Editor and a Button. Tapping the button dismisses the keyboard
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.2.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Samantha Houts [MSFT]
URL:
: 57377 ()
Depends on:
Blocks:
 
Reported: 2016-10-20 08:26 UTC by François M
Modified: 2018-03-20 17:41 UTC (History)
13 users (show)

Tags: entry, keyboard, fr
Is this bug a regression?: Yes
Last known good build: 2.1.06259

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 François M 2016-10-20 08:26:45 UTC
This bug is the same one as in 40121 however it is wrongly titled and described there.

It is a regression on version 2.2 and onward (latest available at time of writing is 2.3.2.127).
On version 2.1, tapping a Button didn't dismiss the keyboard when the focus was on an Entry or and Editor. From version 2.2 onward, tapping a Button dismisses the keyboard.


Simple repro page:

public class EditorAndButtonReproPage : ContentPage
    {
        public EditorAndButtonReproPage()
        {
            BackgroundColor = Color.Gray;
            Padding = 50;
            var editor = new Editor {HorizontalOptions = LayoutOptions.FillAndExpand};
            var editorButton = new Button {Text = "OK", HorizontalOptions = LayoutOptions.End};
            var editorLayout = new StackLayout {Orientation = StackOrientation.Horizontal, Children = { editor, editorButton}, VerticalOptions = LayoutOptions.Start};
            var endtry = new Entry { Placeholder = "Entry", HorizontalOptions = LayoutOptions.FillAndExpand };
            var entryButton = new Button { Text = "OK", HorizontalOptions = LayoutOptions.End };
            var entryLayout = new StackLayout { Orientation = StackOrientation.Horizontal, Children = { endtry, entryButton }, VerticalOptions = LayoutOptions.Start };
            Content = new StackLayout {Children = {editorLayout, entryLayout}};
        }
    }
Comment 2 François M 2016-10-21 16:24:12 UTC
Workaround:

public class PageNoEndEditingGestureRenderer : PageRenderer
    {
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            View.GestureRecognizers = null;
        }
    }
Comment 3 François M 2016-10-28 06:49:43 UTC
The workaround doesn't work when the page is pushed within a NavigationPage.
The NavigationRenderer does a lot of things calling GetRenderer in many places so I'm lost but somewhere it "cancels" View.GestureRecognizers = null.
Comment 4 adrianknight89 2016-11-24 19:20:47 UTC
See https://github.com/xamarin/Xamarin.Forms/pull/560
Comment 5 François M 2016-11-25 08:25:19 UTC
Tks a lot for looking into it.
Not sure I understand your change though. I'll try to pull your changes and see. Does it solve both of my issues described? i.e View.EndEditing(true) when taping on a VisualElement but also the fact that View.GestureRecognizers = null doesn't work within a NavigationPage?
Comment 6 adrianknight89 2016-11-27 02:23:26 UTC
You'd need to make your buttons first responders so that EndEditing is not called. myButton.On<iOS>().SetCanBecomeFirstResponder(true);

I tested View.GestureRecognizers = null in a NavigationPage, and it worked for me.

Removing gesture recognizers is probably not a good idea. For example, XF might add now or in the future gesture recognizers for some hidden work that you wouldn't be able to leverage.
Comment 7 François M 2016-11-28 08:02:37 UTC
I agree that removing gesture is not a good idea. It was a temporary workaround.

I'll try your suggestion that seems to be the new platform specific feature introduced in 2.3.3. In such case, there wouldn't be any needs for a code change in XF, would it?

With regards to the NavigationPage, if your suggestion works then we can forget about it. Otherwise, I'll try to put a simple repro case together.
Comment 8 adrianknight89 2016-11-28 15:29:57 UTC
Platform specifics is a new feature introduced in 2.3.3, but the property I added is a new PR. It would need to be approved and merged before you can use it. If it's released, then yes there is no need for code change. It's a property you can turn on and off.
Comment 9 Jimmy [MSFT] 2017-06-13 18:49:08 UTC
*** Bug 57377 has been marked as a duplicate of this bug. ***
Comment 10 David Ortinau [MSFT] 2017-06-19 22:08:06 UTC
We need to get that PR merged to address this issue. I'm tracking this now and will see it moved forward.
Comment 11 Cliff Cawley 2017-11-23 21:53:41 UTC
Can we get this one merged please? The Pull request has been open for a year now :|
Comment 12 Paul Brenner 2018-03-19 20:06:25 UTC
See https://github.com/xamarin/Xamarin.Forms/issues/2136
Comment 13 Samantha Houts [MSFT] 2018-03-20 17:41:58 UTC
Please follow the GitHub issue for updates. Thank you!