Suppose I am using a `ComposeView` to show a compo...
# compose
a
Suppose I am using a
ComposeView
to show a composable. Is there a way for the
ComposeView
to receive a callback when the content is recomposed?
Receiving a callback when the content of the
ComposeView
is being redrawn would also work
r
I think you can use
SideEffect
in your top composable function inside ComposeView for that.
Schedule 
effect
 to run when the current composition completes successfully and applies changes.
https://developer.android.com/reference/kotlin/androidx/compose/runtime/package-summary#SideEffect(kotlin.Function0)
a
Brillant, cheers!
a
Why do you want this?
a
We have a blurring feature, implemented for Android < 12 as a custom view
I need to rell the blurring custom view when it should invalidate itself (e.g. when its content has changed in compose)
a
SideEffect won't be enough for you then as it only runs if that specific call to SideEffect was recomposed. Layout and drawing frequently change without recomposing.
a
Hm, what would be a way to achieve it in compose then? We managed it inside of the custom blurring view now, skipping compose for that.
a
This is all going to be lower level than compose for your purposes. ViewTreeObserver callbacks are likely to be the closest thing you can rely on from public API since compose UI will use multiple views internally; there's no single view you can extend or add callbacks to that would give you a complete picture or be guaranteed not to change view tree structure in a future update.
If you'd like to file a feature request describing the use case we can track it but it's not likely to be prioritized highly when ranked against other pending work to support other view integration features.