gpt4 book ai didi

android - 如何在撰写中使用 BottomSheetScaffold 为 bottomsheet 设置半展开高度?

转载 作者:行者123 更新时间:2023-12-05 03:17:39 24 4
gpt4 key购买 nike

我需要先在折叠状态下显示底页。在向上滑动 bottomsheet 时,它应该首先固定在屏幕的一半高度。再次向上滑动,它应该扩展到屏幕的最大高度。崩溃时也一样。首先从最大高度到一半高度,然后是窥视高度(在折叠状态下可见的底片高度)。有什么方法可以使用 BottomSheetScaffold 来实现吗?

最佳答案

我开始为您编写解决方案。你可以美化它

enum class ExpandedType {
HALF, FULL, COLLAPSED
}

@Composable
private fun BottomSheet() {
val configuration = LocalConfiguration.current
val screenHeight = configuration.screenHeightDp
var expandedType by remember {
mutableStateOf(ExpandedType.COLLAPSED)
}
val height by animateIntAsState(
when (expandedType) {
ExpandedType.HALF -> screenHeight / 2
ExpandedType.FULL -> screenHeight
ExpandedType.COLLAPSED -> 70
}
)
val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(
bottomSheetState = BottomSheetState(BottomSheetValue.Collapsed)
)
BottomSheetScaffold(
scaffoldState = bottomSheetScaffoldState,
sheetElevation = 8.dp,
sheetShape = RoundedCornerShape(
bottomStart = 0.dp,
bottomEnd = 0.dp,
topStart = 12.dp,
topEnd = 12.dp
),
sheetContent = {
var isUpdated = false
Box(
Modifier
.fillMaxWidth()
.height(height.dp)
.pointerInput(Unit) {
detectVerticalDragGestures(
onVerticalDrag = { change, dragAmount ->
change.consume()
if (!isUpdated) {
expandedType = when {
dragAmount < 0 && expandedType == ExpandedType.COLLAPSED -> {
ExpandedType.HALF
}
dragAmount < 0 && expandedType == ExpandedType.HALF -> {
ExpandedType.FULL
}
dragAmount > 0 && expandedType == ExpandedType.FULL -> {
ExpandedType.HALF
}
dragAmount > 0 && expandedType == ExpandedType.HALF -> {
ExpandedType.COLLAPSED
}
else -> {
ExpandedType.FULL
}
}
isUpdated = true
}
},
onDragEnd = {
isUpdated = false
}
)
}
.background(Color.Red)
)
},
sheetPeekHeight = height.dp
) {
Box(
Modifier
.fillMaxSize()
.background(Color.Black)
)
}
}

关于android - 如何在撰写中使用 BottomSheetScaffold 为 bottomsheet 设置半展开高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74041429/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com