Compose Multiplatform升级后iOS UIScrollView中Composable视图无法滚动
Compose Multiplatform 1.7.3 iOS端UIScrollView与Composable手势冲突问题
我在Compose Multiplatform项目中将Composable视图嵌入iOS的UIScrollView,原本预期实现流畅滚动交互。该配置在org.jetbrains.compose插件1.6.10版本下运行正常,但升级到最新的1.7.3版本后,从Composable视图区域触发滚动时,iOS端的UIScrollView完全无响应,Android端滚动功能正常。推测是Composable视图的手势处理与UIScrollView的滚动手势存在冲突,未出现任何报错信息。
相关代码
ContentView.Swift
import SwiftUI import candlestickchart struct ContentView: View { var body: some View { ScrollView { Rectangle().fill(Color.red).frame(maxWidth: .infinity).frame(height: 300) ComposeView().frame(maxWidth: .infinity).frame(height: 300) Rectangle().fill(Color.red).frame(maxWidth: .infinity).frame(height: 300) } } } struct ComposeView: UIViewRepresentable { func makeUIView(context: Context) -> UIView { return MainKt.MainView().view } func updateUIView(_ uiView: UIView, context: Context) {} }
iOS Main.kt
fun MainView() = ComposeUIViewController(configure = { enforceStrictPlistSanityCheck = false }) { TestComposable() }
TestComposable.kt
@Composable fun TestComposable() { Box( modifier = Modifier.background(Color.Cyan).fillMaxWidth() .height(350.dp) ) }
MainActivity.kt
class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { Column(modifier = Modifier .verticalScroll(rememberScrollState()) .fillMaxWidth() .wrapContentHeight()) { Box( modifier = Modifier .background(Color.Red) .fillMaxWidth() .height(350.dp) ) TestComposable() Box( modifier = Modifier .background(Color.Red) .fillMaxWidth() .height(350.dp) ) } } } }
滚动表现
- iOS端:点击Composable视图区域(青色部分)无法触发UIScrollView滚动,点击红色矩形区域可正常滚动
- Android端:所有区域均可正常触发滚动
内容的提问来源于stack exchange,提问作者Yash Kalariya
相关产品推荐
相关产品推荐

