KevinnZou/compose-webview-multiplatform

IOS 无法滚动页面内容

Matcha-xiaobin opened this issue · 2 comments

依赖版本:
compose = "1.7.0-alpha02"
kotlin = "2.0.10"
navigation = "2.8.0-alpha08"

我将main分支的webview模块手动依赖到了项目中,因为通过
implementation("io.github.kevinnzou:compose-webview-multiplatform:1.9.20")
这种方式依赖会导致ios崩溃

目前运行在 Ios 16.3.1 真机 出现了无法滑动页面内容,但是可以点击到页面上的元素,请问这有可能是什么原因导致的?
我之前几乎没有在Ios端运行过,所以我不太确定是不是之前也是这样。

我另外根据wasm分支的代码,添加了 wasm的代码,以下是我导入项目后的webview的build.gradle.kts:

@file:Suppress("UNUSED_VARIABLE", "OPT_IN_USAGE")

import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl


plugins {
    alias(libs.plugins.kotlinMultiplatform)
    alias(libs.plugins.androidLibrary)
    alias(libs.plugins.jetbrainsCompose)
    alias(libs.plugins.compose.compiler)
    alias(libs.plugins.serialization)
    alias(libs.plugins.ksp)
}

kotlin {
    targetHierarchy.default()

    @OptIn(ExperimentalWasmDsl::class)
    wasmJs {
        moduleName = "composeWebView"
        browser {
            commonWebpackConfig {
                outputFileName = "composeWebView.js"
            }
        }
        binaries.executable()
    }


    androidTarget()

    jvm("desktop")

    listOf(
        iosX64(),
        iosArm64(),
        iosSimulatorArm64(),
    ).forEach { iosTarget ->
        iosTarget.binaries.framework {
            baseName = "webview"
            isStatic = true
        }
        iosTarget.setUpiOSObserver()
    }

    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation(compose.runtime)
                implementation(compose.foundation)
                implementation(compose.material3)
                @OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
                implementation(compose.components.resources)
                implementation(libs.kotlinx.coroutines.core)
                implementation(libs.kotlinx.serialization.json)
                implementation(libs.kermit)
            }
        }
        val androidMain by getting {
            dependencies {
                implementation(libs.androidx.activity.compose)
                implementation(libs.androidx.webkit)
            }
        }
        val iosX64Main by getting
        val iosArm64Main by getting
        val iosSimulatorArm64Main by getting
        val iosMain by getting {
            dependsOn(commonMain)
            iosX64Main.dependsOn(this)
            iosArm64Main.dependsOn(this)
            iosSimulatorArm64Main.dependsOn(this)
        }
        val desktopMain by getting {
            dependencies {
                implementation(compose.desktop.common)
                api(libs.kcef)
                implementation(libs.kotlinx.coroutines.swing)
            }
        }
    }
}

android {

    namespace = "com.multiplatform.webview"
    compileSdk = libs.versions.android.compileSdk.get().toInt()
    defaultConfig {
        minSdk = libs.versions.android.minSdk.get().toInt()
    }

    sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
    sourceSets["main"].res.srcDirs("src/androidMain/res")
    sourceSets["main"].resources.srcDirs("src/commonMain/resources")

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
    kotlin {
        jvmToolchain(17)
    }
}

fun org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget.setUpiOSObserver() {
    val path = projectDir.resolve("src/nativeInterop/cinterop/observer")

    binaries.all {
        linkerOpts("-F $path")
        linkerOpts("-ObjC")
    }

    compilations.getByName("main") {
        cinterops.create("observer") {
            compilerOpts("-F $path")
        }
    }
}

已确认compose = "1.7.0-alpha02" 会破坏UIKitView 中webview 的滑动事件,1.6.11 及以下版本可以正常滑动.
请不要使用1.7.0 以上版本

comment

补充一点,1.7.0-alpha01 没有如上修改, 需要先降级到1.7.0-alpha01, 可选配置目前还未合并到master中
pull/1494