Colton Idle
08/21/2021, 6:10 AMColton Idle
08/21/2021, 6:11 AMColumn(
verticalArrangement = <http://Arrangement.Top|Arrangement.Top>,
modifier = Modifier.fillMaxSize().padding(horizontal = 16.dp),
) {
Text(
"My Bottom Sheet",
color = Color(0xFF073042),
style = MaterialTheme.typography.h2,
modifier =
Modifier.align(Alignment.CenterHorizontally)
.padding(vertical = 16.dp)
)
Colton Idle
08/21/2021, 6:12 AMColumn(
verticalArrangement = <http://Arrangement.Top|Arrangement.Top>,
modifier = Modifier.fillMaxSize().padding(horizontal = 16.dp),
) {
val contentPadding =
rememberInsetsPaddingValues(
insets = LocalWindowInsets.current.systemBars,
applyTop = true,
applyBottom = true,
)
val padding by animateDpAsState(
if (bottomSheetNavigator.navigatorSheetState.offset.value < 120F) {
contentPadding.calculateTopPadding()
} else {
0.dp
})
Text(
"My Bottom Sheet",
color = Color(0xFF073042),
style = MaterialTheme.typography.h2,
modifier =
Modifier.align(Alignment.CenterHorizontally)
.padding(vertical = 16.dp)
.padding(top = padding)
)
but I'm mostly just guessing at some values here and it looks... "okay" according to my designer, but she is asking if I can smoothe it out.
Anyone have suggestions?Colton Idle
08/21/2021, 6:14 AMms
08/21/2021, 6:21 AMColton Idle
08/21/2021, 6:27 AMjossiwolf
08/21/2021, 9:06 AMColton Idle
08/21/2021, 4:23 PMColton Idle
08/21/2021, 4:34 PMjossiwolf
08/21/2021, 6:19 PMColton Idle
08/23/2021, 1:33 AMColton Idle
08/23/2021, 1:33 AMColton Idle
08/23/2021, 1:38 AMbottomSheet(route = "sheet") {
//Need this to find the height of the screen
BoxWithConstraints(Modifier.fillMaxHeight()) {
// Get status bar height
val statusBarHeight = rememberInsetsPaddingValues(
LocalWindowInsets.current.statusBars,
applyTop = true
)
val boxWithConstraintsScope = this
//Top padding of the bottom sheet is dynamic and is derived from:
val padding =
derivedStateOf {
val percentageOpen =
(((bottomSheetNavigator.navigatorSheetState.offset.value) / (boxWithConstraintsScope.maxHeight.value / 0.8)) - 1.0).absoluteValue
statusBarHeight.calculateTopPadding().value.times(
percentageOpen
)
}
Text(
modifier = Modifier
.padding(vertical = padding.value.dp)
.background(Color.Magenta),
text = "We did it!",
style = MaterialTheme.typography.h5
)
}
}
Doing math with dp's seems a little weird and error prone potentially? Not sure if I'm using the right conversions (maybe @Doris Liu can take a look), but it seems to work pretty much as I want it. The only "magic" value is the 0.8 (which I hope I could actually get the height of the half-expanded bottom sheet (even with a BoxWithConstraints) but a bottom sheet seems to always report it's total expanded height.