From 215838007ffaff1b12e6ec1ac207e3378335a86f Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 1 Apr 2022 20:50:55 +0100 Subject: [PATCH] closing keyboard when submitting login details --- .../src/main/kotlin/app/dapk/st/login/LoginScreen.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/features/login/src/main/kotlin/app/dapk/st/login/LoginScreen.kt b/features/login/src/main/kotlin/app/dapk/st/login/LoginScreen.kt index 485c645..8227b82 100644 --- a/features/login/src/main/kotlin/app/dapk/st/login/LoginScreen.kt +++ b/features/login/src/main/kotlin/app/dapk/st/login/LoginScreen.kt @@ -11,9 +11,11 @@ import androidx.compose.material.icons.outlined.Lock import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Alignment +import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusDirection import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.platform.LocalSoftwareKeyboardController import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType @@ -25,6 +27,7 @@ import app.dapk.st.core.StartObserving import app.dapk.st.login.LoginEvent.LoginComplete import app.dapk.st.login.LoginScreenState.* +@OptIn(ExperimentalComposeUiApi::class) @Composable fun LoginScreen(loginViewModel: LoginViewModel, onLoggedIn: () -> Unit) { loginViewModel.ObserveEvents(onLoggedIn) @@ -34,6 +37,7 @@ fun LoginScreen(loginViewModel: LoginViewModel, onLoggedIn: () -> Unit) { var userName by rememberSaveable { mutableStateOf("") } var password by rememberSaveable { mutableStateOf("") } + val keyboardController = LocalSoftwareKeyboardController.current when (loginViewModel.state) { is Error -> { @@ -117,7 +121,10 @@ fun LoginScreen(loginViewModel: LoginViewModel, onLoggedIn: () -> Unit) { Button( modifier = Modifier.fillMaxWidth(), - onClick = { loginViewModel.login(userName, password) }, + onClick = { + keyboardController?.hide() + loginViewModel.login(userName, password) + }, enabled = canDoLoginAttempt ) { Text("Sign in".uppercase(), fontSize = 18.sp)