Skip to content

Commit

Permalink
Merge pull request #924 from Corvus400/bug/fix_clear_focus_profile_ca…
Browse files Browse the repository at this point in the history
…rd_screen

🔧 We have made some modifications to the profile card screen so that focus is handled appropriately.
  • Loading branch information
takahirom authored Sep 2, 2024
2 parents 4eeb9c3 + cbea568 commit 24ec63a
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -78,6 +79,7 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.testTag
Expand Down Expand Up @@ -231,6 +233,7 @@ internal fun ProfileCardScreen(
val snackbarHostState = remember { SnackbarHostState() }
val layoutDirection = LocalLayoutDirection.current
val keyboardController = LocalSoftwareKeyboardController.current
val focusManager = LocalFocusManager.current

SnackbarMessageEffect(
snackbarHostState = snackbarHostState,
Expand All @@ -256,6 +259,7 @@ internal fun ProfileCardScreen(
.pointerInput(Unit) {
detectTapGestures {
keyboardController?.hide()
focusManager.clearFocus()
}
},
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
Expand Down Expand Up @@ -387,6 +391,8 @@ internal fun EditScreen(
}
}

val focusManager = LocalFocusManager.current

Column(
modifier = modifier
.fillMaxWidth()
Expand Down Expand Up @@ -436,6 +442,11 @@ internal fun EditScreen(
imeAction = ImeAction.Done,
keyboardType = KeyboardType.Uri,
),
keyboardActions = KeyboardActions(
onDone = {
focusManager.clearFocus()
},
),
)

Column(
Expand Down Expand Up @@ -520,6 +531,7 @@ private fun InputFieldWithError(
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
maxLines: Int = 1,
) {
Column(modifier = modifier) {
Expand All @@ -539,6 +551,7 @@ private fun InputFieldWithError(
isError = isError,
shape = RoundedCornerShape(4.dp),
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
maxLines = maxLines,
modifier = Modifier
.indicatorLine(
Expand Down

0 comments on commit 24ec63a

Please sign in to comment.