https://kotlinlang.org logo
Title
j

Jakob K

10/25/2021, 2:40 PM
ComposeScene
has the
hasInvalidations
function, which I currently check periodically. Is there a way to setup a callback which will be executed if this value changes to true?
i

Igor Demin

10/25/2021, 3:33 PM
ComposeScene
has
invalidate
callback in its constructor, which will be called, when ComposeScene should be rerendered
👍 1
j

Jakob K

10/25/2021, 9:45 PM
And how can I make sure that calling
scene.render(canvas, System.nanoTime())
inside that
invalidate
callback does not lead to concurrency issues?
i

Igor Demin

10/25/2021, 9:59 PM
You shouldn't call
render
in it. You should schedule a new frame inside your rendering loop,
render
should be called inside it. See the example
j

Jakob K

10/25/2021, 10:15 PM
I assume that in this example
GlfwCoroutineDispatcher()
(and using that for the
FrameDispatcher
) is the important part, because it is only single threaded, am I right?
i

Igor Demin

10/25/2021, 10:30 PM
Yes, it is important that it is single threaded. It is mostly for `LaunchedEffect`'s, which can't perform in parallel with ComposeScene methods. Sorry, it is not true, `LaunchedEffect`'s theoretically can launch in parallel. It also used for other things, like recompositions, and scheduling callbacks.