Skip to content

Instantly share code, notes, and snippets.

@EfeBudak
Last active August 9, 2024 16:30
Show Gist options
  • Save EfeBudak/4ab456f44509b0160858a875206ab0b7 to your computer and use it in GitHub Desktop.
Save EfeBudak/4ab456f44509b0160858a875206ab0b7 to your computer and use it in GitHub Desktop.
val bottomSheetState = rememberStandardBottomSheetState()
val scaffoldState = rememberBottomSheetScaffoldState(bottomSheetState)
BottomSheetScaffold(
modifier = Modifier.fillMaxSize(),
scaffoldState = scaffoldState,
sheetContainerColor = Color.Transparent,
sheetContent = {
// Put whatever the sheet you want in here
}
) { innerPadding ->
Box(
modifier = Modifier
.fillMaxSize()
.padding(innerPadding)
) {
var composableHeight by remember { mutableStateOf(0) } // the height I mentioned
Box(
modifier = Modifier
.fillMaxWidth()
// `.padding(16.dp)` is messing with the `.offset`. Use it after the `.offset` call
.onSizeChanged { composableHeight = it.height } // Dear Modifier, thanks for having such a good function
.offset {
IntOffset(
x = 0,
y = bottomSheetState.requireOffset().roundToInt() - composableHeight, // these values represent pixels
)
}
.padding(16.dp)
) {
FloatingActionButton(
modifier = Modifier.align(Alignment.CenterEnd),
onClick = { /*TODO*/ }
) {
Image(
painter = painterResource(id = R.drawable.ic_launcher_foreground),
contentDescription = null
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment