From dd9463fca2c008072e9f6ba88cca26495dbae54a Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 23 May 2016 22:50:32 -0400 Subject: [PATCH] OnComplete return type, autocorrect, and autocapitalize implemented for android. --- src/Android/Controls/ExtendedEntryRenderer.cs | 55 +++++++++++++++++++ src/App/Controls/ExtendedEntry.cs | 9 +++ src/App/Enums/ReturnType.cs | 4 +- src/iOS/Controls/ExtendedEntryRenderer.cs | 13 ++++- 4 files changed, 76 insertions(+), 5 deletions(-) diff --git a/src/Android/Controls/ExtendedEntryRenderer.cs b/src/Android/Controls/ExtendedEntryRenderer.cs index 2cc4a257e..f1a4a6dd3 100644 --- a/src/Android/Controls/ExtendedEntryRenderer.cs +++ b/src/Android/Controls/ExtendedEntryRenderer.cs @@ -3,8 +3,11 @@ using System.ComponentModel; using Android.Graphics; using Android.Text; using Android.Text.Method; +using Android.Views.InputMethods; +using Android.Widget; using Bit.Android.Controls; using Bit.App.Controls; +using Bit.App.Enums; using Xamarin.Forms; using Xamarin.Forms.Platform.Android; @@ -27,6 +30,29 @@ namespace Bit.Android.Controls SetBorder(view); SetMaxLength(view); + SetReturnType(view); + + // Editor Action is called when the return button is pressed + Control.EditorAction += (object sender, TextView.EditorActionEventArgs args) => + { + if(view.ReturnType != ReturnType.Next) + { + view.Unfocus(); + } + + // Call all the methods attached to base_entry event handler Completed + view.InvokeCompleted(); + }; + + if(view.DisableAutocapitalize) + { + Control.SetRawInputType(Control.InputType |= InputTypes.TextVariationEmailAddress); + } + + if(view.Autocorrect.HasValue) + { + Control.SetRawInputType(Control.InputType |= InputTypes.TextFlagNoSuggestions); + } } protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) @@ -49,6 +75,35 @@ namespace Bit.Android.Controls } } + private void SetReturnType(ExtendedEntry view) + { + if(view.ReturnType.HasValue) + { + switch(view.ReturnType.Value) + { + case ReturnType.Go: + Control.ImeOptions = ImeAction.Go; + Control.SetImeActionLabel("Go", ImeAction.Go); + break; + case ReturnType.Next: + Control.ImeOptions = ImeAction.Next; + Control.SetImeActionLabel("Next", ImeAction.Next); + break; + case ReturnType.Search: + Control.ImeOptions = ImeAction.Search; + Control.SetImeActionLabel("Search", ImeAction.Search); + break; + case ReturnType.Send: + Control.ImeOptions = ImeAction.Send; + Control.SetImeActionLabel("Send", ImeAction.Send); + break; + default: + Control.SetImeActionLabel("Done", ImeAction.Done); + break; + } + } + } + private void SetBorder(ExtendedEntry view) { if(!view.HasBorder) diff --git a/src/App/Controls/ExtendedEntry.cs b/src/App/Controls/ExtendedEntry.cs index 53d229cd2..a4679e206 100644 --- a/src/App/Controls/ExtendedEntry.cs +++ b/src/App/Controls/ExtendedEntry.cs @@ -42,8 +42,17 @@ namespace Bit.App.Controls set { SetValue(MaxLengthProperty, value); } } + public ReturnType? ReturnType { get; set; } public bool? Autocorrect { get; set; } public bool DisableAutocapitalize { get; set; } + + // Need to overwrite default handler because we cant Invoke otherwise + public new event EventHandler Completed; + + public void InvokeCompleted() + { + Completed.Invoke(this, null); + } } } diff --git a/src/App/Enums/ReturnType.cs b/src/App/Enums/ReturnType.cs index fef8f25ff..2ba8343d1 100644 --- a/src/App/Enums/ReturnType.cs +++ b/src/App/Enums/ReturnType.cs @@ -2,10 +2,10 @@ { public enum ReturnType { - Return, Done, Go, Next, - Search + Search, + Send } } diff --git a/src/iOS/Controls/ExtendedEntryRenderer.cs b/src/iOS/Controls/ExtendedEntryRenderer.cs index 8d50ab60c..241479dd5 100644 --- a/src/iOS/Controls/ExtendedEntryRenderer.cs +++ b/src/iOS/Controls/ExtendedEntryRenderer.cs @@ -38,9 +38,6 @@ namespace Bit.iOS.Controls { switch(view.ReturnType.Value) { - case App.Enums.ReturnType.Return: - Control.ReturnKeyType = UIReturnKeyType.Default; - break; case App.Enums.ReturnType.Done: Control.ReturnKeyType = UIReturnKeyType.Done; break; @@ -53,10 +50,20 @@ namespace Bit.iOS.Controls case App.Enums.ReturnType.Search: Control.ReturnKeyType = UIReturnKeyType.Search; break; + case App.Enums.ReturnType.Send: + Control.ReturnKeyType = UIReturnKeyType.Send; + break; default: + Control.ReturnKeyType = UIReturnKeyType.Default; break; } } + + Control.ShouldReturn += (UITextField tf) => + { + view.InvokeCompleted(); + return true; + }; } }