From 9fb0475beca8e69d3ca1d96d72e9b8e611147aba Mon Sep 17 00:00:00 2001 From: Rachel Kang Date: Mon, 13 Mar 2023 12:10:48 -0400 Subject: [PATCH] Revert "Show keyboard on Android entry/editor/searchbar focus (#12890)" This reverts commit 20f54bcdcc6f8aa1d18bb176f543bf7e6b97ffae, reversing changes made to a775a2d121df7f726125e2b6b8b565eeb9711090. --- .../AppCompat/FormsAppCompatActivity.cs | 2 +- src/Controls/src/Core/VisualElement.cs | 9 +- .../DeviceTests/ControlsHandlerTestBase.cs | 19 ++-- .../TextInput/TextInputTests.Android.cs | 42 -------- .../Elements/TextInput/TextInputTests.cs | 24 ----- .../tests/DeviceTests/TestCategory.cs | 1 - .../Handlers/Editor/EditorHandler.Android.cs | 6 -- src/Core/src/Handlers/Editor/EditorHandler.cs | 5 +- .../Handlers/Entry/EntryHandler.Android.cs | 6 -- src/Core/src/Handlers/Entry/EntryHandler.cs | 5 +- .../SearchBar/SearchBarHandler.Android.cs | 6 -- .../Handlers/SearchBar/SearchBarHandler.cs | 5 +- .../src/Platform/Android/KeyboardManager.cs | 51 ++++++---- .../Platform/Android/TextViewExtensions.cs | 12 --- .../src/Platform/Android/ViewExtensions.cs | 8 -- .../TextInput/TextInputHandlerTests.cs | 29 +----- src/Core/tests/DeviceTests/Stubs/StubBase.cs | 6 +- .../AssertionExtensions.Android.cs | 98 +++++-------------- 18 files changed, 77 insertions(+), 257 deletions(-) delete mode 100644 src/Controls/tests/DeviceTests/Elements/TextInput/TextInputTests.Android.cs delete mode 100644 src/Controls/tests/DeviceTests/Elements/TextInput/TextInputTests.cs diff --git a/src/Compatibility/Core/src/Android/AppCompat/FormsAppCompatActivity.cs b/src/Compatibility/Core/src/Android/AppCompat/FormsAppCompatActivity.cs index 94fb9606c6bd..7a433c74536b 100644 --- a/src/Compatibility/Core/src/Android/AppCompat/FormsAppCompatActivity.cs +++ b/src/Compatibility/Core/src/Android/AppCompat/FormsAppCompatActivity.cs @@ -294,7 +294,7 @@ protected override void OnNewIntent(Intent intent) protected override void OnPause() { - _layout.HideKeyboard(); + _layout.HideKeyboard(true); // Stop animations or other ongoing actions that could consume CPU // Commit unsaved changes, build only if users expect such changes to be permanently saved when thy leave such as a draft email diff --git a/src/Controls/src/Core/VisualElement.cs b/src/Controls/src/Core/VisualElement.cs index 900782063f24..41adae244b9e 100644 --- a/src/Controls/src/Core/VisualElement.cs +++ b/src/Controls/src/Core/VisualElement.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using System.ComponentModel; using System.Globalization; +using System.Runtime.InteropServices.ComTypes; using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Controls.Shapes; +//using Microsoft.Maui.Controls.Shapes; using Microsoft.Maui.Graphics; using Geometry = Microsoft.Maui.Controls.Shapes.Geometry; using Rect = Microsoft.Maui.Graphics.Rect; @@ -866,14 +868,7 @@ public ResourceDictionary Resources public bool Focus() { if (IsFocused) - { -#if ANDROID - // TODO: Refactor using mappers for .NET 8 - if (this is ITextInput && Handler is IPlatformViewHandler platformViewHandler) - KeyboardManager.ShowKeyboard(platformViewHandler.PlatformView); -#endif return true; - } if (FocusChangeRequested == null) { diff --git a/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs index c6a9aa8d5835..2ed7283e10b6 100644 --- a/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs +++ b/src/Controls/tests/DeviceTests/ControlsHandlerTestBase.cs @@ -1,15 +1,24 @@ using System; using System.Linq; +using System.Reflection; +using System.Reflection.Metadata; +using System.Reflection.PortableExecutable; using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Maui.Controls; using Microsoft.Maui.Controls.Handlers; +using Microsoft.Maui.Controls.Hosting; +using Microsoft.Maui.Devices; using Microsoft.Maui.DeviceTests.Stubs; +using Microsoft.Maui.Dispatching; using Microsoft.Maui.Graphics; using Microsoft.Maui.Handlers; using Microsoft.Maui.Hosting; +using Microsoft.Maui.LifecycleEvents; using Microsoft.Maui.Platform; +using Microsoft.Maui.TestUtils.DeviceTests.Runners; using Xunit; #if ANDROID || IOS || MACCATALYST using ShellHandler = Microsoft.Maui.Controls.Handlers.Compatibility.ShellRenderer; @@ -63,16 +72,6 @@ protected async Task CreateHandlerAsync(IElement view) where THandler : IElementHandler, new() => await InvokeOnMainThreadAsync(() => CreateHandler(view)); - protected IElementHandler CreateHandler(IElement view) - { - var handler = view.ToHandler(MauiContext); - InitializeViewHandler(view, handler, MauiContext); - return handler; - } - - protected async Task CreateHandlerAsync(IElement view) => - await InvokeOnMainThreadAsync(() => CreateHandler(view)); - protected Task GetValueAsync(IElement view, Func func) where THandler : IElementHandler, new() { diff --git a/src/Controls/tests/DeviceTests/Elements/TextInput/TextInputTests.Android.cs b/src/Controls/tests/DeviceTests/Elements/TextInput/TextInputTests.Android.cs deleted file mode 100644 index 65242db56262..000000000000 --- a/src/Controls/tests/DeviceTests/Elements/TextInput/TextInputTests.Android.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Threading.Tasks; -using Microsoft.Maui.Controls; -using Xunit; - -namespace Microsoft.Maui.DeviceTests -{ - [Category(TestCategory.TextInput)] - [Collection(RunInNewWindowCollection)] - public partial class TextInputTests - { - [Theory] - [InlineData(typeof(Editor))] - [InlineData(typeof(Entry))] - [InlineData(typeof(SearchBar))] - public async Task ShowsKeyboardOnFocus(Type controlType) - { - SetupBuilder(); - var textInput = (View)Activator.CreateInstance(controlType); - - await InvokeOnMainThreadAsync(async () => - { - var handler = (IPlatformViewHandler)CreateHandler(textInput); - var platformView = handler.PlatformView; - - await platformView.AttachAndRun(async () => - { - textInput.Focus(); - await AssertionExtensions.WaitForFocused(platformView, 2000, $"WaitForFocused failed on Line 29 after first focus on {controlType}"); - await AssertionExtensions.WaitForKeyboardToShow(platformView, message: $"WaitForKeyboardToShow failed on Line 30 after first focus on {controlType}"); - - // Test that keyboard reappears when refocusing on an already focused TextInput control - await AssertionExtensions.HideKeyboardForView(platformView, message: $"HideKeyboardForView failed on Line 33 after first keyboard show on {controlType}"); - textInput.Focus(); - await AssertionExtensions.WaitForFocused(platformView, message: $"WaitForFocused failed on Line 35 after second focus on {controlType}"); - await AssertionExtensions.WaitForKeyboardToShow(platformView, message: $"WaitForKeyboardToShow failed on Line 36 after second focus on {controlType}"); - await AssertionExtensions.HideKeyboardForView(platformView, message: $"HideKeyboardForView failed on Line 37 after second keyboard show on {controlType}"); - }); - }); - } - } -} diff --git a/src/Controls/tests/DeviceTests/Elements/TextInput/TextInputTests.cs b/src/Controls/tests/DeviceTests/Elements/TextInput/TextInputTests.cs deleted file mode 100644 index 53833aeec51c..000000000000 --- a/src/Controls/tests/DeviceTests/Elements/TextInput/TextInputTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Microsoft.Maui.Controls; -using Microsoft.Maui.Handlers; -using Microsoft.Maui.Hosting; - -namespace Microsoft.Maui.DeviceTests -{ - - [Category(TestCategory.TextInput)] - public partial class TextInputTests : ControlsHandlerTestBase - { - void SetupBuilder() - { - EnsureHandlerCreated(builder => - { - builder.ConfigureMauiHandlers(handlers => - { - handlers.AddHandler(); - handlers.AddHandler(); - handlers.AddHandler(); - }); - }); - } - } -} diff --git a/src/Controls/tests/DeviceTests/TestCategory.cs b/src/Controls/tests/DeviceTests/TestCategory.cs index bda2f1f36650..92676d6b3192 100644 --- a/src/Controls/tests/DeviceTests/TestCategory.cs +++ b/src/Controls/tests/DeviceTests/TestCategory.cs @@ -35,7 +35,6 @@ public static class TestCategory public const string SearchBar = "SearchBar"; public const string Shell = "Shell"; public const string TabbedPage = "TabbedPage"; - public const string TextInput = "TextInput"; public const string Toolbar = "Toolbar"; public const string TemplatedView = "TemplatedView"; public const string View = "View"; diff --git a/src/Core/src/Handlers/Editor/EditorHandler.Android.cs b/src/Core/src/Handlers/Editor/EditorHandler.Android.cs index 58552b38d469..8b436ca91fd1 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.Android.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.Android.cs @@ -108,12 +108,6 @@ public static void MapCursorPosition(IEditorHandler handler, ITextInput editor) public static void MapSelectionLength(IEditorHandler handler, ITextInput editor) => handler.PlatformView?.UpdateSelectionLength(editor); - static void MapFocus(IEditorHandler handler, IEditor editor, object? args) - { - if (args is FocusRequest request) - handler.PlatformView?.Focus(request); - } - void OnPlatformViewAttachedToWindow(object? sender, ViewAttachedToWindowEventArgs e) { if (PlatformView.IsAlive() && PlatformView.Enabled) diff --git a/src/Core/src/Handlers/Editor/EditorHandler.cs b/src/Core/src/Handlers/Editor/EditorHandler.cs index 45d89b98b034..0fafad6dfe8e 100644 --- a/src/Core/src/Handlers/Editor/EditorHandler.cs +++ b/src/Core/src/Handlers/Editor/EditorHandler.cs @@ -39,12 +39,9 @@ public partial class EditorHandler : IEditorHandler public static CommandMapper CommandMapper = new(ViewCommandMapper) { -#if ANDROID - [nameof(IEditor.Focus)] = MapFocus -#endif }; - public EditorHandler() : this(Mapper) + public EditorHandler() : base(Mapper) { } diff --git a/src/Core/src/Handlers/Entry/EntryHandler.Android.cs b/src/Core/src/Handlers/Entry/EntryHandler.Android.cs index c6b46dd3933a..cddc695521e8 100644 --- a/src/Core/src/Handlers/Entry/EntryHandler.Android.cs +++ b/src/Core/src/Handlers/Entry/EntryHandler.Android.cs @@ -128,12 +128,6 @@ public static void MapClearButtonVisibility(IEntryHandler handler, IEntry entry) handler.PlatformView?.UpdateClearButtonVisibility(entry, platformHandler.GetClearButtonDrawable); } - static void MapFocus(IEntryHandler handler, IEntry entry, object? args) - { - if (args is FocusRequest request) - handler.PlatformView?.Focus(request); - } - void OnTextChanged(object? sender, TextChangedEventArgs e) { if (VirtualView == null) diff --git a/src/Core/src/Handlers/Entry/EntryHandler.cs b/src/Core/src/Handlers/Entry/EntryHandler.cs index 38f0b20ef605..3e7e466b7151 100644 --- a/src/Core/src/Handlers/Entry/EntryHandler.cs +++ b/src/Core/src/Handlers/Entry/EntryHandler.cs @@ -41,12 +41,9 @@ public partial class EntryHandler : IEntryHandler public static CommandMapper CommandMapper = new(ViewCommandMapper) { -#if ANDROID - [nameof(IEntry.Focus)] = MapFocus -#endif }; - public EntryHandler() : this(Mapper) + public EntryHandler() : base(Mapper) { } diff --git a/src/Core/src/Handlers/SearchBar/SearchBarHandler.Android.cs b/src/Core/src/Handlers/SearchBar/SearchBarHandler.Android.cs index 446686e3bcd2..30cdc09bc029 100644 --- a/src/Core/src/Handlers/SearchBar/SearchBarHandler.Android.cs +++ b/src/Core/src/Handlers/SearchBar/SearchBarHandler.Android.cs @@ -114,12 +114,6 @@ public static void MapCancelButtonColor(ISearchBarHandler handler, ISearchBar se handler.PlatformView?.UpdateCancelButtonColor(searchBar); } - static void MapFocus(ISearchBarHandler handler, ISearchBar searchBar, object? args) - { - if (args is FocusRequest request) - handler.QueryEditor?.Focus(request); - } - void OnQueryTextSubmit(object? sender, QueryTextSubmitEventArgs e) { VirtualView.SearchButtonPressed(); diff --git a/src/Core/src/Handlers/SearchBar/SearchBarHandler.cs b/src/Core/src/Handlers/SearchBar/SearchBarHandler.cs index 16045fa4a2f8..d45b40a0273b 100644 --- a/src/Core/src/Handlers/SearchBar/SearchBarHandler.cs +++ b/src/Core/src/Handlers/SearchBar/SearchBarHandler.cs @@ -37,12 +37,9 @@ public partial class SearchBarHandler : ISearchBarHandler public static CommandMapper CommandMapper = new(ViewCommandMapper) { -#if ANDROID - [nameof(ISearchBar.Focus)] = MapFocus -#endif }; - public SearchBarHandler() : this(Mapper) + public SearchBarHandler() : base(Mapper) { } diff --git a/src/Core/src/Platform/Android/KeyboardManager.cs b/src/Core/src/Platform/Android/KeyboardManager.cs index b4d6646142a2..8d9e5b3903ef 100644 --- a/src/Core/src/Platform/Android/KeyboardManager.cs +++ b/src/Core/src/Platform/Android/KeyboardManager.cs @@ -1,41 +1,39 @@ using System; +using Android.App; using Android.Content; +using Android.OS; +using Android.Views; using Android.Views.InputMethods; using Android.Widget; using AndroidX.Core.View; using AView = Android.Views.View; -using SearchView = AndroidX.AppCompat.Widget.SearchView; namespace Microsoft.Maui.Platform { internal static class KeyboardManager { - internal static void HideKeyboard(this AView inputView) + internal static void HideKeyboard(this AView inputView, bool overrideValidation = false) { - if (inputView?.Context is null) + if (inputView?.Context == null) throw new ArgumentNullException(nameof(inputView) + " must be set before the keyboard can be hidden."); - var focusedView = inputView.Context?.GetActivity()?.Window?.CurrentFocus; - AView tokenView = focusedView ?? inputView; - var context = tokenView.Context; - - if (context is null) - return; - - using (var inputMethodManager = context.GetSystemService(Context.InputMethodService) as InputMethodManager) + using (var inputMethodManager = (InputMethodManager)inputView.Context.GetSystemService(Context.InputMethodService)!) { - var windowToken = tokenView.WindowToken; - if (windowToken is not null && inputMethodManager is not null) + if (!overrideValidation && !(inputView is EditText || inputView is TextView || inputView is SearchView)) + throw new ArgumentException("inputView should be of type EditText, SearchView, or TextView"); + + var windowToken = inputView.WindowToken; + if (windowToken != null && inputMethodManager != null) inputMethodManager.HideSoftInputFromWindow(windowToken, HideSoftInputFlags.None); } } internal static void ShowKeyboard(this TextView inputView) { - if (inputView?.Context is null) + if (inputView?.Context == null) throw new ArgumentNullException(nameof(inputView) + " must be set before the keyboard can be shown."); - using (var inputMethodManager = inputView.Context.GetSystemService(Context.InputMethodService) as InputMethodManager) + using (var inputMethodManager = (InputMethodManager)inputView.Context.GetSystemService(Context.InputMethodService)!) { // The zero value for the second parameter comes from // https://developer.android.com/reference/android/view/inputmethod/InputMethodManager#showSoftInput(android.view.View,%20int) @@ -46,22 +44,34 @@ internal static void ShowKeyboard(this TextView inputView) internal static void ShowKeyboard(this SearchView searchView) { - if (searchView?.Context is null || searchView?.Resources is null) + if (searchView?.Context == null || searchView?.Resources == null) { throw new ArgumentNullException(nameof(searchView)); } - var queryEditor = searchView.GetFirstChildOfType(); + // Dig into the SearchView and find the actual TextView that we want to show keyboard input for + int searchViewTextViewId = searchView.Resources.GetIdentifier("android:id/search_src_text", null, null); + + if (searchViewTextViewId == 0) + { + // Cannot find the resource Id; nothing else to do + return; + } + + var textView = searchView.FindViewById(searchViewTextViewId); - if (queryEditor is null) + if (textView == null) + { + // Cannot find the TextView; nothing else to do return; + } using (var inputMethodManager = (InputMethodManager)searchView.Context.GetSystemService(Context.InputMethodService)!) { // The zero value for the second parameter comes from // https://developer.android.com/reference/android/view/inputmethod/InputMethodManager#showSoftInput(android.view.View,%20int) // Apparently there's no named value for zero in this case - inputMethodManager?.ShowSoftInput(queryEditor, 0); + inputMethodManager?.ShowSoftInput(textView, 0); } } @@ -78,7 +88,6 @@ internal static void ShowKeyboard(this AView view) } } - internal static void PostShowKeyboard(this AView view) { void ShowKeyboard() @@ -99,7 +108,7 @@ void ShowKeyboard() public static bool IsSoftKeyboardVisible(this AView view) { var insets = ViewCompat.GetRootWindowInsets(view); - if (insets is null) + if (insets == null) return false; var result = insets.IsVisible(WindowInsetsCompat.Type.Ime()); diff --git a/src/Core/src/Platform/Android/TextViewExtensions.cs b/src/Core/src/Platform/Android/TextViewExtensions.cs index cd2e373cc320..dccf375b6187 100644 --- a/src/Core/src/Platform/Android/TextViewExtensions.cs +++ b/src/Core/src/Platform/Android/TextViewExtensions.cs @@ -124,17 +124,5 @@ public static void UpdateLineHeight(this TextView textView, ILabel label) if (label.LineHeight >= 0) textView.SetLineSpacing(0, (float)label.LineHeight); } - - internal static void Focus(this TextView textView, FocusRequest request) - { - if (textView is null) - return; - - textView.Focus(request, () => - { - if (textView.ShowSoftInputOnFocus) - KeyboardManager.PostShowKeyboard(textView); - }); - } } } \ No newline at end of file diff --git a/src/Core/src/Platform/Android/ViewExtensions.cs b/src/Core/src/Platform/Android/ViewExtensions.cs index bb1459221618..4c5b21ad6717 100644 --- a/src/Core/src/Platform/Android/ViewExtensions.cs +++ b/src/Core/src/Platform/Android/ViewExtensions.cs @@ -63,11 +63,6 @@ public static void UpdateIsEnabled(this AView platformView, IView view) } public static void Focus(this AView platformView, FocusRequest request) - { - platformView?.Focus(request, null); - } - - internal static void Focus(this AView platformView, FocusRequest request, Action? focusRequested) { request.IsFocused = true; @@ -88,9 +83,6 @@ void RequestFocus() return; platformView?.RequestFocus(); - - if (platformView?.RequestFocus() == true) - focusRequested?.Invoke(); } } diff --git a/src/Core/tests/DeviceTests/Handlers/TextInput/TextInputHandlerTests.cs b/src/Core/tests/DeviceTests/Handlers/TextInput/TextInputHandlerTests.cs index 14829ef3a758..5aa951328d99 100644 --- a/src/Core/tests/DeviceTests/Handlers/TextInput/TextInputHandlerTests.cs +++ b/src/Core/tests/DeviceTests/Handlers/TextInput/TextInputHandlerTests.cs @@ -1,5 +1,9 @@ -using System.Threading.Tasks; +using System; +using System.Collections.Generic; +using System.Threading.Tasks; using Microsoft.Maui.DeviceTests.Stubs; +using Microsoft.Maui.Graphics; +using Microsoft.Maui.Handlers; using Xunit; namespace Microsoft.Maui.DeviceTests @@ -79,28 +83,5 @@ await InvokeOnMainThreadAsync(() => protected abstract void UpdateCursorStartPosition(THandler entryHandler, int position); protected abstract int GetCursorStartPosition(THandler entryHandler); protected abstract void SetNativeText(THandler entryHandler, string text); - -#if ANDROID - [Fact] - public async Task ShowsKeyboardOnFocus() - { - var button = new ButtonStub(); - var textInput = new TStub(); - - await InvokeOnMainThreadAsync(async () => - { - var handler = (IPlatformViewHandler)CreateHandler(textInput); - var platformView = handler.PlatformView; - - await platformView.AttachAndRun(async () => - { - button.Focus(); - textInput.Focus(); - await AssertionExtensions.WaitForKeyboardToShow(platformView); - await AssertionExtensions.HideKeyboardForView(platformView); - }); - }); - } -#endif } } \ No newline at end of file diff --git a/src/Core/tests/DeviceTests/Stubs/StubBase.cs b/src/Core/tests/DeviceTests/Stubs/StubBase.cs index ac9ac73678fc..f39485b00b18 100644 --- a/src/Core/tests/DeviceTests/Stubs/StubBase.cs +++ b/src/Core/tests/DeviceTests/Stubs/StubBase.cs @@ -127,9 +127,9 @@ public void InvalidateMeasure() public bool Focus() { - FocusRequest focusRequest = new FocusRequest(false); - Handler?.Invoke(nameof(IView.Focus), focusRequest); - return focusRequest.IsFocused; + IsFocused = true; + + return true; } public void Unfocus() diff --git a/src/TestUtils/src/DeviceTests/AssertionExtensions.Android.cs b/src/TestUtils/src/DeviceTests/AssertionExtensions.Android.cs index 79b2bd577a5e..54c6f54aa960 100644 --- a/src/TestUtils/src/DeviceTests/AssertionExtensions.Android.cs +++ b/src/TestUtils/src/DeviceTests/AssertionExtensions.Android.cs @@ -14,7 +14,6 @@ using Xunit.Sdk; using AColor = Android.Graphics.Color; using AView = Android.Views.View; -using SearchView = AndroidX.AppCompat.Widget.SearchView; namespace Microsoft.Maui.DeviceTests { @@ -48,46 +47,26 @@ public static async Task SendKeyboardReturnType(this AView view, ReturnType retu await Task.Delay(10); } - public static async Task WaitForFocused(this AView view, int timeout = 1000, string message = "") + public static async Task WaitForFocused(this AView view, int timeout = 1000) { - try + if (!view.IsFocused) { - if (view is SearchView searchView) - { - var queryEditor = searchView.GetFirstChildOfType(); - - if (queryEditor is null) - return; + TaskCompletionSource focusSource = new TaskCompletionSource(); + view.FocusChange += OnFocused; + await focusSource.Task.WaitAsync(TimeSpan.FromMilliseconds(timeout)); - view = queryEditor; - } + // Even thuogh the event fires focus hasn't fully been achieved + await Task.Delay(10); - if (!view.IsFocused) + void OnFocused(object? sender, AView.FocusChangeEventArgs e) { - TaskCompletionSource focusSource = new TaskCompletionSource(); - view.FocusChange += OnFocused; - await focusSource.Task.WaitAsync(TimeSpan.FromMilliseconds(timeout)); - - // Even though the event fires focus hasn't fully been achieved - await Task.Delay(10); - - void OnFocused(object? sender, AView.FocusChangeEventArgs e) - { - if (!e.HasFocus) - return; + if (!e.HasFocus) + return; - view.FocusChange -= OnFocused; - focusSource.SetResult(); - } + view.FocusChange -= OnFocused; + focusSource.SetResult(); } } - catch (Exception ex) - { - if (!string.IsNullOrEmpty(message)) - throw new Exception(message, ex); - else - throw; - } } public static async Task WaitForUnFocused(this AView view, int timeout = 1000) @@ -123,54 +102,25 @@ public static Task FocusView(this AView view, int timeout = 1000) return Task.CompletedTask; } - public static async Task ShowKeyboardForView(this AView view, int timeout = 1000, string message = "") + public static async Task ShowKeyboardForView(this AView view, int timeout = 1000) { - try - { - await view.FocusView(timeout); - KeyboardManager.ShowKeyboard(view); - await view.WaitForKeyboardToShow(timeout); - } - catch (Exception ex) - { - if (!string.IsNullOrEmpty(message)) - throw new Exception(message, ex); - else - throw; - } + await view.FocusView(timeout); + KeyboardManager.ShowKeyboard(view); + await view.WaitForKeyboardToShow(timeout); } - public static async Task HideKeyboardForView(this AView view, int timeout = 1000, string message = "") + public static async Task HideKeyboardForView(this AView view, int timeout = 1000) { - try - { - await view.FocusView(timeout); - KeyboardManager.HideKeyboard(view); - await view.WaitForKeyboardToHide(timeout); - } - catch (Exception ex) - { - if (!string.IsNullOrEmpty(message)) - throw new Exception(message, ex); - else - throw; - } + await view.FocusView(timeout); + KeyboardManager.HideKeyboard(view); + await view.WaitForKeyboardToHide(timeout); } - public static async Task WaitForKeyboardToShow(this AView view, int timeout = 1000, string message = "") + public static async Task WaitForKeyboardToShow(this AView view, int timeout = 1000) { - try - { - var result = await Wait(() => KeyboardManager.IsSoftKeyboardVisible(view), timeout); - Assert.True(result); - } - catch (Exception ex) - { - if (!string.IsNullOrEmpty(message)) - throw new Exception(message, ex); - else - throw; - } + var result = await Wait(() => KeyboardManager.IsSoftKeyboardVisible(view), timeout); + Assert.True(result); + } public static async Task WaitForKeyboardToHide(this AView view, int timeout = 1000)