I see that `AbstractComposeView`, when creating it...
# compose
z
I see that
AbstractComposeView
, when creating its composition, looks up the view tree for a
CompositionReference
using
findViewTreeCompositionReference()
. This seems really neat, since it could enable
ComposeView -> AndroidView -> … -> ComposeView
hierarchies to automatically link their compositions. However, as far as I can tell,
AndroidView
never actually sets the view tree
CompositionReference
from the calling composition on its
View
, and this whole mechanism seems to currently only be used to find the
WindowRecomposer
. Would it be feasible for every
AndroidView
call to get a
CompositionReference
and set it on its
View
to support this? Is this sort of automatic linking of compositions across android view subtrees even something that would make sense? If yes, is the
AndroidView
wiring planned? https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/androidMain/kotlin/androidx/compose/ui/platform/ComposeView.kt;drc=a32c0003449e3ca6141ef497f0ee2759b41943ba;l=176
IIRC, at least a couple releases ago, for subcomposition to work the subcomposition had to be manually composed every time the
CompositionReference
was composed, and so if that’s still the case then this simple view tree mechanism lacks the ability to push those recompose events down and this wouldn’t work.
I’m asking because I work on a navigation library where we currently manually implement this sort of nested composition linking through our own, non-view-tag-based mechanism, and it works but it only works if the boundary between compose and android views is controlled by the library. This is a restriction I think we’re ok living with, but if this were something that Compose just supported automatically, it would be great for two reasons: we could delete a bunch of code, and it would work across any Compose/Android view boundaries, not just the ones we control.
a
hmm, yeah we could do that
🎉 2
l
thanks for the idea zach!
🙏 1
1
z
I think it should be pretty straightforward, i can try to get a CL up probably next week
a
oh I'm halfway through it now, I'm just writing a test for it
🎉 3
v
I only read Zach’s comments once (and maybe I should read it a few times) but if I understood this correctly, does this change enable the possibility of introducing a mechanism to propagate recompositions through AndroidView such that ComposeView -> AndroidView -> ComposeView hierarchies have “interlinked” compositions. Does this also come with any performance wins?
z
It doesn’t just enable the possibility of introducing such a mechanism, it is the mechanism.
😄 2
☝️ 1
z
great stuff! it's so cool to see such an interactive dev team/community relationship