зеркало из https://github.com/DeGsoft/maui-linux.git
[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:
Родитель
c4701be513
Коммит
0b2bbb03d4
|
@ -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)Issue1347.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue1356.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Issue1356.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue1439.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Issue1439.cs" />
|
||||||
|
<Compile Include="$(MSBuildThisFileDirectory)Issue1660.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue1691.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Issue1691.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue2983.cs" />
|
<Compile Include="$(MSBuildThisFileDirectory)Issue2983.cs" />
|
||||||
<Compile Include="$(MSBuildThisFileDirectory)Issue2963.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,
|
public static readonly BindableProperty KeyboardProperty = BindableProperty.Create("Keyboard", typeof(Keyboard), typeof(InputView), Keyboard.Default,
|
||||||
coerceValue: (o, v) => (Keyboard)v ?? Keyboard.Default);
|
coerceValue: (o, v) => (Keyboard)v ?? Keyboard.Default);
|
||||||
|
public static readonly BindableProperty IsSpellCheckEnabledProperty = BindableProperty.Create("IsSpellCheckEnabled", typeof(bool), typeof(InputView), true);
|
||||||
|
|
||||||
internal InputView()
|
internal InputView()
|
||||||
{
|
{
|
||||||
|
@ -14,5 +15,11 @@ namespace Xamarin.Forms
|
||||||
get { return (Keyboard)GetValue(KeyboardProperty); }
|
get { return (Keyboard)GetValue(KeyboardProperty); }
|
||||||
set { SetValue(KeyboardProperty, value); }
|
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();
|
UpdateText();
|
||||||
else if (e.PropertyName == InputView.KeyboardProperty.PropertyName)
|
else if (e.PropertyName == InputView.KeyboardProperty.PropertyName)
|
||||||
UpdateInputType();
|
UpdateInputType();
|
||||||
|
else if (e.PropertyName == InputView.IsSpellCheckEnabledProperty.PropertyName)
|
||||||
|
UpdateInputType();
|
||||||
else if (e.PropertyName == Editor.TextColorProperty.PropertyName)
|
else if (e.PropertyName == Editor.TextColorProperty.PropertyName)
|
||||||
UpdateTextColor();
|
UpdateTextColor();
|
||||||
else if (e.PropertyName == Editor.FontAttributesProperty.PropertyName)
|
else if (e.PropertyName == Editor.FontAttributesProperty.PropertyName)
|
||||||
|
@ -149,6 +151,14 @@ namespace Xamarin.Forms.Platform.Android
|
||||||
var keyboard = model.Keyboard;
|
var keyboard = model.Keyboard;
|
||||||
|
|
||||||
edit.InputType = keyboard.ToInputType() | InputTypes.TextFlagMultiLine;
|
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)
|
if (keyboard == Keyboard.Numeric)
|
||||||
{
|
{
|
||||||
|
|
|
@ -141,6 +141,8 @@ namespace Xamarin.Forms.Platform.Android
|
||||||
UpdateColor();
|
UpdateColor();
|
||||||
else if (e.PropertyName == InputView.KeyboardProperty.PropertyName)
|
else if (e.PropertyName == InputView.KeyboardProperty.PropertyName)
|
||||||
UpdateInputType();
|
UpdateInputType();
|
||||||
|
else if (e.PropertyName == InputView.IsSpellCheckEnabledProperty.PropertyName)
|
||||||
|
UpdateInputType();
|
||||||
else if (e.PropertyName == Entry.HorizontalTextAlignmentProperty.PropertyName)
|
else if (e.PropertyName == Entry.HorizontalTextAlignmentProperty.PropertyName)
|
||||||
UpdateAlignment();
|
UpdateAlignment();
|
||||||
else if (e.PropertyName == Entry.FontAttributesProperty.PropertyName)
|
else if (e.PropertyName == Entry.FontAttributesProperty.PropertyName)
|
||||||
|
@ -198,6 +200,14 @@ namespace Xamarin.Forms.Platform.Android
|
||||||
var keyboard = model.Keyboard;
|
var keyboard = model.Keyboard;
|
||||||
|
|
||||||
Control.InputType = keyboard.ToInputType();
|
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)
|
if (keyboard == Keyboard.Numeric)
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,6 +72,14 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
{
|
{
|
||||||
UpdateTextColor();
|
UpdateTextColor();
|
||||||
}
|
}
|
||||||
|
else if (e.PropertyName == InputView.KeyboardProperty.PropertyName)
|
||||||
|
{
|
||||||
|
UpdateInputScope();
|
||||||
|
}
|
||||||
|
else if (e.PropertyName == InputView.IsSpellCheckEnabledProperty.PropertyName)
|
||||||
|
{
|
||||||
|
UpdateInputScope();
|
||||||
|
}
|
||||||
else if (e.PropertyName == Editor.FontAttributesProperty.PropertyName)
|
else if (e.PropertyName == Editor.FontAttributesProperty.PropertyName)
|
||||||
{
|
{
|
||||||
UpdateFont();
|
UpdateFont();
|
||||||
|
@ -157,7 +165,8 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
|
|
||||||
void UpdateInputScope()
|
void UpdateInputScope()
|
||||||
{
|
{
|
||||||
var custom = Element.Keyboard as CustomKeyboard;
|
Editor editor = Element;
|
||||||
|
var custom = editor.Keyboard as CustomKeyboard;
|
||||||
if (custom != null)
|
if (custom != null)
|
||||||
{
|
{
|
||||||
Control.IsTextPredictionEnabled = (custom.Flags & KeyboardFlags.Suggestions) != 0;
|
Control.IsTextPredictionEnabled = (custom.Flags & KeyboardFlags.Suggestions) != 0;
|
||||||
|
@ -166,10 +175,13 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Control.ClearValue(TextBox.IsTextPredictionEnabledProperty);
|
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()
|
void UpdateText()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using Windows.System;
|
using Windows.System;
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
|
using Windows.UI.Xaml.Controls;
|
||||||
using Windows.UI.Xaml.Input;
|
using Windows.UI.Xaml.Input;
|
||||||
using Windows.UI.Xaml.Media;
|
using Windows.UI.Xaml.Media;
|
||||||
using Xamarin.Forms.Internals;
|
using Xamarin.Forms.Internals;
|
||||||
|
@ -75,6 +76,8 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
UpdateTextColor();
|
UpdateTextColor();
|
||||||
else if (e.PropertyName == InputView.KeyboardProperty.PropertyName)
|
else if (e.PropertyName == InputView.KeyboardProperty.PropertyName)
|
||||||
UpdateInputScope();
|
UpdateInputScope();
|
||||||
|
else if (e.PropertyName == InputView.IsSpellCheckEnabledProperty.PropertyName)
|
||||||
|
UpdateInputScope();
|
||||||
else if (e.PropertyName == Entry.FontAttributesProperty.PropertyName)
|
else if (e.PropertyName == Entry.FontAttributesProperty.PropertyName)
|
||||||
UpdateFont();
|
UpdateFont();
|
||||||
else if (e.PropertyName == Entry.FontFamilyProperty.PropertyName)
|
else if (e.PropertyName == Entry.FontFamilyProperty.PropertyName)
|
||||||
|
@ -163,14 +166,23 @@ namespace Xamarin.Forms.Platform.UWP
|
||||||
|
|
||||||
void UpdateInputScope()
|
void UpdateInputScope()
|
||||||
{
|
{
|
||||||
var custom = Element.Keyboard as CustomKeyboard;
|
Entry entry = Element;
|
||||||
|
var custom = entry.Keyboard as CustomKeyboard;
|
||||||
if (custom != null)
|
if (custom != null)
|
||||||
{
|
{
|
||||||
Control.IsTextPredictionEnabled = (custom.Flags & KeyboardFlags.Suggestions) != 0;
|
Control.IsTextPredictionEnabled = (custom.Flags & KeyboardFlags.Suggestions) != 0;
|
||||||
Control.IsSpellCheckEnabled = (custom.Flags & KeyboardFlags.Spellcheck) != 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()
|
void UpdateIsPassword()
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
<Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" />
|
<Setter Property="BorderThickness" Value="{ThemeResource TextControlBorderThemeThickness}" />
|
||||||
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
|
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
|
||||||
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
|
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}" />
|
||||||
|
<Setter Property="IsSpellCheckEnabled" Value="True" />
|
||||||
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
|
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
|
||||||
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
|
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
|
||||||
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
|
<Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
|
||||||
|
|
|
@ -78,6 +78,8 @@ namespace Xamarin.Forms.Platform.iOS
|
||||||
UpdateText();
|
UpdateText();
|
||||||
else if (e.PropertyName == Xamarin.Forms.InputView.KeyboardProperty.PropertyName)
|
else if (e.PropertyName == Xamarin.Forms.InputView.KeyboardProperty.PropertyName)
|
||||||
UpdateKeyboard();
|
UpdateKeyboard();
|
||||||
|
else if (e.PropertyName == Xamarin.Forms.InputView.IsSpellCheckEnabledProperty.PropertyName)
|
||||||
|
UpdateKeyboard();
|
||||||
else if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName)
|
else if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName)
|
||||||
UpdateEditable();
|
UpdateEditable();
|
||||||
else if (e.PropertyName == Editor.TextColorProperty.PropertyName)
|
else if (e.PropertyName == Editor.TextColorProperty.PropertyName)
|
||||||
|
@ -128,6 +130,13 @@ namespace Xamarin.Forms.Platform.iOS
|
||||||
void UpdateKeyboard()
|
void UpdateKeyboard()
|
||||||
{
|
{
|
||||||
Control.ApplyKeyboard(Element.Keyboard);
|
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();
|
Control.ReloadInputViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,8 @@ namespace Xamarin.Forms.Platform.iOS
|
||||||
UpdateColor();
|
UpdateColor();
|
||||||
else if (e.PropertyName == Xamarin.Forms.InputView.KeyboardProperty.PropertyName)
|
else if (e.PropertyName == Xamarin.Forms.InputView.KeyboardProperty.PropertyName)
|
||||||
UpdateKeyboard();
|
UpdateKeyboard();
|
||||||
|
else if (e.PropertyName == Xamarin.Forms.InputView.IsSpellCheckEnabledProperty.PropertyName)
|
||||||
|
UpdateKeyboard();
|
||||||
else if (e.PropertyName == Entry.HorizontalTextAlignmentProperty.PropertyName)
|
else if (e.PropertyName == Entry.HorizontalTextAlignmentProperty.PropertyName)
|
||||||
UpdateAlignment();
|
UpdateAlignment();
|
||||||
else if (e.PropertyName == Entry.FontAttributesProperty.PropertyName)
|
else if (e.PropertyName == Entry.FontAttributesProperty.PropertyName)
|
||||||
|
@ -205,6 +207,13 @@ namespace Xamarin.Forms.Platform.iOS
|
||||||
void UpdateKeyboard()
|
void UpdateKeyboard()
|
||||||
{
|
{
|
||||||
Control.ApplyKeyboard(Element.Keyboard);
|
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();
|
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>
|
<remarks>The constructor of this class is internal. Forms does not provide any renderer for InputView base class.</remarks>
|
||||||
</Docs>
|
</Docs>
|
||||||
<Members>
|
<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">
|
<Member MemberName="Keyboard">
|
||||||
<MemberSignature Language="C#" Value="public Xamarin.Forms.Keyboard Keyboard { get; set; }" />
|
<MemberSignature Language="C#" Value="public Xamarin.Forms.Keyboard Keyboard { get; set; }" />
|
||||||
<MemberSignature Language="ILAsm" Value=".property instance class Xamarin.Forms.Keyboard Keyboard" />
|
<MemberSignature Language="ILAsm" Value=".property instance class Xamarin.Forms.Keyboard Keyboard" />
|
||||||
|
|
Загрузка…
Ссылка в новой задаче