Browse Source

feat: add hidesuggestions property to textbox (#17815)

* feat: add hidesuggestions property to textbox

* fix: set HideSuggestions in FromStyledElement

* refactor: api review recommendations

* refactor: pr suggestions
pull/18029/head
Joseph Sawyer 1 year ago
committed by GitHub
parent
commit
b45872e728
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      samples/ControlCatalog/Pages/TextBoxPage.xaml
  2. 3
      src/Android/Avalonia.Android/Platform/Input/AndroidInputMethod.cs
  3. 36
      src/Avalonia.Base/Input/TextInput/TextInputOptions.cs
  4. 11
      src/iOS/Avalonia.iOS/TextInputResponder.Properties.cs

1
samples/ControlCatalog/Pages/TextBoxPage.xaml

@ -38,6 +38,7 @@
UseFloatingWatermark="True"
PasswordChar="*"
Text="Password" />
<TextBox Width="200" Watermark="Suggestions are hidden" TextInputOptions.ShowSuggestions="False" />
<TextBox Width="200" Text="Left aligned text" TextAlignment="Left" AcceptsTab="True" />
<TextBox Width="200" Text="Center aligned text" TextAlignment="Center" />
<TextBox Width="200" Text="Right aligned text" TextAlignment="Right" />

3
src/Android/Avalonia.Android/Platform/Input/AndroidInputMethod.cs

@ -172,6 +172,9 @@ namespace Avalonia.Android.Platform.Input
if (options.Multiline)
outAttrs.InputType |= InputTypes.TextFlagMultiLine;
if (outAttrs.InputType is InputTypes.ClassText && options.ShowSuggestions == false)
outAttrs.InputType |= InputTypes.TextVariationPassword | InputTypes.TextFlagNoSuggestions;
outAttrs.ImeOptions = options.ReturnKeyType switch
{
TextInputReturnKeyType.Return => ImeFlags.NoEnterAction,

36
src/Avalonia.Base/Input/TextInput/TextInputOptions.cs

@ -12,7 +12,8 @@ public class TextInputOptions
AutoCapitalization = GetAutoCapitalization(avaloniaObject),
IsSensitive = GetIsSensitive(avaloniaObject),
Lowercase = GetLowercase(avaloniaObject),
Uppercase = GetUppercase(avaloniaObject)
Uppercase = GetUppercase(avaloniaObject),
ShowSuggestions = GetShowSuggestions(avaloniaObject),
};
return result;
@ -253,4 +254,37 @@ public class TextInputOptions
/// Text contains sensitive data like card numbers and should not be stored
/// </summary>
public bool IsSensitive { get; set; }
/// <summary>
/// Defines the <see cref="ShowSuggestions"/> property.
/// </summary>
public static readonly AttachedProperty<bool?> ShowSuggestionsProperty =
AvaloniaProperty.RegisterAttached<TextInputOptions, StyledElement, bool?>(
"ShowSuggestions",
inherits: true);
/// <summary>
/// Sets the value of the attached <see cref="ShowSuggestionsProperty"/> on a control.
/// </summary>
/// <param name="avaloniaObject">The control.</param>
/// <param name="value">The property value to set.</param>
public static void SetShowSuggestions(StyledElement avaloniaObject, bool? value)
{
avaloniaObject.SetValue(ShowSuggestionsProperty, value);
}
/// <summary>
/// Gets the value of the attached <see cref="ShowSuggestionsProperty"/>.
/// </summary>
/// <param name="avaloniaObject">The target.</param>
/// <returns>true if ShowSuggestions</returns>
public static bool? GetShowSuggestions(StyledElement avaloniaObject)
{
return avaloniaObject.GetValue(ShowSuggestionsProperty);
}
/// <summary>
/// Show virtual keyboard suggestions
/// </summary>
public bool? ShowSuggestions { get; set; }
}

11
src/iOS/Avalonia.iOS/TextInputResponder.Properties.cs

@ -12,7 +12,10 @@ partial class AvaloniaView
public UITextAutocapitalizationType AutocapitalizationType { get; private set; }
[Export("autocorrectionType")]
public UITextAutocorrectionType AutocorrectionType => UITextAutocorrectionType.Yes;
public UITextAutocorrectionType AutocorrectionType =>
_view._options?.ShowSuggestions == false ?
UITextAutocorrectionType.No :
UITextAutocorrectionType.Yes;
[Export("keyboardType")]
public UIKeyboardType KeyboardType =>
@ -64,7 +67,11 @@ partial class AvaloniaView
_view._options?.ContentType is TextInputContentType.Password or TextInputContentType.Pin
|| (_view._options?.IsSensitive ?? false);
[Export("spellCheckingType")] public UITextSpellCheckingType SpellCheckingType => UITextSpellCheckingType.Yes;
[Export("spellCheckingType")]
public UITextSpellCheckingType SpellCheckingType =>
_view._options?.ShowSuggestions == false ?
UITextSpellCheckingType.No :
UITextSpellCheckingType.Yes;
[Export("textContentType")] public NSString TextContentType { get; set; } = new NSString("text/plain");

Loading…
Cancel
Save