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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
22 additions and
1 deletions
samples/MobileSandbox/MainView.xaml
src/Android/Avalonia.Android/Platform/SkiaPlatform/TopLevelImpl.cs
src/Avalonia.Base/Input/FocusManager.cs
src/iOS/Avalonia.iOS/TextInputResponder.cs
@ -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>
@ -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 ) ;
@ -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.
@ -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 :