-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TurboModules (NativeModules Re-architecture) #40
Comments
This comment has been minimized.
This comment has been minimized.
@empyrical, this isn’t related to turbomodules, but rather one of the other projects I’m working on. This won’t need to be lazy because requireNativeComponent won’t exist and the only work that will be done is returning the string “RCTView”. There will be no round trips to native so it won’t provide value to make this async. |
Does this proposal (and related parts such as JSI) mean C++ native modules will become a first class, documented citizen of the RN universe? That would be awesome, I’m doing a lot of work in this area and most of it had to be figured out by reverse engineering/trial and error. |
Depends on what you meant by first class citizen. You can already build C++ class that talks directly to the VM via JSI's An example consumer is https://github.com/facebook/react-native/blob/94d49e544d10d0039a1178dc97533e96a4354198/ReactCommon/fabric/uimanager/UIManagerBinding.h We plan to build a thin C++ wrapper on top of this direct access to HostObject to make the binding slightly easier in the future, but the first focus will be ObjC/Java modules. Documentation will come when they are all ready and stable. So yes, C++ modules will become first class in this angle. |
This is really interesting, thanks for the pointers. So far we've been working with Will have a proper look into it when time allows, we are doing some pretty interesting stuff with C++/React Native integration which pushes it fairly hard and could make a good test case for some of this stuff, so if you'd be interested in discussing in more detail please feel free to get in touch (details in Github bio)! |
@fkgozali Do you mean in the current version of react native we can already build and register C++ classes using jsi's HostObject to the VM? Are there any examples of this? I'm particularly unclear on where the registration would occur -- from outside of RN core. |
Yeah same question here - would be nice to know the recommended way to register a C++ JSI module |
Yes. We're working on a cleaner abstraction, but at the moment you can try something like this at your own:
Expect more documentation when TurboModule is ready to use. We moved a bunch of code for iOS already to github, Android coming soon, but sample code will be provided at later time. |
Thanks very much - I was looking at this today but it would have taken me a while to figure that out :) I noticed the Turbomodules stuff in github - seems to be adding a new layer of abstraction for this stuff? Would you say it’s better to develop against what is in master than what is in the RC branch if we want to have more of a chance of keeping close to the final API? |
That's correct. It's abstraction for crossing C++-->ObjC and C++-->Java. You don't need it if you want to stay in pure C++ via
Nothing in master/RC is ready to use, but you can get the idea about where we're headed. If you for some reason needs to play with |
@fkgozali I wonder if you'd be able to advise me a little further on the Android side of this? I was able to get it up and running on iOS without too much trouble and it seems great, but on Android I'm having issues and as I'm pretty new to the Android platform, not sure quite where I am going wrong. You said:
So, the only way I could find to get access to the I'm then passing the
Then in my
But this causes it to crash with a useless stack trace and no errors that I can see in logcat: Indeed, either of the lines Like I say, new to all this so I may be making some stupid mistake – if you have any pointers (heh...) or examples of doing this on Android, I'd be really grateful! Thanks, |
Will TuboModules make it easier to write native modules in Swift? Right now we still have to write Objective-C bridging code which is far from ideal. |
In case it helps, I wrote a module to automate away the creation of
bridging code:
NPM: https://www.npmjs.com/package/react-native-swift-bridge
GitHub: https://github.com/rhdeck/reactnative-swift-bridge
And eagerly await TM to find out how the bridge changes to similarly make
swift code easier for us native devs.
…On Thu, Feb 14, 2019 at 8:54 PM Rhys Powell ***@***.***> wrote:
Will TuboModules make it easier to write native modules in Swift? Right
now we still have to write Objective-C bridging code which is far from
ideal.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#40 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ALov_2APjndVX1WTDOSW5PI8psWUrowHks5vNhNkgaJpZM4XaH5o>
.
|
TurboModule foundation is just JSI + platform specific binding. JSI is C++, and for iOS, we need a binding to convert c++ calls into objc++ class methods. To support swift, such c++ to swift binding needs to be built (we won’t be building this as we’re focused on objc support right now). Then with codegen, swift code per module can be generated to some degree. |
@fkgozali Can you introduce more about the jsi/jsc refactor? Some native modules may need the jsContextRef which is now gone facebook/react-native@c49d365#diff-e15318f48b6447f2d9936c5e047d882fL395 |
See the comment above for now: #40 (comment) Why would you need direct access to the VM though? |
@fkgozali the webgl context needs this https://github.com/react-native-community/react-native-webgl/blob/master/cpp/RNWebGL.cpp#L205 |
The existing nativemodules system was not designed to provide you access to the VM directly since that can be dangerous (e.g. multithreaded access, since JS is single threaded, etc). The jsContextRef just happened to be added for a different purpose in the past. With JSI/TurboModule, you can achieve the same thing as https://github.com/react-native-community/react-native-webgl/blob/master/cpp/RNWebGL.cpp#L205 without getting access to the VM. This is done by subclassing JSI HostObject: https://github.com/facebook/react-native/blob/0d7faf6f73b942126e1f45016cde8fd480fd0164/ReactCommon/jsi/jsi.h#L98 -- In fact, TurboModule is just a special subclass of HostObject. So if your webgl stuff registers itself as TurboModule compatible and you provide your own HostObject subclass, then you don't need any access to the VM directly. This process is work in progress and will be documented when they're ready. For now, you can see the comment above as I previously pasted. #40 (comment) |
@fkgozali Thanks for your detailed explanation! I'll give it a try. |
Do TurboModules support multiple callbacks per function? I noticed that with the "legacy" native module system you cannot pass a Callback ( |
Sorry if this is the wrong place. I didn't find any good place to post this possibly turboModules issue. I just upgraded from RN 0.63.2 to 0.64. And my project doesn't build anymore due to this: My build target is ios 10.0. I even tried to bump it to 11. Googling this error brings nothing, which is quite rare when googling RN problems. Should I post this elsewhere? Edit: My bad, sorry. Solved. |
@fkgozali sorry not relevant to this thread but is there documentation on how to disable TurboModules on RNTester? I think it's breaking fast refresh and debugging with Chrome. |
Fast Refresh should work normally, but old Chrome debugger flow won't work because of the lack of sync call support in that env. We're still hashing out the debugger solution later, but a few things you can try:
If you're hitting issue with Fast refresh, make sure you're not connected to the old Chrome debugger flow (the one you launch from dev menu) and see if the problem is solved. If not, would you mind opening a new issue and linking to it here? To disable TurboModule in RNTester (not recommended but OK for your own exploration), change the flag(s) here:
|
I want to use TurboModules to send events from Java to JS using JSI bridge. But i am not able to find a right docs or sample code to proceed. Below is what I have achieved so far. Code to register and later callback
Below is the JS side code
Registration is working but when I tried to do call Any help or pointers on this will be helpful |
@prakashjais99 quick question, I am also in the similar situation but was wondering how where you getting reference to the |
iOS
Android
|
@mrousavy follow up question... when passing the invoker to the cpp-adapter.cpp file, what is the proper way to cast the invoker?
my cpp file has this declaration |
Another workaround to "old debug flow not working": If you're using Hermes you can follow the steps here: https://reactnative.dev/docs/hermes#debugging-js-on-hermes-using-google-chromes-devtools |
Here is roadmap update from react native team https://reactnative.dev/blog/2021/08/19/h2-2021 Looks like they are planning to release new architecture by end of this year. |
dude , did you solved this cast problem ? I encountered this too . |
Here's the magic 🪄: // from java:
CallInvokerHolderImpl callInvoker = (CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder()
initialize(runtime.get(), callInvoker) // in c++:
extern "C" JNIEXPORT void JNICALL Java_com_mrousavy_MyModule_initialize(JNIEnv* env, jclass clazz, jlong jsiRuntime, jni::alias_ref<facebook::react::CallInvokerHolder::javaobject> callInvoker);
// cast:
auto jsCallInvoker = jsCallInvokerHolder->cthis()->getCallInvoker(); But keep in mind that this is pretty unrelated to the issue. |
hey ! guys ! As the rn0.68.0 released the new arch feature; I'm about digging into rn's new archi adoption;
my library 'module-level' react spec looks like below react {
libraryName = "Test"
codegenJavaPackageName = "com.iturbomodule.test"
root = rootProject.file("..")
jsRootDir = rootProject.file("../js/")
reactNativeDir = rootProject.file("../react-native/")
codegenDir = rootProject.file("../react-native-codegen/")
} |
@yaaliuzhipeng As a rule of thumb, report issues like this one either on github.com/reactwg/react-native-new-architecture/ (if you don't have access yet, you can apply for it with the form in the README).
This happens as you don't have the React Gradle Plugin applied in that module. I would say that you miss a:
but not knowing your full gradle file setup, makes hard to say if this is the only issue |
love you dude, I did missed the plugin, everything goes fine after this plugin's added ! ! ! guess I have to learn gradle for a while 😅 |
Hello, I'm playing with TurboModules and figured out something confusing. I was testing my brand new turbo module which uses ExoPlayer. ExoPlayer requires all actions to be triggered from the same thread. I've created two methods represented by the below interface.
I was surprised when I've triggered those methods one by one and got an error
I've tested it further and noticed that there are two types of methods in TurboModule
I've prepared a small playground. Can someone elaborate on why it's like that? |
hey folks, since we have now an official deep dive discussion open on this in the ReactWG New architecture, let's close this one and make the conversation progress over there: reactwg/react-native-new-architecture#2 Remember that you can apply to the WG (in case you are not in it yet) by applying to the form in the readme. |
Introduction
This is a place for discussions around the upcoming "TurboModule" feature.
Terminology
TL;DR
From @axe-fb's blogpost, here's a temporary description of TurboModules (please consider that this is not yet finalized, it may change in the future)
Available Materials
At ReactConf 2018 @axe-fb did a talk about React Native's New Architecture, which also explains the 3 concepts above: JSI, Fabric, TurboModule.
IN Q1 2019, @kelset wrote a more high-level explanation in a blogpost: https://formidable.com/blog/2019/fabric-turbomodules-part-3/ and did a talk about the whole rearchitecture in April 2019 at React Edinburgh.
@kelset also did a more in-depth talk at React Advanced London in Oct 2019: youtube recording & slides.
Q&A
This is also a place for questions related to this effort and its direction.
The text was updated successfully, but these errors were encountered: