From f80ac6dc50217280fe848fdd874332fe43f71b6d Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Tue, 23 Apr 2024 04:13:14 +0700 Subject: [PATCH] android: proper hiding keyboard when entering passcode (#4066) --- .../kotlin/chat/simplex/common/platform/UI.android.kt | 5 ++++- .../src/commonMain/kotlin/chat/simplex/common/platform/UI.kt | 2 +- .../chat/simplex/common/views/localauth/PasscodeView.kt | 2 ++ .../kotlin/chat/simplex/common/platform/UI.desktop.kt | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/UI.android.kt b/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/UI.android.kt index 5a4ae01098..c90946c95b 100644 --- a/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/UI.android.kt +++ b/apps/multiplatform/common/src/androidMain/kotlin/chat/simplex/common/platform/UI.android.kt @@ -67,10 +67,13 @@ actual fun getKeyboardState(): State { return keyboardState } -actual fun hideKeyboard(view: Any?) { +actual fun hideKeyboard(view: Any?, clearFocus: Boolean) { // LALAL // LocalSoftwareKeyboardController.current?.hide() if (view is View) { + if (clearFocus) { + view.clearFocus() + } (androidAppContext.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager).hideSoftInputFromWindow(view.windowToken, 0) } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/UI.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/UI.kt index 28ac357c2d..af202fcabd 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/UI.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/platform/UI.kt @@ -13,7 +13,7 @@ expect fun LocalMultiplatformView(): Any? @Composable expect fun getKeyboardState(): State -expect fun hideKeyboard(view: Any?) +expect fun hideKeyboard(view: Any?, clearFocus: Boolean = false) expect fun androidIsFinishingMainActivity(): Boolean diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/localauth/PasscodeView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/localauth/PasscodeView.kt index 2b2f006d25..9b25e9b5e0 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/localauth/PasscodeView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/localauth/PasscodeView.kt @@ -135,7 +135,9 @@ fun PasscodeView( if (!buttonsEnabled.value) { ProgressIndicator() } + val view = LocalMultiplatformView() LaunchedEffect(Unit) { + hideKeyboard(view, true) focusRequester.requestFocus() // Disallow to steal a focus by clicking on buttons or using Tab focusRequester.captureFocus() diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/UI.desktop.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/UI.desktop.kt index b5a0e2e008..e49dc6f2b1 100644 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/UI.desktop.kt +++ b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/platform/UI.desktop.kt @@ -16,7 +16,7 @@ actual fun LocalMultiplatformView(): Any? = null @Composable actual fun getKeyboardState(): State = remember { mutableStateOf(KeyboardState.Opened) } -actual fun hideKeyboard(view: Any?) {} +actual fun hideKeyboard(view: Any?, clearFocus: Boolean) {} actual fun androidIsFinishingMainActivity(): Boolean = false