React 0.68+ Turbo Module starter using codegen with typescript for Objective-C and Java/Kotlin with C++ shared library. 🚀🚀🚀
.podspec
file, the version of folly has to be exactly the same as the react-native's versionndk.dir=/Users/{USER}/Library/Android/sdk/ndk/24.0.8215888
yarn bootstrap
yarn ios
yarn android
src/NativeTurboStarter.ts
src/index.ts
and export your new function via a wrapperApp.tsx
to test that it worksRCT_NEW_ARCH_ENABLED=1 pod install
in example/ios
folderxed ios
to open to workspace, and on the left side-bar navigate to Pods -> Development Pods -> react-native-turbo-starter -> ios -> TurboStarter.mm
and next to the @implementation
XCode will offer to complete the missing protocol for youTurboStarter.mm
and implement the new function by yourself.example/ios/build/generated/ios/TurboStarter
./gradlew generateCodegenArtifactsFromSchema
in example/androidandroid/src/main/java/com/reactnativeturbostarter/TurboStarterModule.kt
and let android studio complete the missing new function for youTurboStarterModule.kt
and implement it by yourselfandroid/build/generated/source/codegen
Now you can re-run the example project and watch as your code runs with JSI!
Follow the steps above, but consider the following:
cpp/react-native-turbo-starter.h
cpp/react-native-turbo-starter.cpp
- (NSNumber *) turboMultiply:(double)num1 num2:(double)num2{
double res = turbostarter::multiply(num1, num2);
return [NSNumber numberWithDouble:res];
}
TurboStarterModule.kt
you will need to declare your native JNI functionprivate external fun nativeMultiply(num1: Double, num2: Double): Double
override fun turboMultiply(num1: Double, num2: Double): Double {
return nativeMultiply(num1, num2)
}
android/src/main/jni/cpp-adapter.cpp
you will need to add the JNI function that wraps around the C++ functionextern "C" JNIEXPORT jdouble JNICALL
Java_com_reactnativeturbostarter_TurboStarterModule_nativeMultiply(JNIEnv *env, jclass type, jdouble num1, jdouble num2)
{
return turbostarter::multiply(num1, num2);
}
It's all nice but how do we know this is actually not using the bridge anymore? To see that we enabled JSI correctly, you can log out everything that is passing through the bridge and see that it's now clean (besides some data from metro-bundler)
in App.tsx
Add import MessageQueue from 'react-native/Libraries/BatchedBridge/MessageQueue.js';
const spyFunction = (msg) => {
console.log(msg);
};
MessageQueue.spy(spyFunction);
react-native-turbo-starter
react-native-turbo-starter
rm -rf .git
starter
word (script in the future)git init
git remote add origin <new repo url>
git add .
git commit -m "Initial Commit"
git push -u origin main
Nagish makes communication more accessible to all.
We believe that people who are Deaf or Hard-of-Hearing deserve to communicate on their own, without relying on anyone else.
We're always looking for talented humans who are interested in building the future of accessible communication with us.
If you like this project and want to work on similar tech click below
https://talknagish.com/careers
MIT