https://kotlinlang.org logo
#compose-android
Title
# compose-android
d

David

10/16/2023, 11:52 AM
Given a click from a button I open a dialog with a TextField, the textfield has
singleLine=true
and defined
onDone
KeyboardOption
and
KeyboardAction
. If I use keyboard to navigate to the dialog and the textfield enter some text and press enter to finish, it will not consume the enter-key. It will call the onDone, but also about 50ms later call onClick on the button that opened the Dialog causing it to reappear 🤯. I've tried achieve a fix by consuming the enter with
onKeyEvent
,
onPreviewKeyEvent
and
onPreInterceptKeyBeforeSoftkeyboard
but even though i return
true
and consume the press a onClick will happen on the button behind the open dialog. Any other idea how this can be prevented? Right now the only solution I've found that works is to add a delay of 50ms to before actually closing the dialog. 💩 Pressing enter on a button to close the dialog instead of enter using onDone works fine. For now I've made an issue on the google's tracker with a snippet on how to reproduce it: https://issuetracker.google.com/issues/305518328
Got me thinking, literally did this now:
Copy code
// Submit button's interactionSource                            val interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }

// TextField
...
onDone = {
    val press = PressInteraction.Press(Offset.Zero)
    interactionSource.tryEmit(press)  interactionSource.tryEmit(PressInteraction.Release(press))
},
...
Workaround, but I hate it 🙃
😵‍💫 1