voize-gmbh / reakt-native-toolkit

Combine React Native with Kotlin Multiplatform (KMP)
Apache License 2.0
134 stars 5 forks source link

Update Kotlin to 2.0.21 #77

Closed erksch closed 1 month ago

erksch commented 1 month ago

Currently using the Toolkit with Kotlin 2.0.21 creates errors like

on iOS

> Task :shared:compileKotlinIosArm64
e: file:///.../build/generated/ksp/iosArm64/iosArm64Main/kotlin/.../TestModuleRNModuleProvider.kt:9:23 'fun getModule(lifecycleScope: CoroutineScope): TestModuleRNModuleIOS' has no corresponding expected declaration
The following declaration is incompatible because return type is different:
    fun getModule(lifecycleScope: CoroutineScope): RCTBridgeModuleProtocol

on Android

> Task :shared:compileDebugKotlinAndroid FAILED
e: file:///.../build/generated/ksp/android/androidDebug/kotlin/.../TestModuleRNModuleProvider.kt:10:23 'fun getModule(reactApplicationContext: ReactApplicationContext, lifecycleScope: CoroutineScope): TestModuleRNModuleAndroid' has no corresponding expected declaration
The following declaration is incompatible because return type is different:
    fun getModule(reactApplicationContext: ReactApplicationContext, lifecycleScope: CoroutineScope): ReactNativeModuleBase

The provider platform implementation currently return the RNModule directly, the interface declares ReactNativeModuleBase on Android and RCTBridgeModuleProtocol on iOS. To fix this we drop the type narrowing in the implementation and return ReactNativeModuleBase and RCTBridgeModuleProtocol in the implementation, too.

Before

// build/generated/ksp/iosArm64/iosArm64Main/kotlin/.../TestModuleRNModuleProvider.kt

public actual class TestModuleRNModuleProvider actual constructor(...) : ReactNativeModuleProvider {
  override fun getModule(lifecycleScope: CoroutineScope): TestModuleRNModuleIOS =
      TestModuleRNModuleIOS(lifecycleScope, ...)
}
// /build/generated/ksp/android/androidDebug/kotlin/.../TestModuleRNModuleProvider.kt

public actual class TestModuleRNModuleProvider actual constructor() : ReactNativeModuleProvider {
  override fun getModule(reactApplicationContext: ReactApplicationContext,
      lifecycleScope: CoroutineScope): TestModuleRNModuleAndroid =
      E2ETestAndroid(reactApplicationContext, lifecycleScope)
}

After

// build/generated/ksp/iosArm64/iosArm64Main/kotlin/.../TestModuleRNModuleProvider.kt

public actual class TestModuleRNModuleProvider actual constructor(...) : ReactNativeModuleProvider {
  override fun getModule(lifecycleScope: CoroutineScope): RCTBridgeModuleProtocol =
      TestModuleRNModuleIOS(lifecycleScope, ...)
}
// /build/generated/ksp/android/androidDebug/kotlin/.../TestModuleRNModuleProvider.kt

public actual class TestModuleRNModuleProvider actual constructor() : ReactNativeModuleProvider {
  override fun getModule(reactApplicationContext: ReactApplicationContext,
      lifecycleScope: CoroutineScope): ReactNativeModuleBase =
      E2ETestAndroid(reactApplicationContext, lifecycleScope)
}