[Android] Keyboard should not change layout while dismissing on Entry and Editor...
authoradrianknight89 <adrianknight89@outlook.com>
Thu, 26 Jan 2017 17:24:37 +0000 (11:24 -0600)
committerKangho Hur <kangho.hur@samsung.com>
Fri, 24 Mar 2017 04:15:53 +0000 (13:15 +0900)
* handle keyboard on entry

* add sample code

* editor changes

* change text

* better fix

* changes

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla43867.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Platform.Android/Renderers/EditorEditText.cs
Xamarin.Forms.Platform.Android/Renderers/EntryEditText.cs

diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla43867.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla43867.cs
new file mode 100644 (file)
index 0000000..938200c
--- /dev/null
@@ -0,0 +1,49 @@
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+using Xamarin.Forms.PlatformConfiguration;
+using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+       [Preserve(AllMembers = true)]
+       [Issue(IssueTracker.Bugzilla, 43867, "Numeric keyboard shows text / default keyboard when back button is hit", PlatformAffected.Android)]
+       public class Bugzilla43867 : TestContentPage // or TestMasterDetailPage, etc ...
+       {
+               protected override void Init()
+               {
+                       Application.Current.On<Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
+
+                       Content = new StackLayout
+                       {
+                               Spacing = 10,
+                               VerticalOptions = LayoutOptions.Center,
+                               Children =
+                               {
+                                       new Label
+                                       {
+                                               Text = "Focus and unfocus each element 10 times using the Back button. Observe that the soft keyboard does not show different characters while hiding. Now repeat the test by tapping off of the element."
+                                       },
+                                       new Entry
+                                       {
+                                               WidthRequest = 250,
+                                               HeightRequest = 50,
+                                               BackgroundColor = Color.AntiqueWhite,
+                                               Keyboard = Keyboard.Numeric
+                                       },
+                                       new Editor
+                                       {
+                                               WidthRequest = 250,
+                                               HeightRequest = 50,
+                                               BackgroundColor = Color.BurlyWood,
+                                               Keyboard = Keyboard.Numeric
+                                       }
+                               }
+                       };
+               }
+       }
+}
\ No newline at end of file
index 2d6ddb5..a8270fd 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43516.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43941.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43663.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43867.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla43735.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla44453.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Bugzilla51536.cs" />
index 2427312..4a6428e 100644 (file)
@@ -23,13 +23,12 @@ namespace Xamarin.Forms.Platform.Android
 
                public override bool OnKeyPreIme(Keycode keyCode, KeyEvent e)
                {
-                       if (keyCode == Keycode.Back && e.Action == KeyEventActions.Down)
-                       {
-                               EventHandler handler = OnBackKeyboardPressed;
-                               if (handler != null)
-                                       handler(this, EventArgs.Empty);
-                       }
-                       return base.OnKeyPreIme(keyCode, e);
+                       if (keyCode != Keycode.Back || e.Action != KeyEventActions.Down)
+                               return base.OnKeyPreIme(keyCode, e);
+
+                       this.HideKeyboard();
+                       OnBackKeyboardPressed?.Invoke(this, EventArgs.Empty);
+                       return true;
                }
 
                public override bool RequestFocus(FocusSearchDirection direction, Rect previouslyFocusedRect)
index de03a41..5c0b7c0 100644 (file)
@@ -23,13 +23,12 @@ namespace Xamarin.Forms.Platform.Android
 
                public override bool OnKeyPreIme(Keycode keyCode, KeyEvent e)
                {
-                       if (keyCode == Keycode.Back && e.Action == KeyEventActions.Down)
-                       {
-                               EventHandler handler = OnKeyboardBackPressed;
-                               if (handler != null)
-                                       handler(this, EventArgs.Empty);
-                       }
-                       return base.OnKeyPreIme(keyCode, e);
+                       if (keyCode != Keycode.Back || e.Action != KeyEventActions.Down)
+                               return base.OnKeyPreIme(keyCode, e);
+
+                       this.HideKeyboard();
+                       OnKeyboardBackPressed?.Invoke(this, EventArgs.Empty);
+                       return true;
                }
 
                public override bool RequestFocus(FocusSearchDirection direction, Rect previouslyFocusedRect)