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

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 04:40:09