Browse Source

Implement Next action in android IME (#13222)

* implement Next action in android IME

* Handle UIReturnKeyType.Next on iOS

* Remove NavigationMethod.Directional (do we need focus adorner?)

---------

Co-authored-by: Max Katz <maxkatz6@outlook.com>
Co-authored-by: Julien Lebosquain <julien@lebosquain.net>
pull/13523/head
Emmanuel Hansen 3 years ago
committed by GitHub
parent
commit
a6e936d74a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      samples/MobileSandbox/MainView.xaml
  2. 6
      src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs
  3. 11
      src/Avalonia.Base/Input/FocusManager.cs
  4. 4
      src/iOS/Avalonia.iOS/TextInputResponder.cs

2
samples/MobileSandbox/MainView.xaml

@ -8,7 +8,7 @@
<TextBox TextInputOptions.Multiline="True" AcceptsReturn="True" Watermark="Text" Height="200" TextWrapping="Wrap"/>
<TextBox Watermark="Username" TextInputOptions.ContentType="Email" TextInputOptions.ReturnKeyType="Done" />
<TextBox Watermark="Password" PasswordChar="*" TextInputOptions.ContentType="Password" />
<TextBox Watermark="Pin" PasswordChar="*" TextInputOptions.ContentType="Digits" />
<TextBox Watermark="Pin" PasswordChar="*" TextInputOptions.ContentType="Digits" TextInputOptions.ReturnKeyType="Next" />
<Button Content="Login" Command="{Binding ButtonCommand}" />
</StackPanel>
</UserControl>

6
src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs

@ -624,6 +624,12 @@ namespace Avalonia.Android.Platform.SkiaPlatform
_inputMethod.IMM.HideSoftInputFromWindow(_inputMethod.View.WindowToken, HideSoftInputFlags.ImplicitOnly);
break;
}
case ImeAction.Next:
{
FocusManager.GetFocusManager(_toplevel.InputRoot)?
.TryMoveFocus(NavigationDirection.Next);
break;
}
}
return base.PerformEditorAction(actionCode);

11
src/Avalonia.Base/Input/FocusManager.cs

@ -200,6 +200,17 @@ namespace Avalonia.Input
// In our unit tests some elements might not have a root. Remove when we migrate to headless tests.
?? (FocusManager?)AvaloniaLocator.Current.GetService<IFocusManager>();
}
internal bool TryMoveFocus(NavigationDirection direction)
{
if (GetFocusedElement() is {} focusedElement
&& KeyboardNavigationHandler.GetNext(focusedElement, direction) is {} newElement)
{
return newElement.Focus();
}
return false;
}
/// <summary>
/// Checks if the specified element can be focused.

4
src/iOS/Avalonia.iOS/TextInputResponder.cs

@ -182,6 +182,10 @@ partial class AvaloniaView
switch (ReturnKeyType)
{
case UIReturnKeyType.Next:
FocusManager.GetFocusManager(_view._topLevel)?
.TryMoveFocus(NavigationDirection.Next);
break;
case UIReturnKeyType.Done:
case UIReturnKeyType.Go:
case UIReturnKeyType.Send:

Loading…
Cancel
Save