JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
16.24k stars 1.18k forks source link

Not updating window when changing state from key event #1842

Closed dkim19375 closed 1 month ago

dkim19375 commented 2 years ago

In onKeyEvent in the Window parameter, I have it change the state in another function to update the window However, it doesn't update, so how should I force the window to update? Code: https://paste.helpch.at/lomewinoqo.java Logs:

updated (open window)
got key (press a key)
got key (press a key)
got key (press a key)

It only prints update when the window is first created

akurasov commented 2 years ago

Try to use update variable in some composable. E.g. add a checkbox showing its state.

dkim19375 commented 2 years ago

Try to use update variable in some composable. E.g. add a checkbox showing its state.

The thing is, that my app is supposed to change a color of a Box when certain keys are pressed, not from a checkbox. I also haven't found a KeyEvent function that is composable

dkim19375 commented 2 years ago

Found a solution (?) or workaround to this issue: I just added

update

at line 25 like this: https://paste.helpch.at/ujanunuyid.java

(I'm new to JB Compose - if this is intentional, then you can close this issue)

akurasov commented 2 years ago

Nope, this shouldn't be done like this. Try to add a Box, which color depends on the state. It also should work.

okushnikov commented 2 months ago

Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.