Add TurboModule and CodegenNativeComponent bindings for React Native New Architecture by ricku44 · Pull Request #840 · rescript-react-native/rescript-react-native
hi @Freddy03h,
Thanks for reviewing the PR. Let me give you more insights.
This PR introduces ReScript support for React Native's codegen system. Currently, React Native codegen works by parsing TypeScript or Flow files using respective AST parsers (like react-native-codegen/src/parsers/flow) and converting them to a standardized Flow AST representation for native code generation. The system has strict prerequisites including TurboModule extension, proper module registration patterns, and HostComponent checks that must be satisfied for successful codegen.
I've implemented a Flow-like AST parser for ReScript that translates ReScript syntax into the same Flow AST format that the existing codegen pipeline expects. This allows developers to write native module and component specifications in ReScript while maintaining full compatibility with the existing codegen infrastructure.
Could you please review the implementation and suggest any improvements? I'm particularly interested in feedback on the best Rescript syntax for this for AST transformation logic and whether the ReScript-to-Flow AST mapping aligns well with the existing codegen expectations.
NativeTurboModule.res
open ReactNative open TurboModule type spec = { ...turboModule, initialise: ((option<string>, option<string>) => unit) => unit, getSession: ( Js.Dict.t<string>, Js.Dict.t<string>, array<Js.Json.t>, (option<string>, option<string>) => unit, ) => unit, exit: string => unit, } let hyperHeadlessModule: get<spec> = get("HyperHeadlessModule")
NativeButtonComponent.res
open ReactNative open CodegenNativeComponent module NativeButton = { type props = { ...View.viewProps, title: string, color?: string, } let make: nativeComponentType<props> = codegenNativeComponent("NativeButton", ~options=makeOptions(~interfaceOnly=true, ())) }