mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-01-12 22:50:10 +08:00
Summary:
JSCallInvoker requires a `std::weak_ptr<Instance>` to create. In our C++, `CatalystInstance` is responsible for creating this `Instance` object. This `CatalystInstance` C++ initialization is separate from the `TurboModuleManager` C++ initialization. Therefore, in this diff, I made `CatalystInstance` responsible for creating the `JSCallInvoker`. It then exposes the `JSCallInvoker` using a hybrid class called `JSCallInvokerHolder`, which contains a `std::shared_ptr<JSCallInvoker>` member variable. Using `CatalystInstance.getJSCallInvokerHolder()` in TurboModuleManager.java, we get a handle to this hybrid container. Then, we pass it this hybrid object to `TurboModuleManager::initHybrid`, which retrieves the `std::shared_ptr<JSCallInvoker>` from the `JavaJSCallInvokerHandler`.
There were a few cyclic dependencies, so I had to break down the buck targets:
- `CatalystInstanceImpl.java` depends on `JSCallInvokerHolderImpl.java`, and `TurboModuleManager.java` depends on classes that are packaged with `CatalystInstanceImpl.java`. So, I had to put `JSCallInvokerHolderImpl.java` in its own buck target.
- `CatalystInstance.cpp` depends on `JavaJSCallInvokerHolder.cpp`, and `TurboModuleManager.cpp` depends on classes that are build with `CatalystInstance.cpp`. So, I had to put `JavaJSCallInvokerHolder.cpp` in its own buck target. To make things simpler, I also moved `JSCallInvoker.{cpp,h}` files into the same buck target as `JavaJSCallInvokerHolder.{cpp,h}`.
I think these steps should be enough to create the TurboModuleManager without needing a bridge:
1. Make `JSCallInvoker` an abstract base class.
2. On Android, create another derived class of `JSCallInvoker` that doesn't depend on Instance.
3. Create `JavaJSCallInvokerHolder` using an instance of this new class somewhere in C++.
4. Pass this instance of `JavaJSCallInvokerHolder` to Java and use it to create/instatiate `TurboModuleManager`.
Regarding steps 1 and 2, we can also make JSCallInvoker accept a lambda.
Reviewed By: mdvacca
Differential Revision: D15055511
fbshipit-source-id: 0ad72a86599819ec35d421dbee7e140959a26ab6
86 lines
3.6 KiB
Python
86 lines
3.6 KiB
Python
load("//tools/build_defs/oss:rn_defs.bzl", "IS_OSS_BUILD", "react_native_dep", "react_native_target", "rn_android_library")
|
|
|
|
INTERFACES = [
|
|
"Dynamic.java",
|
|
"ReadableMap.java",
|
|
"ReadableMapKeySetIterator.java",
|
|
"WritableArray.java",
|
|
"WritableMap.java",
|
|
"NativeModule.java",
|
|
"JSInstance.java",
|
|
"ReadableArray.java",
|
|
"ReadableType.java",
|
|
"NativeArrayInterface.java",
|
|
]
|
|
|
|
rn_android_library(
|
|
name = "bridge",
|
|
srcs = glob(
|
|
["**/*.java"],
|
|
exclude = INTERFACES,
|
|
),
|
|
is_androidx = True,
|
|
proguard_config = "reactnative.pro",
|
|
provided_deps = [
|
|
react_native_dep("third-party/android/androidx:annotation"),
|
|
react_native_dep("third-party/android/androidx:core"),
|
|
react_native_dep("third-party/android/androidx:fragment"),
|
|
react_native_dep("third-party/android/androidx:legacy-support-core-ui"),
|
|
react_native_dep("third-party/android/androidx:legacy-support-core-utils"),
|
|
],
|
|
required_for_source_only_abi = True,
|
|
visibility = [
|
|
"PUBLIC",
|
|
],
|
|
deps = [
|
|
react_native_dep("java/com/facebook/debug/debugoverlay/model:model"),
|
|
react_native_dep("java/com/facebook/systrace:systrace"),
|
|
react_native_dep("libraries/fbcore/src/main/java/com/facebook/common/logging:logging"),
|
|
react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"),
|
|
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
|
|
react_native_dep("third-party/java/jsr-305:jsr-305"),
|
|
react_native_target("java/com/facebook/debug/tags:tags"),
|
|
react_native_target("java/com/facebook/debug/holder:holder"),
|
|
react_native_target("java/com/facebook/react/common:common"),
|
|
react_native_target("java/com/facebook/react/config:config"),
|
|
react_native_target("java/com/facebook/react/module/model:model"),
|
|
react_native_target("java/com/facebook/react/uimanager/common:common"),
|
|
react_native_target("java/com/facebook/react/module/annotations:annotations"),
|
|
react_native_target("java/com/facebook/react/turbomodule/core/interfaces:interfaces"),
|
|
react_native_target("java/com/facebook/react/turbomodule/core:jscallinvokerholder"),
|
|
] + ([react_native_target("jni/react/jni:jni")] if not IS_OSS_BUILD else []),
|
|
exported_deps = [
|
|
react_native_dep("java/com/facebook/jni:jni"),
|
|
react_native_dep("java/com/facebook/proguard/annotations:annotations"),
|
|
react_native_dep("third-party/java/jsr-330:jsr-330"),
|
|
react_native_target("java/com/facebook/react/bridge:interfaces"),
|
|
],
|
|
)
|
|
|
|
rn_android_library(
|
|
name = "interfaces",
|
|
srcs = glob(INTERFACES),
|
|
is_androidx = True,
|
|
proguard_config = "reactnative.pro",
|
|
provided_deps = [
|
|
react_native_dep("third-party/android/androidx:annotation"),
|
|
react_native_dep("third-party/android/androidx:core"),
|
|
react_native_dep("third-party/android/androidx:fragment"),
|
|
react_native_dep("third-party/android/androidx:legacy-support-core-ui"),
|
|
react_native_dep("third-party/android/androidx:legacy-support-core-utils"),
|
|
],
|
|
required_for_source_only_abi = True,
|
|
visibility = [
|
|
"PUBLIC",
|
|
],
|
|
deps = [
|
|
react_native_dep("third-party/java/infer-annotations:infer-annotations"),
|
|
react_native_dep("third-party/java/jsr-305:jsr-305"),
|
|
react_native_target("java/com/facebook/debug/tags:tags"),
|
|
],
|
|
exported_deps = [
|
|
react_native_dep("java/com/facebook/proguard/annotations:annotations"),
|
|
react_native_dep("third-party/java/jsr-330:jsr-330"),
|
|
],
|
|
)
|