Thread
#compose
    Alex

    Alex

    11 months ago
    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
    raenardev

    raenardev

    11 months ago
    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)
    Alex

    Alex

    11 months ago
    Brillant, cheers!
    Adam Powell

    Adam Powell

    11 months ago
    Why do you want this?
    Alex

    Alex

    11 months ago
    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)
    Adam Powell

    Adam Powell

    11 months ago
    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.
    Alex

    Alex

    11 months ago
    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.
    Adam Powell

    Adam Powell

    11 months ago
    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.