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
matvei
03/02/2021, 7:00 PM
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
Bryan Herbst
03/02/2021, 7:01 PM
Thanks! A side effect is exactly what I’m thinking, for example sending analytics events.
m
matvei
03/02/2021, 7:01 PM
So this tools will suit your case perfectly then 🙂