gpt4 book ai didi

android - 使 ModalBottomSheetLayout 始终展开

转载 作者:行者123 更新时间:2023-12-04 23:37:14 29 4
gpt4 key购买 nike

我正在使用 ModalBottomSheetLayout在 Jetpack Compose 中。每当它显示为 modalBottomSheetState.show() ,它显示 HalfExpandedExpanded取决于其内容的高度。这是来自源代码:

val anchors = if (sheetHeight < fullHeight / 2) {
mapOf(
fullHeight to Hidden,
fullHeight - sheetHeight to Expanded
)
} else {
mapOf(
fullHeight to Hidden,
fullHeight / 2 to HalfExpanded,
max(0f, fullHeight - sheetHeight) to Expanded
)
}
Modifier.swipeable(
state = sheetState,
anchors = anchors,
orientation = Orientation.Vertical,
enabled = sheetState.currentValue != Hidden,
resistance = null
)
然后 show()像这里一样工作:
 internal val isHalfExpandedEnabled: Boolean
get() = anchors.values.contains(HalfExpanded)

/**
* Show the bottom sheet with animation and suspend until it's shown. If half expand is
* enabled, the bottom sheet will be half expanded. Otherwise it will be fully expanded.
*
* @throws [CancellationException] if the animation is interrupted
*/
suspend fun show() {
val targetValue =
if (isHalfExpandedEnabled) HalfExpanded
else Expanded
animateTo(targetValue = targetValue)
}
我想知道我们是否可以将其设置为始终 Expanded不知何故

最佳答案

您可以使用:

scope.launch { state.animateTo(ModalBottomSheetValue.Expanded) }
代替
scope.launch { state.show() }

关于android - 使 ModalBottomSheetLayout 始终展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68890357/

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