Browse Source

implement return key and accepts return, and closing keyboard on done return keys.

pull/8963/head
Dan Walmsley 3 years ago
parent
commit
c82687426c
  1. 4
      samples/MobileSandbox/MainView.xaml
  2. 9
      samples/MobileSandbox/MainView.xaml.cs
  3. 17
      src/iOS/Avalonia.iOS/TextInputResponder.Properties.cs
  4. 10
      src/iOS/Avalonia.iOS/TextInputResponder.cs

4
samples/MobileSandbox/MainView.xaml

@ -3,9 +3,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Margin="100 50" Spacing="50"> <StackPanel Margin="100 50" Spacing="50">
<TextBlock Text="Login" Foreground="White" /> <TextBlock Text="Login" Foreground="White" />
<TextBox Watermark="Username" TextInputOptions.ContentType="Email" /> <TextBox Watermark="Username" TextInputOptions.ContentType="Email" AcceptsReturn="True" TextInputOptions.ReturnKeyType="Search" />
<TextBox Watermark="Password" PasswordChar="*" TextInputOptions.ContentType="Password" /> <TextBox Watermark="Password" PasswordChar="*" TextInputOptions.ContentType="Password" />
<TextBox Watermark="Pin" PasswordChar="*" TextInputOptions.ContentType="Digits" /> <TextBox Watermark="Pin" PasswordChar="*" TextInputOptions.ContentType="Digits" />
<Button Content="Login" /> <Button Content="Login" Command="{Binding ButtonCommand}" />
</StackPanel> </StackPanel>
</UserControl> </UserControl>

9
samples/MobileSandbox/MainView.xaml.cs

@ -1,3 +1,5 @@
using System;
using System.Windows.Input;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
@ -8,6 +10,13 @@ namespace MobileSandbox
public MainView() public MainView()
{ {
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
DataContext = this;
}
public void ButtonCommand()
{
Console.WriteLine("Button pressed");
} }
} }
} }

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

@ -35,7 +35,22 @@ partial class AvaloniaView
[Export("keyboardAppearance")] [Export("keyboardAppearance")]
public UIKeyboardAppearance KeyboardAppearance => UIKeyboardAppearance.Alert; public UIKeyboardAppearance KeyboardAppearance => UIKeyboardAppearance.Alert;
[Export("returnKeyType")] public UIReturnKeyType ReturnKeyType => (UIReturnKeyType)(_view._options?.ReturnKeyType ?? TextInputReturnKeyType.Default); [Export("returnKeyType")]
public UIReturnKeyType ReturnKeyType
{
get
{
if (_view._options != null)
{
if (_view._options.ReturnKeyType == TextInputReturnKeyType.Default)
{
return _view._options.Multiline ? UIReturnKeyType.Default : UIReturnKeyType.Done;
}
}
return UIReturnKeyType.Default;
}
}
[Export("enablesReturnKeyAutomatically")] [Export("enablesReturnKeyAutomatically")]
public bool EnablesReturnKeyAutomatically { get; set; } public bool EnablesReturnKeyAutomatically { get; set; }

10
src/iOS/Avalonia.iOS/TextInputResponder.cs

@ -149,6 +149,16 @@ partial class AvaloniaView
if (text == "\n") if (text == "\n")
{ {
KeyPress(Key.Enter); KeyPress(Key.Enter);
switch (ReturnKeyType)
{
case UIReturnKeyType.Done:
case UIReturnKeyType.Go:
case UIReturnKeyType.Send:
case UIReturnKeyType.Search:
ResignFirstResponder();
break;
}
return; return;
} }

Loading…
Cancel
Save