一、背景
在现有Android项目中使用Compose可能存在滑动冲突问题,例如
SmartRefreshLayout+CoordinatorLayout+ComposeView(ComposeView这里又是一个LazyColumn)
二、解决方案
官方介绍:https://developer.android.google.cn/develop/ui/compose/touch-input/pointer-input/scroll?hl=sk
如果基于以上原因出现滚动问题,可以在Compose中使用以下方式解决
- binding.composeConfigList.setContent {
- // fix滑动冲突问题
- val nestedScrollInterop = rememberNestedScrollInteropConnection()
- SettingConfig(settingConfig.value, showRedDot.value, nestedScrollInterop, configClick = {
- })
- }
- @Composable
- fun SettingConfig(
- data: List<ConfigData>,
- showRedDot: Boolean,
- nestedScrollInterop: NestedScrollConnection,
- configClick: (ConfigData) -> Unit
- ) {
- LazyColumn(modifier = Modifier.nestedScroll(nestedScrollInterop)) {
- items(data) {
- ItemConfig(it, showRedDot, configClick)
- }
- }
- }