I'm getting key events twice when I trigger a reco...
# compose-desktop
r
I'm getting key events twice when I trigger a recomposition in
onPreviewKeyEvent
, is this a known issue? I just needed to only respond to key down events
The handler is:
Copy code
.onPreviewKeyEvent {
    when (it.key) {
        Key.Escape -> {
            editing = false
            true
        }
        Key.Enter, Key.NumPadEnter -> {
            editing = !editing
            true
        }
        Key.Plus, Key.DirectionRight -> {
            setMax(max + 1)
            true
        }
        Key.Minus, Key.DirectionLeft -> {
            setMax(max - 1)
            true
        }
        else -> false
    }
}
where
setMax
is a passed-in setter that will trigger recomposition.
I can work around it by using:
Copy code
scope.launch {
    delay(100)
    setMax(max - 1)
}
the
delay
is necessary.
a
you can filter it by event type. e.g.:
Copy code
it.type == KeyEventType.KeyDown
1
r
Yeah, that's what I ended up doing. It might be nice to have
onKeyDown(key: Key, action: () -> Unit)
style modifiers, eventually, I'm ending up with rather clunky handlers for
onKeyEvent
.