I have a lazyList of items where I am showing a number. When the user presses the number, I show a TextField, so that the user can edit the number.
However, if I want to edit a number that is below where the IME will appear, the textfield will immediatly lose focus and trigger the showNumber method.
I show/hide the number/textfield like so:
if (isEditing) ExpenseTextField() {
isEditing = false // onConfirmInput
} else ExpenseDisplay() {
isEditing = true // onClickNumber
}
In the TextField, I am listening to the focus state, and triggering the onConfirmInput when focus is lost
modifier = Modifier
.focusRequester(focusRequester)
.onFocusChanged { state ->
inFocus = state.hasFocus
coroutineScope.launch {
delay(50)
if (!inFocus)
onConfirmInput()
}
},
I had to add the delay(50)
because the focus state will trigger multiple times, and I can only get the latest if I wait a bit.
This is the output:
As you can see, the desired effect works with most of the elemnts, but not the bottom one, that will be overlapped by the IME.