You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My use case is relatively simple: I would like to get a bottom sheet that jumps to a specific height based on the content on the screen. However, that content can be dynamic, so I would like the seet size to be dynamic as well.
Take this example:
@Composable
funTestScreen(accountId:AccountId) {
// make a big boxBox(Modifier.fillMaxSize().safeContentPadding().background(Color.Gray)) {
// measured size of the contentvar contentSize by remember { mutableStateOf(IntSize.Zero) }
// measured height is derived from the sizeval contentHeight =with(LocalDensity.current) { contentSize.height.toDp() }
// draw a box that grows by 100.dp every time it's clickedvar height by remember { mutableStateOf(100.dp) }
Box(
Modifier
.height(height)
.fillMaxWidth()
.background(Color.Red)
.clickable { height +=100.dp }
// measure size of the box
.onSizeChanged { contentSize = it }) {}
// create detents// peek should be 50.dp below the box aboveval peek =SheetDetent(identifier ="peek") { containerHeight, _ ->// contentHeight is captured here, but because rememberBottomSheetState remembers it from the first time// the scrim was created, it's not updatedprintln("calling peek with content height: $contentHeight")
containerHeight - contentHeight -50.dp
}
// fullscreen should go above the box to 90% of the content sizeval fullScreen =SheetDetent(identifier ="fullscreen") { containerHeight, _ ->
containerHeight *0.9f
}
// make sheetval sheetState = rememberBottomSheetState(
detents =listOf(peek, fullScreen),
initialDetent = peek,
)
BottomSheet(
state = sheetState,
modifier =Modifier.fillMaxWidth().background(Color.White),
) {
Column(
modifier =Modifier.fillMaxWidth(),
horizontalAlignment =Alignment.CenterHorizontally,
) {
DragIndication(
Modifier
.padding(top =22.dp)
.background(Color.Black.copy(0.4f), RoundedCornerShape(100))
.width(32.dp)
.height(4.dp)
)
LazyColumn {
repeat(50) {
item { Text("Item #${(it +1)}", modifier =Modifier.padding(10.dp)) }
}
}
}
}
}
}
The problem is that when I specify detents, their lambdas capture values during the first run and won't re-trigger afterwards. It would be nice if it was possible to force the sheetState to recalculate on specific keys, in this case e.g. contentHeight.
I would have implemented my own rememberBottomSheetState, but since the SheetState constructor is internal, I can't.
The text was updated successfully, but these errors were encountered:
My use case is relatively simple: I would like to get a bottom sheet that jumps to a specific height based on the content on the screen. However, that content can be dynamic, so I would like the seet size to be dynamic as well.
Take this example:
The problem is that when I specify detents, their lambdas capture values during the first run and won't re-trigger afterwards. It would be nice if it was possible to force the sheetState to recalculate on specific keys, in this case e.g. contentHeight.
I would have implemented my own
rememberBottomSheetState
, but since the SheetState constructor is internal, I can't.The text was updated successfully, but these errors were encountered: