Hi, if invalidation occurs, it is recorded in `inv...
# compose
j
Hi, if invalidation occurs, it is recorded in
invalidateStack
, and if this stack is not empty, it is popped from this stack and returned from
endRestartGroup()
. Recomposition is performed through the returned
RecomposeScope
. Right? However, if there is no invalidation during the composition process, null is returned, and if invalidation is requested later, how does
endRestartGroup()
detect this and recompose again? If look at the implementation of
endRestartGroup()
, there is no code to track invalidations. Only request pop once.
Copy code
val scope = if (invalidateStack.isNotEmpty()) invalidateStack.pop() else null // RecomposeScopeImpl?
EDIT: I found some clues. Suspend until invalidation is added through
awaitWorkAvailable()
in
Recomposer.runRecomposeAndApplyChanges()
. If there is a waiting task(
hasSchedulingWork
), it immediately resumes
Continuation
and proceeds to recompose. Otherwise, it maintains the suspend state. The maintained suspend(
CancellableCoroutine
) is resumed when the operation is completed through the
effectJob
, but as I traced the places where the
effectJob
is used, there are only
rememberCoroutineScope()
and
LaunchedEffect
. Where will this suspend resume? I think it’s time to record invalidation, but it wasn’t. They are recorded regardless of
Job
.
a
well, it seems like your puzzlement might be because you're looking primarily at the invalidation code in
Composer.kt
, but it's only responsible for a portion of the invalidation logic. invalidate calls flow up to the
Recomposer.kt
, which is the parent of the root CompositionContext.
with respect to your questions about when we wake up to resume activity, note also that the code assumes an integration with the operating system invalidation model. On Android, Compose ties in to the Choreographer animate/measure/draw callbacks instead of handling scheduling with pure standard library Kotlin
I'm not sure precisely what you're asking here but anyway, it sounds like expanding your research to
Recomposer
and
Choreographer
might clarify things for you
j
Thank you so much 🥰 I will investigate again with your comments.