diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2017-05-31 16:37:39 -0600 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2017-05-31 15:37:39 -0700 |
commit | 4cde4ecb6c26318faeba8988ccb2bb162dded560 (patch) | |
tree | e88ad437aa8ba44f9209da54dfe02f966a4f5e3c /Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs | |
parent | 27f6cfbda80fc2b0feb6f6c513e925891d8a645b (diff) | |
download | xamarin-forms-4cde4ecb6c26318faeba8988ccb2bb162dded560.tar.gz xamarin-forms-4cde4ecb6c26318faeba8988ccb2bb162dded560.tar.bz2 xamarin-forms-4cde4ecb6c26318faeba8988ccb2bb162dded560.zip |
[Android] Correctly size content after toggling soft keyboard in Resize mode (#927)
* Repro of 45215
* Consolidate base class for Entry/Editor; add missing Dispose implementations
* Fixed problem with hiding the keyboard and child layout in ScrollViewer
* Force page layout update when navigating back from a keyboard-resized page
* Explanatory comments
* Fix namespace
* Fix possible NRE after device rotation
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs')
-rw-r--r-- | Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs index 1f2c51b6..00e95a98 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs @@ -1,3 +1,4 @@ +using System; using System.ComponentModel; using Android.Content.Res; using Android.Text; @@ -5,12 +6,15 @@ using Android.Text.Method; using Android.Util; using Android.Views; using Java.Lang; +using Xamarin.Forms.Internals; +using Xamarin.Forms.PlatformConfiguration.AndroidSpecific; namespace Xamarin.Forms.Platform.Android { - public class EditorRenderer : ViewRenderer<Editor, EditorEditText>, ITextWatcher + public class EditorRenderer : ViewRenderer<Editor, FormsEditText>, ITextWatcher { ColorStateList _defaultColors; + bool _disposed; public EditorRenderer() { @@ -36,9 +40,9 @@ namespace Xamarin.Forms.Platform.Android ((IElementController)Element).SetValueFromRenderer(Editor.TextProperty, s.ToString()); } - protected override EditorEditText CreateNativeControl() + protected override FormsEditText CreateNativeControl() { - return new EditorEditText(Context); + return new FormsEditText(Context); } protected override void OnElementChanged(ElementChangedEventArgs<Editor> e) @@ -47,18 +51,14 @@ namespace Xamarin.Forms.Platform.Android HandleKeyboardOnFocus = true; - EditorEditText edit = Control; + FormsEditText edit = Control; if (edit == null) { edit = CreateNativeControl(); SetNativeControl(edit); edit.AddTextChangedListener(this); - edit.OnBackKeyboardPressed += (sender, args) => - { - ElementController.SendCompleted(); - edit.ClearFocus(); - }; + edit.OnKeyboardBackPressed += OnKeyboardBackPressed; } edit.SetSingleLine(false); @@ -89,6 +89,26 @@ namespace Xamarin.Forms.Platform.Android base.OnElementPropertyChanged(sender, e); } + protected override void Dispose(bool disposing) + { + if (_disposed) + { + return; + } + + _disposed = true; + + if (disposing) + { + if (Control != null) + { + Control.OnKeyboardBackPressed -= OnKeyboardBackPressed; + } + } + + base.Dispose(disposing); + } + protected virtual NumberKeyListener GetDigitsKeyListener(InputTypes inputTypes) { // Override this in a custom renderer to use a different NumberKeyListener @@ -112,7 +132,7 @@ namespace Xamarin.Forms.Platform.Android void UpdateInputType() { Editor model = Element; - EditorEditText edit = Control; + FormsEditText edit = Control; var keyboard = model.Keyboard; edit.InputType = keyboard.ToInputType() | InputTypes.TextFlagMultiLine; @@ -159,5 +179,11 @@ namespace Xamarin.Forms.Platform.Android Control.SetTextColor(Element.TextColor.ToAndroidPreserveDisabled(_defaultColors)); } } + + void OnKeyboardBackPressed(object sender, EventArgs eventArgs) + { + ElementController?.SendCompleted(); + Control?.ClearFocus(); + } } }
\ No newline at end of file |