What is the right way to get a callback when a `Mo...
# compose
b
What is the right way to get a callback when a
ModalBottomSheetLayout
is dismissed, either from accessibility actions or from tapping on the scrim outside the sheet? Drop a
DisposableEffect
inside the sheet’s content? I don’t see any sort of callback or observable state.
k
👍 1
b
I like the LaunchedEfffect approach- that would support getting a callback for half expanded and fully expanded states as well. Both that and DisposableEffect feel a little weird, but that might just be me getting used to the declarative UI paradigm
m
the closure of the ModalSheet is an event you can observe. If you want to trigger a side effect when happens (which is why you are reaching out for a callback probably, right?) you can do it via DisposableEffect or LaunchedEffect, if you need a scope:
Copy code
val state = rememberModalBottomsheetState(BottmsheetValue.Expanded)
DisposableEffect(state.isClosed) {
    //this is called when state.isClosed changed during last composition, so you can trigger a side effect when you want (true or false)
    onDispose { /* cleanup here */}
}

ModalBottomSheetLayout(state, ....)
💯 1
b
Thanks! A side effect is exactly what I’m thinking, for example sending analytics events.
m
So this tools will suit your case perfectly then 🙂
👌 2
👍 1