Skip to content

Commit 2e16785

Browse files
philIipfacebook-github-bot
authored andcommitted
introduce unstable_enableSyncVoidMethods config (facebook#39989)
Summary: Pull Request resolved: facebook#39989 Changelog: [Internal] we need some configuration path to turn on the sync void method execution behavior, doing that here Reviewed By: luluwu2032 Differential Revision: D50028200 fbshipit-source-id: a2501b622685e4bafa5e2a5031275cc8bc5050b7
1 parent b41a2f9 commit 2e16785

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManager.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public TurboModuleManager(
7171
(CallInvokerHolderImpl) jsCallInvokerHolder,
7272
(NativeMethodCallInvokerHolderImpl) nativeMethodCallInvokerHolder,
7373
delegate);
74-
installJSIBindings(shouldEnableLegacyModuleInterop());
74+
installJSIBindings(shouldEnableLegacyModuleInterop(), enableSyncVoidMethods());
7575

7676
mEagerInitModuleNames =
7777
delegate == null ? new ArrayList<>() : delegate.getEagerInitModuleNames();
@@ -116,6 +116,10 @@ private boolean shouldRouteTurboModulesThroughLegacyModuleInterop() {
116116
&& mDelegate.unstable_shouldRouteTurboModulesThroughLegacyModuleInterop();
117117
}
118118

119+
private boolean enableSyncVoidMethods() {
120+
return mDelegate != null && mDelegate.unstable_enableSyncVoidMethods();
121+
}
122+
119123
@Override
120124
@NonNull
121125
public List<String> getEagerInitModuleNames() {
@@ -417,7 +421,8 @@ private native HybridData initHybrid(
417421
NativeMethodCallInvokerHolderImpl nativeMethodCallInvoker,
418422
TurboModuleManagerDelegate tmmDelegate);
419423

420-
private native void installJSIBindings(boolean shouldCreateLegacyModules);
424+
private native void installJSIBindings(
425+
boolean shouldCreateLegacyModules, boolean enableSyncVoidMethods);
421426

422427
@Override
423428
public void initialize() {}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/turbomodule/core/TurboModuleManagerDelegate.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,9 @@ public boolean unstable_shouldRouteTurboModulesThroughLegacyModuleInterop() {
7070
return false;
7171
}
7272

73+
public boolean unstable_enableSyncVoidMethods() {
74+
return false;
75+
}
76+
7377
protected synchronized void maybeLoadOtherSoLibraries() {}
7478
}

packages/react-native/ReactAndroid/src/main/jni/react/turbomodule/ReactCommon/TurboModuleManager.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ void TurboModuleManager::registerNatives() {
128128
});
129129
}
130130

131-
TurboModuleProviderFunctionType
132-
TurboModuleManager::createTurboModuleProvider() {
131+
TurboModuleProviderFunctionType TurboModuleManager::createTurboModuleProvider(
132+
bool enableSyncVoidMethods) {
133133
return [turboModuleCache_ = std::weak_ptr<ModuleCache>(turboModuleCache_),
134134
jsCallInvoker_ = std::weak_ptr<CallInvoker>(jsCallInvoker_),
135135
nativeMethodCallInvoker_ =
@@ -209,8 +209,8 @@ TurboModuleManager::createTurboModuleProvider() {
209209
};
210210
}
211211

212-
TurboModuleProviderFunctionType
213-
TurboModuleManager::createLegacyModuleProvider() {
212+
TurboModuleProviderFunctionType TurboModuleManager::createLegacyModuleProvider(
213+
bool enableSyncVoidMethods) {
214214
return [legacyModuleCache_ = std::weak_ptr<ModuleCache>(legacyModuleCache_),
215215
jsCallInvoker_ = std::weak_ptr<CallInvoker>(jsCallInvoker_),
216216
nativeMethodCallInvoker_ =
@@ -302,21 +302,27 @@ TurboModuleManager::createLegacyModuleProvider() {
302302
};
303303
}
304304

305-
void TurboModuleManager::installJSIBindings(bool shouldCreateLegacyModules) {
305+
void TurboModuleManager::installJSIBindings(
306+
bool shouldCreateLegacyModules,
307+
bool enableSyncVoidMethods) {
306308
if (!jsCallInvoker_) {
307309
return; // Runtime doesn't exist when attached to Chrome debugger.
308310
}
309311

310312
bool isInteropLayerDisabled = !shouldCreateLegacyModules;
311313

312-
runtimeExecutor_([this, isInteropLayerDisabled](jsi::Runtime& runtime) {
314+
runtimeExecutor_([this, isInteropLayerDisabled, enableSyncVoidMethods](
315+
jsi::Runtime& runtime) {
313316
if (isInteropLayerDisabled) {
314-
TurboModuleBinding::install(runtime, createTurboModuleProvider());
317+
TurboModuleBinding::install(
318+
runtime, createTurboModuleProvider(enableSyncVoidMethods));
315319
return;
316320
}
317321

318322
TurboModuleBinding::install(
319-
runtime, createTurboModuleProvider(), createLegacyModuleProvider());
323+
runtime,
324+
createTurboModuleProvider(enableSyncVoidMethods),
325+
createLegacyModuleProvider(enableSyncVoidMethods));
320326
});
321327
}
322328

packages/react-native/ReactAndroid/src/main/jni/react/turbomodule/ReactCommon/TurboModuleManager.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,20 @@ class TurboModuleManager : public jni::HybridClass<TurboModuleManager> {
5656
std::shared_ptr<ModuleCache> turboModuleCache_;
5757
std::shared_ptr<ModuleCache> legacyModuleCache_;
5858

59-
void installJSIBindings(bool shouldCreateLegacyModules);
59+
void installJSIBindings(
60+
bool shouldCreateLegacyModules,
61+
bool enableSyncVoidMethods);
6062
explicit TurboModuleManager(
6163
jni::alias_ref<TurboModuleManager::jhybridobject> jThis,
6264
RuntimeExecutor runtimeExecutor,
6365
std::shared_ptr<CallInvoker> jsCallInvoker,
6466
std::shared_ptr<NativeMethodCallInvoker> nativeMethodCallInvoker,
6567
jni::alias_ref<TurboModuleManagerDelegate::javaobject> delegate);
6668

67-
TurboModuleProviderFunctionType createTurboModuleProvider();
68-
TurboModuleProviderFunctionType createLegacyModuleProvider();
69+
TurboModuleProviderFunctionType createTurboModuleProvider(
70+
bool enableSyncVoidMethods);
71+
TurboModuleProviderFunctionType createLegacyModuleProvider(
72+
bool enableSyncVoidMethods);
6973
};
7074

7175
} // namespace facebook::react

0 commit comments

Comments
 (0)