Add installJSIBindings for turbo modules on android#43110
Conversation
Base commit: 7fffe69 |
| bool enableSyncVoidMethods) { | ||
| jsi::Runtime *runtime, bool enableSyncVoidMethods) { | ||
| return [turboModuleCache_ = std::weak_ptr<ModuleCache>(turboModuleCache_), | ||
| runtime, |
There was a problem hiding this comment.
the runtime could be a dangling pointer in theory. but the lambda would run on js thread and there's the check. so it should not hit to handling pointer crash.
if (!turboModuleCache || !jsCallInvoker || !nativeMethodCallInvoker ||
!delegate || !javaPart) {
return nullptr;
}| public void installJSIBindings(long runtime) { | ||
| installJSIBindingsCxx(runtime); | ||
| } |
There was a problem hiding this comment.
so it feels like one motivation of having this live in native land is that we might have some native dependencies that we want to pass down the the runtime bindings. if that's the case, i feel like this will be called before we could do anything to manipulate the native state of the module, or do you see it differently?
There was a problem hiding this comment.
if that's the case, i feel like this will be called before we could do anything to manipulate the native state of the module
from js side, yes, and that's why we need a synchronous way to install bindings right after initiating the module and before the further js call. i.e.
const module = TurboModuleRegistry.getEnforcing<Spec>('Module');
// globalThis.someJSIBindings should be available here
module.call();| * @param runtime The (facebook::jsi::Runtime *) pointer casted to Long type. | ||
| */ | ||
| @DoNotStrip | ||
| public fun installJSIBindings(runtime: Long) |
There was a problem hiding this comment.
implementation detail, but i think it would be nice if we could have a compile time check here to fail if there's no JNI method here... they have to write C++ anyways to handle the runtime anyways if they're using this API, and maybe we could also obfuscate the pointer cast from them. i am a kotlin noob so not sure if that's possible here
There was a problem hiding this comment.
originally i was thinking to introduce the interface as an abstract class and having fbjni c++ hybrid data. we could scaffold more c++ stuff there. ultimately i thought that abstract class might not be a good idea since some native module might need their dedicated base class.
unfortunately kotlin seems not support interface with public external fun, otherwise it helps to indicate the method should be a jni call.
|
close and looking forward to seeing alternative solutions in the future |
Summary: Add synchronous JS bindings installation for TurboModules. That would help some 3rd party JSI based modules to install JS bindings easier. Re-create from #43110 but for iOS ## Changelog: [IOS] [ADDED] - Add BindingsInstaller for TurboModules Pull Request resolved: #44486 Test Plan: Added test in RN-Tester TurboModule test case Reviewed By: javache Differential Revision: D57224891 Pulled By: philIip fbshipit-source-id: fabe5c4f8d2087ac9a465f2cb90d884b83265a68
Summary: Add synchronous JS bindings installation for TurboModules. That would help some 3rd party JSI based modules to install JS bindings easier. Re-create from facebook#43110 but for iOS ## Changelog: [IOS] [ADDED] - Add BindingsInstaller for TurboModules Pull Request resolved: facebook#44486 Test Plan: Added test in RN-Tester TurboModule test case Reviewed By: javache Differential Revision: D57224891 Pulled By: philIip fbshipit-source-id: fabe5c4f8d2087ac9a465f2cb90d884b83265a68
Summary:
Add synchronous JSI installation for TurboModules on Android. That would help some 3rd party JSI based modules to get the
jsi::Runtimeon bridgeless mode.The iOS implementation will be in a separate PR.
Changelog:
[ANDROID] [ADDED] - Add installJSIBindings for TurboModules
Test Plan:
Added test in RN-Tester TurboModule test case