Should `ModalBottomSheetLayout` collapses when bac...
# compose
n
Should
ModalBottomSheetLayout
collapses when back key is pressed? 🤔
I created this… not sure if there’s an easy way…
Copy code
@ExperimentalMaterialApi
@Composable
fun BottomSheetBackHandler(
    state: ModalBottomSheetState,
    doOnDismiss: (() -> Unit)? = null,
    content: @Composable () -> Unit,
) {
    val scope = rememberCoroutineScope()
    content()
    BackHandler(
        onBack = {
            scope.launch {
                state.hide()
                doOnDismiss?.invoke()
            }
        }
    )
}
i
In general, nothing in Compose relies on Activity APIs (such as those for reacting to the system back button). This would be something you get for free in the upcoming bottom sheet integration with Navigation Compose: https://github.com/androidx/androidx/pull/173
👍 1