You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Compose1.4.0+中ModalBottomSheetLayout滑动跳动问题及关闭方法问询

Compose 1.4.0+ ModalBottomSheetLayout滑动跳动问题的临时解决方案

在Compose 1.4.0及以上版本中,ModalBottomSheetLayout滑动时会出现跳动异常,1.4.0以下版本无此问题。已知该问题对应官方Issue编号为285847707,以下是几个临时解决思路:

代码复现

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val scope = rememberCoroutineScope()
            val sheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Hidden)
            ModalBottomSheetLayout(
                sheetState = sheetState,
                sheetContent = {
                    Text(
                        modifier = Modifier
                            .fillMaxWidth()
                            .height(200.dp),
                        text = "CONTENT"
                    )
                }
            ) {
                Button(onClick = { scope.launch { sheetState.show() } }) {
                    Text(text = "MODAL")
                }
            }
        }
    }
}

临时解决方案

  • 修改动画规格缓解跳动:自定义rememberModalBottomSheetState的animationSpec,使用无弹跳的线性动画替换默认带弹跳效果的动画,弱化跳动感:

    val sheetState = rememberModalBottomSheetState(
        initialValue = ModalBottomSheetValue.Hidden,
        animationSpec = tween<Float>(durationMillis = 300, easing = LinearEasing)
    )
    

    适合需要保留新版Compose特性的场景。

  • 回退到稳定版本:暂时将Compose依赖版本回退到1.3.3,直接规避该bug,等待官方修复。

  • 替换为第三方BottomSheet组件:使用成熟的第三方BottomSheet库替代官方ModalBottomSheetLayout,绕过该组件的bug问题。

内容的提问来源于stack exchange,提问作者admund

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 07:10:16