https://kotlinlang.org logo
#compose
Title
# compose
h

Henri Gourvest

10/12/2023, 9:10 PM
Hello, is there a way to change two states atomically? For example, to draw an object, I need to change the scale and translation. I don't want the object to be redrawn before I've changed these two states.
o

Oliver.O

10/12/2023, 9:38 PM
What makes you think you need to do this? Compose will wait until the next frame before recomposing/redrawing.
f

Francesc

10/12/2023, 9:54 PM
while you may not need it in this case, the way to have multiple state updates happen atomically is to use
Snapshot.withMutableSnapshot
☝️ 3
☝🏻 1
☝🏾 1
v

vide

10/13/2023, 5:12 AM
^ this is only needed if you are operating from somewhere else than the UI thread
h

Henri Gourvest

10/13/2023, 5:22 AM
Thank you for your very helpful answers. I wrongly assumed that this was the reason for my display bug. At least I've eliminated that possibility and learned something. Have a nice day!
o

Oliver.O

10/13/2023, 9:54 AM
Good news! If you need to use
Snapshot.withMutableSnapshot
in the future, be aware of this:
[block] must not suspend if [withMutableSnapshot] is called from a suspend function.
As of Compose 1.5.1,
withMutableSnapshot
is still tagged with:
Copy code
// TODO: determine a good way to prevent/discourage suspending in an inlined [block]