Created
April 11, 2024 04:11
-
-
Save RudraOp9/d51d330fddc6bdb61ede80e4bf4da4f4 to your computer and use it in GitHub Desktop.
How to make an ModalBottomSheet uplifted in Compose ? an uplifted bottom sheet looks good as compared to default one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @OptIn(ExperimentalMaterial3Api::class) | |
| @Composable | |
| fun Parent() { | |
| var boo by rememberSaveable { | |
| mutableStateOf(false) | |
| } | |
| Button(onClick = { boo = true }) { | |
| Text(text = "Click to see") | |
| } | |
| AnimatedVisibility( | |
| visible = boo, | |
| enter = fadeIn(animationSpec = tween(800)), | |
| exit = fadeOut(animationSpec = tween(500)) | |
| ) { // this will make an custom scrim effect when the sheet is shown or hide | |
| Box( | |
| modifier = Modifier | |
| .fillMaxSize() | |
| .background(Color.DarkGray.copy(alpha = 0.4f)) | |
| ) | |
| } | |
| if (boo) { | |
| BottomSheetHome() { | |
| boo = false | |
| } | |
| } | |
| } | |
| @OptIn(ExperimentalMaterial3Api::class) | |
| @Composable | |
| fun BottomSheetHome(handleBoo: () -> Unit) { | |
| ModalBottomSheet( | |
| scrimColor = Color.Transparent, // Making default scrim Transparent. | |
| containerColor = Color.DarkGray, // Customization | |
| contentColor = Color.LightGray, | |
| modifier = Modifier | |
| .padding(start = 20.dp, end = 20.dp), | |
| shape = RoundedCornerShape(10.dp), | |
| dragHandle = { | |
| BottomSheetDefaults.DragHandle(color = Color.LightGray) | |
| }, | |
| windowInsets = WindowInsets(bottom = 40), // This will lift the sheet by 40 . | |
| onDismissRequest = handleBoo | |
| ) { | |
| // Your layout here | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment