https://kotlinlang.org logo
#compose
Title
# compose
n

nuhkoca

05/16/2022, 10:40 AM
Hello, I need to check whether bottom sheet is dismissed or shown and have a code below for two cases. However, dismiss case is also triggered when user selects something and then bottom sheet closes. I don’t want my
onSortingSheetStateChanged(SortSheetState.Dismissed)
to be triggered for that case but only if user presses back button or touches outside. BTW is there any better way to handle these cases?
Copy code
if (sortingBottomSheetState.currentValue != ModalBottomSheetValue.Hidden) {
    DisposableEffect(Unit) {
        onSortingSheetStateChanged(SortSheetState.Shown)
        onDispose {
            onSortingSheetStateChanged(SortSheetState.Dismissed)
        }
    }
}
c

Chris Fillmore

05/19/2022, 9:19 PM
At a minimum to handle the back button, you could use
BackHandler
Overall, using bottom sheet state to trigger behaviour sounds like a bad idea. Can you trigger things another way? Such as “user selects something”, to use your example?
3 Views