[Enhancement] IsSpellCheckEnabled on Entry/Editor (#1836)

Adds the InputView.IsSpellCheckEnabled property which makes it easier to
disable the native spell checking features. Fixes #1660.
This commit is contained in:
Niklas Therning 2018-02-16 11:39:19 +01:00 коммит произвёл Rui Marinho
Родитель c4701be513
Коммит 0b2bbb03d4
11 изменённых файлов: 158 добавлений и 5 удалений

Просмотреть файл

@ -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;
}
}
}

Просмотреть файл

@ -279,6 +279,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue1347.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1356.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1439.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1660.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue1691.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue2983.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue2963.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); }
}
}
}

Просмотреть файл

@ -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)
{

Просмотреть файл

@ -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)
{

Просмотреть файл

@ -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()

Просмотреть файл

@ -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()

Просмотреть файл

@ -18,6 +18,7 @@
<Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" />
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
<Setter Property="IsSpellCheckEnabled" Value="True" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -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();
}

Просмотреть файл

@ -20,6 +20,37 @@
<remarks>The constructor of this class is internal. Forms does not provide any renderer for InputView base class.</remarks>
</Docs>
<Members>
<Member MemberName="IsSpellCheckEnabled">
<MemberSignature Language="C#" Value="public bool IsSpellCheckEnabled { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance bool IsSpellCheckEnabled" />
<MemberType>Property</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Docs>
<summary>To be added.</summary>
<value>To be added.</value>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="IsSpellCheckEnabledProperty">
<MemberSignature Language="C#" Value="public static readonly Xamarin.Forms.BindableProperty IsSpellCheckEnabledProperty;" />
<MemberSignature Language="ILAsm" Value=".field public static initonly class Xamarin.Forms.BindableProperty IsSpellCheckEnabledProperty" />
<MemberType>Field</MemberType>
<AssemblyInfo>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>Xamarin.Forms.BindableProperty</ReturnType>
</ReturnValue>
<Docs>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Keyboard">
<MemberSignature Language="C#" Value="public Xamarin.Forms.Keyboard Keyboard { get; set; }" />
<MemberSignature Language="ILAsm" Value=".property instance class Xamarin.Forms.Keyboard Keyboard" />