-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Propagate composition locals to layers in the (re)composition phase #1233
Propagate composition locals to layers in the (re)composition phase #1233
Conversation
…mmediately in rememberComposeSceneLayer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm.
Let's wait for Ivan, maybe there were issues with setting these in the composition instead of SideEffect
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -581,7 +587,14 @@ private class MultiLayerComposeSceneImpl( | |||
composition?.dispose() | |||
composition = owner.setContent( | |||
parent = this@AttachedComposeSceneLayer.compositionContext, | |||
{ this@AttachedComposeSceneLayer.compositionLocalContext } | |||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to remove this lambda completely (it has the same default value), otherwise it is difficult to read without IDE support. The comment itself can be placed above setContent
compose/ui/ui/src/skikoMain/kotlin/androidx/compose/ui/scene/ComposeSceneLayer.skiko.kt
Show resolved
Hide resolved
DisposableEffect(Unit) { | ||
onDispose { | ||
layer.close() | ||
} | ||
} | ||
SideEffect { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like SideEffect
was required because of rememberUpdatedState
. The current state works fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SideEffect
was introduced in #562
When the value of a composition local that is provided outside a
Popup
changes, typically, the order of events is:CompositionLocalProvider
.CompositionLocalProvider
is recomposed, modifying the composition local context, which triggersrememberComposeSceneLayer
to recompose, as it readscurrentCompositionLocalContext
.rememberComposeSceneLayer
is recomposed.SideEffect
inrememberComposeSceneLayer
is executed, changing thecompositionLocalContext
of the layer, which triggers recomposition of the layer (popup) content.However, if the layer content is recomposed (for unrelated reasons) in the same frame as
rememberComposeSceneLayer
, it will read an old value of the composition local.The question then is why doesn't the layer content recompose again when the
SideEffect
updates compositionLocalContext. The answer is thatMultiLayerComposeScene.compositionLocalContext
is not a Compose state.Proposed Changes
Apply compositionLocalContext, density and layoutDirection to layer immediately in rememberComposeSceneLayer.
Testing
Test: Added a unit test
This PR should be verified by QA.
Issues Fixed
Fixes: JetBrains/compose-multiplatform#4558