зеркало из https://github.com/DeGsoft/maui-linux.git
Auto-focus next view from Entry with ReturnType.Next (#6706)
* Automatically focus the next view after hitting the Return key on an Entry with ReturnType.Next * UWP implementation
This commit is contained in:
Родитель
51654555d8
Коммит
ed26340b0e
|
@ -3,11 +3,13 @@ using System.Threading.Tasks;
|
|||
|
||||
namespace Xamarin.Forms.Controls
|
||||
{
|
||||
public class EntryReturnTypeGalleryPage: ContentPage
|
||||
public class EntryReturnTypeGalleryPage : ContentPage
|
||||
{
|
||||
Picker picker;
|
||||
Entry returnTypeEntry;
|
||||
Label lblCompleted;
|
||||
Entry nextEntry;
|
||||
|
||||
public EntryReturnTypeGalleryPage()
|
||||
{
|
||||
BackgroundColor = Color.LightBlue;
|
||||
|
@ -35,7 +37,7 @@ namespace Xamarin.Forms.Controls
|
|||
{
|
||||
HorizontalOptions = LayoutOptions.Fill,
|
||||
Placeholder = $"Entry with {ReturnType.Go}",
|
||||
ReturnCommand = new Command<string>(obj =>
|
||||
ReturnCommand = new Command<string>(obj =>
|
||||
{
|
||||
lblCompleted.Text = "Completed Fired";
|
||||
}),
|
||||
|
@ -48,6 +50,7 @@ namespace Xamarin.Forms.Controls
|
|||
if (e.PropertyName == Entry.ReturnTypeProperty.PropertyName)
|
||||
{
|
||||
returnTypeEntry.Placeholder = $"Entry with {returnTypeEntry.ReturnType}";
|
||||
lblCompleted.Text = null;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -79,9 +82,17 @@ namespace Xamarin.Forms.Controls
|
|||
}
|
||||
};
|
||||
|
||||
layout.Children.Add(returnTypeEntry);
|
||||
nextEntry = new Entry
|
||||
{
|
||||
Placeholder = "Next Entry to Focus",
|
||||
ReturnType = ReturnType.Next,
|
||||
HorizontalOptions = LayoutOptions.FillAndExpand
|
||||
};
|
||||
|
||||
layout.Children.Add(picker);
|
||||
layout.Children.Add(returnTypeEntry);
|
||||
layout.Children.Add(lblCompleted);
|
||||
layout.Children.Add(nextEntry);
|
||||
picker.SelectedIndex = 0;
|
||||
|
||||
Content = layout;
|
||||
|
|
|
@ -91,8 +91,26 @@ namespace Xamarin.Forms.Platform.Android
|
|||
// Fire Completed and dismiss keyboard for hardware / physical keyboards
|
||||
if (actionId == ImeAction.Done || actionId == _currentInputImeFlag || (actionId == ImeAction.ImeNull && e.KeyCode == Keycode.Enter && e.Action == KeyEventActions.Up))
|
||||
{
|
||||
EditText.ClearFocus();
|
||||
v.HideKeyboard();
|
||||
global::Android.Views.View nextFocus = null;
|
||||
if (_currentInputImeFlag == ImeAction.Next)
|
||||
{
|
||||
nextFocus = FocusSearch(v, FocusSearchDirection.Forward);
|
||||
}
|
||||
|
||||
if (nextFocus != null)
|
||||
{
|
||||
nextFocus.RequestFocus();
|
||||
if (!nextFocus.OnCheckIsTextEditor())
|
||||
{
|
||||
v.HideKeyboard();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EditText.ClearFocus();
|
||||
v.HideKeyboard();
|
||||
}
|
||||
|
||||
((IEntryController)Element).SendCompleted();
|
||||
}
|
||||
|
||||
|
|
|
@ -165,9 +165,15 @@ namespace Xamarin.Forms.Platform.UWP
|
|||
if (args?.Key != VirtualKey.Enter)
|
||||
return;
|
||||
|
||||
|
||||
// Hide the soft keyboard; this matches the behavior of Forms on Android/iOS
|
||||
Windows.UI.ViewManagement.InputPane.GetForCurrentView().TryHide();
|
||||
if (Element.ReturnType == ReturnType.Next)
|
||||
{
|
||||
FocusManager.TryMoveFocus(FocusNavigationDirection.Next);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hide the soft keyboard; this matches the behavior of Forms on Android/iOS
|
||||
Windows.UI.ViewManagement.InputPane.GetForCurrentView().TryHide();
|
||||
}
|
||||
|
||||
((IEntryController)Element).SendCompleted();
|
||||
}
|
||||
|
|
|
@ -231,6 +231,12 @@ namespace Xamarin.Forms.Platform.iOS
|
|||
{
|
||||
Control.ResignFirstResponder();
|
||||
((IEntryController)Element).SendCompleted();
|
||||
|
||||
if (Element.ReturnType == ReturnType.Next)
|
||||
{
|
||||
FocusSearch(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче