Skip to content

Instantly share code, notes, and snippets.

@RudraOp9
Created April 11, 2024 04:11
Show Gist options
  • Select an option

  • Save RudraOp9/d51d330fddc6bdb61ede80e4bf4da4f4 to your computer and use it in GitHub Desktop.

Select an option

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.
@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