Skip to content

Commit 9ce9085

Browse files
authored
Call NodesManager.initWithContext and thus create NativeProxy in ReanimatedModule constructor (#7206)
## Summary Currently, we first create `ReanimatedModule` and `NodesManager` in its constructor. Then, calling `ReanimatedModule.installTurboModule` invokes `NodesManager.initWithContext` which creates `NativeProxy` and injects JSI bindings in its constructor. The part I don't like here is that `NodesManager` stays unconfigured for some time (between constructor and `initWithContext` calls). Also, there's some time period when `ReanimatedModule` exists but `NativeProxy` doesn't exist yet, even though it will be necessary, so why don't we just instantiate it earlier? After this change, all three `ReanimatedModule`, `NodesManager` and `NativeProxy` instances will be created at the same time (but without injecting JSI bindings). Then, calling `installTurboModule` will delegate the call to already existing `NativeProxy` which will inject the bindings at the right time. ## Test plan Build, launch and reload fabric-example on Android.
1 parent ff127af commit 9ce9085

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/NativeProxy.java

-5
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ public class NativeProxy {
8484
Objects.requireNonNull(context.getJavaScriptContextHolder()).get(),
8585
callInvokerHolder,
8686
fabricUIManager);
87-
88-
installJSIBindings();
89-
if (BuildConfig.DEBUG) {
90-
checkCppVersion();
91-
}
9287
}
9388

9489
@OptIn(markerClass = FrameworkAPI.class)

packages/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/ReanimatedModule.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public ReanimatedModule(ReactApplicationContext reactContext) {
1616
reactContext.assertOnJSQueueThread();
1717
mWorkletsModule = reactContext.getNativeModule(WorkletsModule.class);
1818
mNodesManager = new NodesManager(reactContext, mWorkletsModule);
19+
mNodesManager.initWithContext(reactContext);
20+
// TODO: merge initWithContext into NodesManager constructor
1921
}
2022

2123
@Override
@@ -48,7 +50,10 @@ public NodesManager getNodesManager() {
4850
@ReactMethod(isBlockingSynchronousMethod = true)
4951
public boolean installTurboModule() {
5052
getReactApplicationContext().assertOnJSQueueThread();
51-
mNodesManager.initWithContext(getReactApplicationContext());
53+
mNodesManager.getNativeProxy().installJSIBindings();
54+
if (BuildConfig.DEBUG) {
55+
mNodesManager.getNativeProxy().checkCppVersion();
56+
}
5257
return true;
5358
}
5459

0 commit comments

Comments
 (0)