Add Editor.IsTextPredictionEnabled property (#4023)
* Add Editor.IsTextPredictionEnabled property
* simplfy UpdateInputType logic
* modify IsTextPredictionEnabledProperty BindingMode to Default
* undo changes of commit 5db2456d
* [UITests] update namespace for UI Tests
- Fixes #3555
This commit is contained in:
Родитель
276fad975e
Коммит
dbfa47c978
|
@ -0,0 +1,46 @@
|
|||
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.Issues
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 3555, "[Enhancement] Editor: Control over text-prediction", PlatformAffected.All)]
|
||||
public class Issue3555
|
||||
: TestContentPage
|
||||
{
|
||||
protected override void Init()
|
||||
{
|
||||
var editorDefaults = new Editor();
|
||||
var editorFull = new Editor();
|
||||
editorFull.Keyboard = Keyboard.Create(KeyboardFlags.All);
|
||||
var editorNoTextPrediction = new Editor { IsTextPredictionEnabled = false };
|
||||
// IsTextPredictionEnabled should be ignored for email in Editor
|
||||
var editorEmail = new Editor { Text = "moses@example.com", Keyboard = Keyboard.Email, IsTextPredictionEnabled = true };
|
||||
// IsTextPredictionEnabled should be ignored for numeric Editor
|
||||
var editorNumeric = new Editor { Text = "01234", Keyboard = Keyboard.Numeric, IsTextPredictionEnabled = true };
|
||||
// On Android disabling either spell checking or text prediction both turn off text suggestions so this Editor
|
||||
// should behave the same as editorNoTextPrediction above
|
||||
var editorNoSpellChecking = new Editor { IsSpellCheckEnabled = false };
|
||||
var stackLayout = new StackLayout();
|
||||
stackLayout.Children.Add(new Label { Text = "Defaults" });
|
||||
stackLayout.Children.Add(editorDefaults);
|
||||
stackLayout.Children.Add(new Label { Text = "Text prediction disabled" });
|
||||
stackLayout.Children.Add(editorNoTextPrediction);
|
||||
stackLayout.Children.Add(new Label { Text = "Spell checking disabled" });
|
||||
stackLayout.Children.Add(editorNoSpellChecking);
|
||||
stackLayout.Children.Add(new Label { Text = "Email" });
|
||||
stackLayout.Children.Add(editorEmail);
|
||||
stackLayout.Children.Add(new Label { Text = "Numeric" });
|
||||
stackLayout.Children.Add(editorNumeric);
|
||||
stackLayout.Children.Add(new Label { Text = "Full" });
|
||||
stackLayout.Children.Add(editorFull);
|
||||
stackLayout.Padding = new Thickness(0, 20, 0, 0);
|
||||
Content = stackLayout;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Issue3509.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Github3856.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue1937.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue3555.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue3843.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue4053.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue3809.cs" />
|
||||
|
|
|
@ -23,6 +23,8 @@ namespace Xamarin.Forms
|
|||
|
||||
public static readonly BindableProperty PlaceholderColorProperty = PlaceholderElement.PlaceholderColorProperty;
|
||||
|
||||
public static readonly BindableProperty IsTextPredictionEnabledProperty = BindableProperty.Create(nameof(IsTextPredictionEnabled), typeof(bool), typeof(Editor), true, BindingMode.Default);
|
||||
|
||||
public static readonly BindableProperty AutoSizeProperty = BindableProperty.Create(nameof(AutoSize), typeof(EditorAutoSizeOption), typeof(Editor), defaultValue: EditorAutoSizeOption.Disabled, propertyChanged: (bindable, oldValue, newValue)
|
||||
=> ((Editor)bindable)?.InvalidateMeasure());
|
||||
|
||||
|
@ -62,6 +64,12 @@ namespace Xamarin.Forms
|
|||
set { SetValue(FontAttributesProperty, value); }
|
||||
}
|
||||
|
||||
public bool IsTextPredictionEnabled
|
||||
{
|
||||
get { return (bool)GetValue(IsTextPredictionEnabledProperty); }
|
||||
set { SetValue(IsTextPredictionEnabledProperty, value); }
|
||||
}
|
||||
|
||||
public string FontFamily
|
||||
{
|
||||
get { return (string)GetValue(FontFamilyProperty); }
|
||||
|
|
|
@ -100,6 +100,8 @@ namespace Xamarin.Forms.Platform.Android
|
|||
UpdateInputType();
|
||||
else if (e.PropertyName == InputView.IsSpellCheckEnabledProperty.PropertyName)
|
||||
UpdateInputType();
|
||||
else if (e.PropertyName == Editor.IsTextPredictionEnabledProperty.PropertyName)
|
||||
UpdateInputType();
|
||||
else if (e.PropertyName == Editor.TextColorProperty.PropertyName)
|
||||
UpdateTextColor();
|
||||
else if (e.PropertyName == Editor.FontAttributesProperty.PropertyName)
|
||||
|
@ -165,12 +167,17 @@ 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 (!(keyboard is Internals.CustomKeyboard))
|
||||
{
|
||||
if ((edit.InputType & InputTypes.TextFlagNoSuggestions) != InputTypes.TextFlagNoSuggestions)
|
||||
if (model.IsSet(InputView.IsSpellCheckEnabledProperty))
|
||||
{
|
||||
if (!model.IsSpellCheckEnabled)
|
||||
edit.InputType = edit.InputType | InputTypes.TextFlagNoSuggestions;
|
||||
edit.InputType = edit.InputType | InputTypes.TextFlagNoSuggestions;
|
||||
}
|
||||
if (model.IsSet(Editor.IsTextPredictionEnabledProperty))
|
||||
{
|
||||
if (!model.IsTextPredictionEnabled)
|
||||
edit.InputType = edit.InputType | InputTypes.TextFlagNoSuggestions;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,6 +94,10 @@ namespace Xamarin.Forms.Platform.UWP
|
|||
{
|
||||
UpdateInputScope();
|
||||
}
|
||||
else if (e.PropertyName == Editor.IsTextPredictionEnabledProperty.PropertyName)
|
||||
{
|
||||
UpdateInputScope();
|
||||
}
|
||||
else if (e.PropertyName == Editor.FontAttributesProperty.PropertyName)
|
||||
{
|
||||
UpdateFont();
|
||||
|
@ -282,7 +286,10 @@ namespace Xamarin.Forms.Platform.UWP
|
|||
}
|
||||
else
|
||||
{
|
||||
Control.ClearValue(TextBox.IsTextPredictionEnabledProperty);
|
||||
if (editor.IsSet(Editor.IsTextPredictionEnabledProperty))
|
||||
Control.IsTextPredictionEnabled = editor.IsTextPredictionEnabled;
|
||||
else
|
||||
Control.ClearValue(TextBox.IsTextPredictionEnabledProperty);
|
||||
if (editor.IsSet(InputView.IsSpellCheckEnabledProperty))
|
||||
Control.IsSpellCheckEnabled = editor.IsSpellCheckEnabled;
|
||||
else
|
||||
|
|
|
@ -132,6 +132,8 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
UpdateKeyboard();
|
||||
else if (e.PropertyName == Xamarin.Forms.InputView.IsSpellCheckEnabledProperty.PropertyName)
|
||||
UpdateKeyboard();
|
||||
else if (e.PropertyName == Editor.IsTextPredictionEnabledProperty.PropertyName)
|
||||
UpdateKeyboard();
|
||||
else if (e.PropertyName == VisualElement.IsEnabledProperty.PropertyName)
|
||||
UpdateEditable();
|
||||
else if (e.PropertyName == Editor.TextColorProperty.PropertyName)
|
||||
|
@ -202,12 +204,23 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
|
||||
void UpdateKeyboard()
|
||||
{
|
||||
Control.ApplyKeyboard(Element.Keyboard);
|
||||
if (!(Element.Keyboard is Internals.CustomKeyboard) && Element.IsSet(Xamarin.Forms.InputView.IsSpellCheckEnabledProperty))
|
||||
var keyboard = Element.Keyboard;
|
||||
Control.ApplyKeyboard(keyboard);
|
||||
if (!(keyboard is Internals.CustomKeyboard))
|
||||
{
|
||||
if (!Element.IsSpellCheckEnabled)
|
||||
if (Element.IsSet(Xamarin.Forms.InputView.IsSpellCheckEnabledProperty))
|
||||
{
|
||||
Control.SpellCheckingType = UITextSpellCheckingType.No;
|
||||
if (!Element.IsSpellCheckEnabled)
|
||||
{
|
||||
Control.SpellCheckingType = UITextSpellCheckingType.No;
|
||||
}
|
||||
}
|
||||
if (Element.IsSet(Editor.IsTextPredictionEnabledProperty))
|
||||
{
|
||||
if (!Element.IsTextPredictionEnabled)
|
||||
{
|
||||
Control.AutocorrectionType = UITextAutocorrectionType.No;
|
||||
}
|
||||
}
|
||||
}
|
||||
Control.ReloadInputViews();
|
||||
|
|
Загрузка…
Ссылка в новой задаче