From a6c6af7a56190e9ee799e5bda684fbb8ce6681c8 Mon Sep 17 00:00:00 2001 From: David Perez Date: Wed, 7 Feb 2024 18:48:17 -0600 Subject: [PATCH] Hide soft keyboard when attempting to login (#982) --- .../x8bit/bitwarden/ui/auth/feature/login/LoginScreen.kt | 8 +++++++- .../bitwarden/ui/auth/feature/login/LoginScreenTest.kt | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreen.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreen.kt index 604504828..1447c81e6 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreen.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreen.kt @@ -27,6 +27,8 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalSoftwareKeyboardController +import androidx.compose.ui.platform.SoftwareKeyboardController import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.semantics @@ -68,6 +70,7 @@ fun LoginScreen( onNavigateToTwoFactorLogin: (String, String?) -> Unit, viewModel: LoginViewModel = hiltViewModel(), intentManager: IntentManager = LocalIntentManager.current, + keyboardController: SoftwareKeyboardController? = LocalSoftwareKeyboardController.current, ) { val state by viewModel.stateFlow.collectAsStateWithLifecycle() val context = LocalContext.current @@ -148,7 +151,10 @@ fun LoginScreen( { viewModel.trySendAction(LoginAction.MasterPasswordHintClick) } }, onLoginButtonClick = remember(viewModel) { - { viewModel.trySendAction(LoginAction.LoginButtonClick) } + { + keyboardController?.hide() + viewModel.trySendAction(LoginAction.LoginButtonClick) + } }, onLoginWithDeviceClick = remember(viewModel) { { viewModel.trySendAction(LoginAction.LoginWithDeviceButtonClick) } diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreenTest.kt index 7316b530d..c562eb557 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreenTest.kt @@ -1,6 +1,7 @@ package com.x8bit.bitwarden.ui.auth.feature.login import android.net.Uri +import androidx.compose.ui.platform.SoftwareKeyboardController import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.filter @@ -32,7 +33,9 @@ import com.x8bit.bitwarden.ui.util.performLockAccountClick import com.x8bit.bitwarden.ui.util.performLogoutAccountClick import com.x8bit.bitwarden.ui.util.performLogoutAccountConfirmationClick import io.mockk.every +import io.mockk.just import io.mockk.mockk +import io.mockk.runs import io.mockk.verify import junit.framework.TestCase.assertTrue import kotlinx.coroutines.flow.MutableStateFlow @@ -41,8 +44,11 @@ import org.junit.Before import org.junit.Test class LoginScreenTest : BaseComposeTest() { + private val keyboardController: SoftwareKeyboardController = mockk { + every { hide() } just runs + } private val intentManager = mockk(relaxed = true) { - every { startCustomTabsActivity(any()) } returns Unit + every { startCustomTabsActivity(any()) } just runs } private var onNavigateBackCalled = false private var onNavigateToMasterPasswordHintCalled = false @@ -67,6 +73,7 @@ class LoginScreenTest : BaseComposeTest() { onNavigateToTwoFactorLogin = { _, _ -> onNavigateToTwoFactorLoginCalled = true }, viewModel = viewModel, intentManager = intentManager, + keyboardController = keyboardController, ) } }