diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1660.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1660.cs new file mode 100644 index 000000000..978969d02 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue1660.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +namespace Xamarin.Forms.Controls +{ + [Preserve (AllMembers=true)] + [Issue (IssueTracker.Github, 1660, "[Enhancement] IsSpellCheckEnabled on Entry/Editor", PlatformAffected.All)] + public class Issue1660 + : TestContentPage + { + protected override void Init() + { + var text = "The quck bron fx jumps ovr the lazyy doog"; + + var entryDefaults = new Entry { Text = text }; + var editorDefaults = new Editor { Text = text }; + var entryNoSpellCheck = new Entry { Text = text, IsSpellCheckEnabled = false }; + var editorNoSpellCheck = new Editor { Text = text, IsSpellCheckEnabled = false }; + var entryToggleable = new Entry { Text = text }; + var editorToggleable = new Editor { Text = text }; + var toggle = new Switch { IsToggled = true }; + + var stackLayout = new StackLayout(); + stackLayout.Children.Add(new Label { Text = "Defaults" }); + stackLayout.Children.Add(entryDefaults); + stackLayout.Children.Add(editorDefaults); + stackLayout.Children.Add(new Label { Text = "Spell checking disabled" }); + stackLayout.Children.Add(entryNoSpellCheck); + stackLayout.Children.Add(editorNoSpellCheck); + stackLayout.Children.Add(new Label { Text = "Toggleable spell checking" }); + stackLayout.Children.Add(entryToggleable); + stackLayout.Children.Add(editorToggleable); + stackLayout.Children.Add(toggle); + + toggle.Toggled += (_, b) => + { + entryToggleable.IsSpellCheckEnabled = b.Value; + editorToggleable.IsSpellCheckEnabled = b.Value; + }; + + stackLayout.Padding = new Thickness(0, 20, 0, 0); + Content = stackLayout; + } + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index c5a4dc7f3..3bb2f8af5 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -279,6 +279,7 @@ + diff --git a/Xamarin.Forms.Core/InputView.cs b/Xamarin.Forms.Core/InputView.cs index 58b75c424..9ceb70ce2 100644 --- a/Xamarin.Forms.Core/InputView.cs +++ b/Xamarin.Forms.Core/InputView.cs @@ -4,6 +4,7 @@ namespace Xamarin.Forms { public static readonly BindableProperty KeyboardProperty = BindableProperty.Create("Keyboard", typeof(Keyboard), typeof(InputView), Keyboard.Default, coerceValue: (o, v) => (Keyboard)v ?? Keyboard.Default); + public static readonly BindableProperty IsSpellCheckEnabledProperty = BindableProperty.Create("IsSpellCheckEnabled", typeof(bool), typeof(InputView), true); internal InputView() { @@ -14,5 +15,11 @@ namespace Xamarin.Forms get { return (Keyboard)GetValue(KeyboardProperty); } set { SetValue(KeyboardProperty, value); } } + + public bool IsSpellCheckEnabled + { + get { return (bool)GetValue(IsSpellCheckEnabledProperty); } + set { SetValue(IsSpellCheckEnabledProperty, value); } + } } } \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs index 5b7973c12..ccfb09ae2 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/EditorRenderer.cs @@ -90,6 +90,8 @@ namespace Xamarin.Forms.Platform.Android UpdateText(); else if (e.PropertyName == InputView.KeyboardProperty.PropertyName) UpdateInputType(); + else if (e.PropertyName == InputView.IsSpellCheckEnabledProperty.PropertyName) + UpdateInputType(); else if (e.PropertyName == Editor.TextColorProperty.PropertyName) UpdateTextColor(); else if (e.PropertyName == Editor.FontAttributesProperty.PropertyName) @@ -149,6 +151,14 @@ namespace Xamarin.Forms.Platform.Android var keyboard = model.Keyboard; edit.InputType = keyboard.ToInputType() | InputTypes.TextFlagMultiLine; + if (!(keyboard is Internals.CustomKeyboard) && model.IsSet(InputView.IsSpellCheckEnabledProperty)) + { + if ((edit.InputType & InputTypes.TextFlagNoSuggestions) != InputTypes.TextFlagNoSuggestions) + { + if (!model.IsSpellCheckEnabled) + edit.InputType = edit.InputType | InputTypes.TextFlagNoSuggestions; + } + } if (keyboard == Keyboard.Numeric) { diff --git a/Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs index fbc814a3c..76ba233e5 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/EntryRenderer.cs @@ -141,6 +141,8 @@ namespace Xamarin.Forms.Platform.Android UpdateColor(); else if (e.PropertyName == InputView.KeyboardProperty.PropertyName) UpdateInputType(); + else if (e.PropertyName == InputView.IsSpellCheckEnabledProperty.PropertyName) + UpdateInputType(); else if (e.PropertyName == Entry.HorizontalTextAlignmentProperty.PropertyName) UpdateAlignment(); else if (e.PropertyName == Entry.FontAttributesProperty.PropertyName) @@ -198,6 +200,14 @@ namespace Xamarin.Forms.Platform.Android var keyboard = model.Keyboard; Control.InputType = keyboard.ToInputType(); + if (!(keyboard is Internals.CustomKeyboard) && model.IsSet(InputView.IsSpellCheckEnabledProperty)) + { + if ((Control.InputType & InputTypes.TextFlagNoSuggestions) != InputTypes.TextFlagNoSuggestions) + { + if (!model.IsSpellCheckEnabled) + Control.InputType = Control.InputType | InputTypes.TextFlagNoSuggestions; + } + } if (keyboard == Keyboard.Numeric) { diff --git a/Xamarin.Forms.Platform.UAP/EditorRenderer.cs b/Xamarin.Forms.Platform.UAP/EditorRenderer.cs index 489a18084..9aae0e561 100644 --- a/Xamarin.Forms.Platform.UAP/EditorRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/EditorRenderer.cs @@ -72,6 +72,14 @@ namespace Xamarin.Forms.Platform.UWP { UpdateTextColor(); } + else if (e.PropertyName == InputView.KeyboardProperty.PropertyName) + { + UpdateInputScope(); + } + else if (e.PropertyName == InputView.IsSpellCheckEnabledProperty.PropertyName) + { + UpdateInputScope(); + } else if (e.PropertyName == Editor.FontAttributesProperty.PropertyName) { UpdateFont(); @@ -157,7 +165,8 @@ namespace Xamarin.Forms.Platform.UWP void UpdateInputScope() { - var custom = Element.Keyboard as CustomKeyboard; + Editor editor = Element; + var custom = editor.Keyboard as CustomKeyboard; if (custom != null) { Control.IsTextPredictionEnabled = (custom.Flags & KeyboardFlags.Suggestions) != 0; @@ -166,10 +175,13 @@ namespace Xamarin.Forms.Platform.UWP else { Control.ClearValue(TextBox.IsTextPredictionEnabledProperty); - Control.ClearValue(TextBox.IsSpellCheckEnabledProperty); + if (editor.IsSet(InputView.IsSpellCheckEnabledProperty)) + Control.IsSpellCheckEnabled = editor.IsSpellCheckEnabled; + else + Control.ClearValue(TextBox.IsSpellCheckEnabledProperty); } - Control.InputScope = Element.Keyboard.ToInputScope(); + Control.InputScope = editor.Keyboard.ToInputScope(); } void UpdateText() diff --git a/Xamarin.Forms.Platform.UAP/EntryRenderer.cs b/Xamarin.Forms.Platform.UAP/EntryRenderer.cs index 2a116c380..633820527 100644 --- a/Xamarin.Forms.Platform.UAP/EntryRenderer.cs +++ b/Xamarin.Forms.Platform.UAP/EntryRenderer.cs @@ -1,6 +1,7 @@ using System.ComponentModel; using Windows.System; using Windows.UI.Xaml; +using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Xamarin.Forms.Internals; @@ -75,6 +76,8 @@ namespace Xamarin.Forms.Platform.UWP UpdateTextColor(); else if (e.PropertyName == InputView.KeyboardProperty.PropertyName) UpdateInputScope(); + else if (e.PropertyName == InputView.IsSpellCheckEnabledProperty.PropertyName) + UpdateInputScope(); else if (e.PropertyName == Entry.FontAttributesProperty.PropertyName) UpdateFont(); else if (e.PropertyName == Entry.FontFamilyProperty.PropertyName) @@ -163,14 +166,23 @@ namespace Xamarin.Forms.Platform.UWP void UpdateInputScope() { - var custom = Element.Keyboard as CustomKeyboard; + Entry entry = Element; + var custom = entry.Keyboard as CustomKeyboard; if (custom != null) { Control.IsTextPredictionEnabled = (custom.Flags & KeyboardFlags.Suggestions) != 0; Control.IsSpellCheckEnabled = (custom.Flags & KeyboardFlags.Spellcheck) != 0; } + else + { + Control.ClearValue(TextBox.IsTextPredictionEnabledProperty); + if (entry.IsSet(InputView.IsSpellCheckEnabledProperty)) + Control.IsSpellCheckEnabled = entry.IsSpellCheckEnabled; + else + Control.ClearValue(TextBox.IsSpellCheckEnabledProperty); + } - Control.InputScope = Element.Keyboard.ToInputScope(); + Control.InputScope = entry.Keyboard.ToInputScope(); } void UpdateIsPassword() diff --git a/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml b/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml index dc7c4e1d3..bdf5cc0c1 100644 --- a/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml +++ b/Xamarin.Forms.Platform.UAP/FormsTextBoxStyle.xaml @@ -18,6 +18,7 @@ + diff --git a/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs index 5fdceaeec..06aa23b55 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/EditorRenderer.cs @@ -78,6 +78,8 @@ namespace Xamarin.Forms.Platform.iOS UpdateText(); else if (e.PropertyName == Xamarin.Forms.InputView.KeyboardProperty.PropertyName) UpdateKeyboard(); + else if (e.PropertyName == Xamarin.Forms.InputView.IsSpellCheckEnabledProperty.PropertyName) + UpdateKeyboard(); else if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName) UpdateEditable(); else if (e.PropertyName == Editor.TextColorProperty.PropertyName) @@ -128,6 +130,13 @@ namespace Xamarin.Forms.Platform.iOS void UpdateKeyboard() { Control.ApplyKeyboard(Element.Keyboard); + if (!(Element.Keyboard is Internals.CustomKeyboard) && Element.IsSet(Xamarin.Forms.InputView.IsSpellCheckEnabledProperty)) + { + if (!Element.IsSpellCheckEnabled) + { + Control.SpellCheckingType = UITextSpellCheckingType.No; + } + } Control.ReloadInputViews(); } diff --git a/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs index c590adb3f..02069d239 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/EntryRenderer.cs @@ -118,6 +118,8 @@ namespace Xamarin.Forms.Platform.iOS UpdateColor(); else if (e.PropertyName == Xamarin.Forms.InputView.KeyboardProperty.PropertyName) UpdateKeyboard(); + else if (e.PropertyName == Xamarin.Forms.InputView.IsSpellCheckEnabledProperty.PropertyName) + UpdateKeyboard(); else if (e.PropertyName == Entry.HorizontalTextAlignmentProperty.PropertyName) UpdateAlignment(); else if (e.PropertyName == Entry.FontAttributesProperty.PropertyName) @@ -205,6 +207,13 @@ namespace Xamarin.Forms.Platform.iOS void UpdateKeyboard() { Control.ApplyKeyboard(Element.Keyboard); + if (!(Element.Keyboard is Internals.CustomKeyboard) && Element.IsSet(Xamarin.Forms.InputView.IsSpellCheckEnabledProperty)) + { + if (!Element.IsSpellCheckEnabled) + { + Control.SpellCheckingType = UITextSpellCheckingType.No; + } + } Control.ReloadInputViews(); } diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms/InputView.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms/InputView.xml index 7e81cb2d0..2a5f3f982 100644 --- a/docs/Xamarin.Forms.Core/Xamarin.Forms/InputView.xml +++ b/docs/Xamarin.Forms.Core/Xamarin.Forms/InputView.xml @@ -20,6 +20,37 @@ The constructor of this class is internal. Forms does not provide any renderer for InputView base class. + + + + Property + + 2.0.0.0 + + + System.Boolean + + + To be added. + To be added. + To be added. + + + + + + Field + + 2.0.0.0 + + + Xamarin.Forms.BindableProperty + + + To be added. + To be added. + +