Hello, is there a way to change two states atomica...
# compose
h
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
What makes you think you need to do this? Compose will wait until the next frame before recomposing/redrawing.
f
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
^ this is only needed if you are operating from somewhere else than the UI thread
h
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
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]