Coordinating ViewCompositionStrategy across nested ComposeView and AndroidView boundaries
0 reputation · 09 Sept 2021, 09:08 UTC
When a ComposeView embedded in an XML layout hosts an AndroidView that itself renders a Compose subtree via a nested ComposeView, the two composition boundaries each require a ViewCompositionStrategy. The outer ComposeView typically uses DisposeOnViewTreeLifecycleDestroyed to survive configuration changes, while the inner ComposeView may need DisposeOnDetachedFromWindow to avoid leaking when the AndroidView is recycled in a RecyclerView.
The documentation does not specify how these strategies interact when the inner composition is created from within an AndroidView factory lambda. It is unclear whether the inner ComposeView inherits the outer ViewTreeLifecycleOwner, whether detachment of the AndroidView triggers disposal of the inner composition before the outer one, or whether a mismatch can leave a composition attached to a destroyed window.
What is the expected disposal order when the AndroidView is detached but the outer ComposeView remains attached? Does the inner ComposeView automatically adopt the outer ViewTreeLifecycleOwner, or must it be explicitly scoped? Can a single ViewCompositionStrategy be configured to handle both boundaries safely?