Hi folks, I trying to embed Compose runtime in a project and I'm not getting it to recompose when a ...
s
Hi folks, I trying to embed Compose runtime in a project and I'm not getting it to recompose when a state change and updating my tree, what I'm missing? Source: https://github.com/DevSrSouza/compose-tree-test/blob/master/src/main/kotlin/Test.kt
a
It's likely that you aren't scheduling
Snapshot.sendApplyNotifications()
when snapshot writes happen in the global transaction. Compose UI uses this internal utility to do it: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]androidx/compose/ui/platform/GlobalSnapshotManager.android.kt
You can call
Snapshot.sendApplyNotifications()
manually in your test after performing snapshot writes to confirm.
this is decoupled from the runtime itself because it's affected by other environmental expectations. For Compose UI there's a main thread and an event loop, and the intent is to batch snapshot state changes within single messages processed on that event loop. So this simply posts it to handle as part of a later event loop message on that main thread.
s
Thank you, was my mistake on
GlobalSnapshotManager
, I was not registering the GlobalWriterObserver correctly