Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The onCancel event in Jetpack Compose's ModalBottomSheetLayout is handled by specifying a callback function using the onDismissRequest parameter.

The onDismissRequest parameter takes a function that will be called when the user dismisses the bottom sheet by tapping outside of it or by swiping it down. The function takes no arguments and returns no values.

Here is an example of how to handle the onCancel event:

ModalBottomSheetLayout(
    sheetState = bottomSheetState,
    sheetContent = { /* Sheet content */ },
    sheetShape = RoundedCornerShape(16.dp),
    sheetElevation = 8.dp,
    sheetBackgroundColor = Color.White,
    scrimColor = Color.Black.copy(alpha = 0.5f),
    sheetContentColor = LocalContentColor.current,
    sheetContentAlpha = 1f,
    sheetAnimationMode = BottomSheetAnimationMode.Slide,
    onDismissRequest = { 
        /* Handle onCancel event */ 
    }
) {
    /* Screen content */
}

In this example, the onDismissRequest parameter is set to a lambda function that will handle the onCancel event. The function can perform any required actions, such as updating the state of the bottom sheet or performing some other action.