Fix keyboard not hidden.
This commit is contained in:
@@ -33,6 +33,7 @@ import androidx.compose.material3.Surface
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextField
|
import androidx.compose.material3.TextField
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@@ -43,6 +44,7 @@ import androidx.compose.ui.focus.focusRequester
|
|||||||
import androidx.compose.ui.focus.onFocusChanged
|
import androidx.compose.ui.focus.onFocusChanged
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
|
import androidx.compose.ui.platform.LocalTextInputService
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@@ -290,37 +292,40 @@ fun CenteredTextField(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Box(contentAlignment = Alignment.Center) {
|
Box(contentAlignment = Alignment.Center) {
|
||||||
TextField(
|
CompositionLocalProvider(LocalTextInputService provides null) {
|
||||||
value = value,
|
TextField(
|
||||||
onValueChange = { },
|
value = value,
|
||||||
placeholder = {
|
onValueChange = { },
|
||||||
if (!focused) {
|
placeholder = {
|
||||||
Text(
|
if (!focused) {
|
||||||
placeholder,
|
Text(
|
||||||
textAlign = TextAlign.Center,
|
placeholder,
|
||||||
modifier = Modifier.fillMaxWidth()
|
textAlign = TextAlign.Center,
|
||||||
)
|
modifier = Modifier.fillMaxWidth()
|
||||||
}
|
)
|
||||||
},
|
}
|
||||||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
|
},
|
||||||
singleLine = true,
|
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
|
||||||
readOnly = true,
|
singleLine = true,
|
||||||
modifier = modifier
|
readOnly = true,
|
||||||
.fillMaxWidth()
|
modifier = modifier
|
||||||
.onFocusChanged {
|
.fillMaxWidth()
|
||||||
onFocusStateChanged(it)
|
.onFocusChanged {
|
||||||
}
|
onFocusStateChanged(it)
|
||||||
)
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (focused) {
|
if (focused) {
|
||||||
val cursorColor = MaterialTheme.colorScheme.onSurface
|
val cursorColor = MaterialTheme.colorScheme.onSurface
|
||||||
val infiniteTransition = rememberInfiniteTransition()
|
val infiniteTransition = rememberInfiniteTransition(label = "blinkingCursor")
|
||||||
val alpha by infiniteTransition.animateFloat(
|
val alpha by infiniteTransition.animateFloat(
|
||||||
0f,
|
0f,
|
||||||
cursorColor.alpha,
|
cursorColor.alpha,
|
||||||
animationSpec = infiniteRepeatable(
|
animationSpec = infiniteRepeatable(
|
||||||
animation = tween(500),
|
animation = tween(500),
|
||||||
repeatMode = RepeatMode.Reverse
|
repeatMode = RepeatMode.Reverse
|
||||||
)
|
), label = "blinkingCursor"
|
||||||
)
|
)
|
||||||
Row {
|
Row {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user