voize-gmbh / reakt-native-toolkit

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

Generate wrappers for ReactNativeFlows that properly serialize complex parameters #31

Closed erksch closed 1 year ago

erksch commented 1 year ago
@ReactNativeModule("MyRNModule")
class MyRnModule() {
  @ReactNativeFlow
  fun myFlow(myParam: List<String>): Flow<Int> = ...
}

Before

interface MyRNModuleInterface {
  myFlow: Next1<number, string[]>;
}

const MyRNModule: MyRNModuleInterface = {
  ...NativeModules.MyRnModule 
  // no wrappers for myFlow
}

After

const MyRNModule: MyRNModuleInterface = {
  ...NativeModules.MyRNModule,
  myFlow: (currentValue: string | null, arg: string[]) => NativeModules.MyRNModule.myFlow(
     currentValue, 
     JSON.stringify(arg)
  ),
}
erksch commented 1 year ago

I am releasing this as a patch release. Because it does not break existing primitive argument flows and fixes broken complex flows.