Support React Native 0.83.x New Architecture on iOS via Interop Layer#126
Open
DGuang21 wants to merge 5 commits intovoize-gmbh:mainfrom
Open
Support React Native 0.83.x New Architecture on iOS via Interop Layer#126DGuang21 wants to merge 5 commits intovoize-gmbh:mainfrom
DGuang21 wants to merge 5 commits intovoize-gmbh:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
👋 Hi there! Our team is also implementing a solution that integrates Kotlin Multiplatform with React Native. Although our usage is slightly different (we embed RN pages within KMP), the core challenge remains the same: enabling React Native to invoke KMP code effectively.
We experimented with generating KMP interfaces based on the objects declared by the New Architecture, but found the process to be overly complex. Furthermore, React Native 0.83.1 (New Architecture) still retains support for legacy Modules. After extensive testing, we discovered that on Android, the bridge code generated by reakt-native-toolkit works directly even under the New Architecture. However, the implementation on iOS differs, causing it to fail in automatically locating the legacy Modules.
To address this, we implemented hack to ensure compatibility with React Native 0.83.1. The primary goal of this PR is to resolve the visibility issue within the iOS Interop Layer for RN 0.83.1.
Usage Changes
The logic is straightforward. If you are using the New Architecture or React Native 0.83.x and above, you can configure the following in build.gradle.kts:
How it works
After executing the code generation task, Swift code compatible with the Interop Layer pattern will be generated in: build/generated/ksp/metadata/commonMain/resources/reaktNativeToolkit/iosNewArch
This directory will contain:
Swift files corresponding to the Module Namespaces.
RCTBridgeModule.m and Types.swift.
Installation Step
You simply need to go to your iosApp in Xcode:
Right-click and select Add files to "xxx".
Select the folder build/generated/ksp/metadata/commonMain/resources/reaktNativeToolkit/iOSInteropLayer.
Choose "Create folder references" (Reference files in place).
Stability & Compatibility
Aside from this step, no other manual handling is required. The bridge code generation, TS bridges, and direct references work as usual. We have also added compatibility for Flow.
We have tested and confirmed the stability of all solutions, with the exception of the Flow type. The app we maintain is open source, and you can verify the relevant references and implementations there. Our App
Generated Code Examples
Closing
We welcome any suggestions for modifications, improvements, or optimizations. I would also like to extend my sincerest gratitude to everyone here—it is your work that expands the possibilities for both React Native and Kotlin Multiplatform! 🚀