Gas*_*lén 5 android kotlin android-jetpack-compose
所以我正在使用ModalBottomSheet,它引起我的注意的是,sheetState 有 2 个公共方法,show()文档中hide()说show()
/**
* Show the bottom sheet with animation and suspend until it's shown. If the sheet is taller
* than 50% of the parent's height, 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 = when {
hasHalfExpandedState -> HalfExpanded
else -> Expanded
}
animateTo(targetValue = targetValue)
}
Run Code Online (Sandbox Code Playgroud)
但有一个问题,如果我们只是使用,.show()有时sheetState我们会得到半滚动的底部工作表,这会导致与我当前的 UI 不一致
深入研究该文件后,我发现我们有一个expand()内部方法,正是我所需要的
/**
* Fully expand the bottom sheet with animation and suspend until it if fully expanded or
* animation has been cancelled.
* *
* @throws [CancellationException] if the animation is interrupted
*/
internal suspend fun expand() = animateTo(Expanded)
Run Code Online (Sandbox Code Playgroud)
但这恰好是内部的,无法从外部访问
有没有办法用 执行该状态sheetState?
小智 7
skipHalfExpanded已被添加到1.2.0 的ModalBottomSheetState构造函数中。这将确保调用始终显示展开状态。show()
val modalBottomSheetState = rememberModalBottomSheetState(
initialValue = ModalBottomSheetValue.Hidden,
skipHalfExpanded = true
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2560 次 |
| 最近记录: |