I wrote the code below to display a Dialog. When a user calls the onDone function on the keyboard, the keyboard should disappear. The problem is that the focusManager.clearFocus() line does nothing: the focus doesn't disappear. I tried everything, there is no way to remove the focus and make the keyboard disappear.
@Composable
fun showRouteDialog(
initialName: String,
initialDescription: String,
onResult: (String, String) -> Unit,
onDismiss: () -> Unit,
create: Boolean = true
) {
var name by remember { mutableStateOf(initialName) }
var description by remember { mutableStateOf(initialDescription) }
var isLoading by remember { mutableStateOf(false) }
val focusManager = LocalFocusManager.current
Dialog(onDismissRequest = { }) {
Column(
modifier = Modifier
.background(
MaterialTheme.colors.onPrimary,
MaterialTheme.shapes.medium
)
.padding(16.dp)
) {
TextField(
value = name,
enabled = !isLoading,
onValueChange = {
if (it.length <= 50) name = it
},
label = { Text(stringResource(R.string.name)) },
singleLine = true,
textStyle = TextStyle(
color = nodemappBlack,
fontSize = 18.textDp,
fontFamily = SourceSansPro
),
modifier = Modifier
.fillMaxWidth()
.padding(top = 8.dp),
keyboardOptions = KeyboardOptions(
imeAction = ImeAction.Done
),
keyboardActions = KeyboardActions(
onDone = {
focusManager.clearFocus()
}
)
)
}
}
}