Hide soft keyboard when attempting to login (#982)

This commit is contained in:
David Perez 2024-02-07 18:48:17 -06:00 committed by Álison Fernandes
parent f7150d33cb
commit a6c6af7a56
2 changed files with 15 additions and 2 deletions

View file

@ -27,6 +27,8 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext 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.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.semantics
@ -68,6 +70,7 @@ fun LoginScreen(
onNavigateToTwoFactorLogin: (String, String?) -> Unit, onNavigateToTwoFactorLogin: (String, String?) -> Unit,
viewModel: LoginViewModel = hiltViewModel(), viewModel: LoginViewModel = hiltViewModel(),
intentManager: IntentManager = LocalIntentManager.current, intentManager: IntentManager = LocalIntentManager.current,
keyboardController: SoftwareKeyboardController? = LocalSoftwareKeyboardController.current,
) { ) {
val state by viewModel.stateFlow.collectAsStateWithLifecycle() val state by viewModel.stateFlow.collectAsStateWithLifecycle()
val context = LocalContext.current val context = LocalContext.current
@ -148,7 +151,10 @@ fun LoginScreen(
{ viewModel.trySendAction(LoginAction.MasterPasswordHintClick) } { viewModel.trySendAction(LoginAction.MasterPasswordHintClick) }
}, },
onLoginButtonClick = remember(viewModel) { onLoginButtonClick = remember(viewModel) {
{ viewModel.trySendAction(LoginAction.LoginButtonClick) } {
keyboardController?.hide()
viewModel.trySendAction(LoginAction.LoginButtonClick)
}
}, },
onLoginWithDeviceClick = remember(viewModel) { onLoginWithDeviceClick = remember(viewModel) {
{ viewModel.trySendAction(LoginAction.LoginWithDeviceButtonClick) } { viewModel.trySendAction(LoginAction.LoginWithDeviceButtonClick) }

View file

@ -1,6 +1,7 @@
package com.x8bit.bitwarden.ui.auth.feature.login package com.x8bit.bitwarden.ui.auth.feature.login
import android.net.Uri import android.net.Uri
import androidx.compose.ui.platform.SoftwareKeyboardController
import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.assertCountEquals
import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.filter 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.performLogoutAccountClick
import com.x8bit.bitwarden.ui.util.performLogoutAccountConfirmationClick import com.x8bit.bitwarden.ui.util.performLogoutAccountConfirmationClick
import io.mockk.every import io.mockk.every
import io.mockk.just
import io.mockk.mockk import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify import io.mockk.verify
import junit.framework.TestCase.assertTrue import junit.framework.TestCase.assertTrue
import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.MutableStateFlow
@ -41,8 +44,11 @@ import org.junit.Before
import org.junit.Test import org.junit.Test
class LoginScreenTest : BaseComposeTest() { class LoginScreenTest : BaseComposeTest() {
private val keyboardController: SoftwareKeyboardController = mockk {
every { hide() } just runs
}
private val intentManager = mockk<IntentManager>(relaxed = true) { private val intentManager = mockk<IntentManager>(relaxed = true) {
every { startCustomTabsActivity(any()) } returns Unit every { startCustomTabsActivity(any()) } just runs
} }
private var onNavigateBackCalled = false private var onNavigateBackCalled = false
private var onNavigateToMasterPasswordHintCalled = false private var onNavigateToMasterPasswordHintCalled = false
@ -67,6 +73,7 @@ class LoginScreenTest : BaseComposeTest() {
onNavigateToTwoFactorLogin = { _, _ -> onNavigateToTwoFactorLoginCalled = true }, onNavigateToTwoFactorLogin = { _, _ -> onNavigateToTwoFactorLoginCalled = true },
viewModel = viewModel, viewModel = viewModel,
intentManager = intentManager, intentManager = intentManager,
keyboardController = keyboardController,
) )
} }
} }