Skip to content

Commit 1e6ed83

Browse files
Fix CallInvokerHolderImpl backwards compatibility (#6601)
## Summary This PR changes the way `CallInvokerHandlerImpl` is obtained on older versions of RN. It seems that there is a bug in our build checking CI, since calling `context.getJSCallInvokerHolder()` is not valid on older versions of RN. ## Test plan
1 parent 84d8d3a commit 1e6ed83

File tree

6 files changed

+166
-6
lines changed

6 files changed

+166
-6
lines changed

packages/react-native-reanimated/android/build.gradle

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,14 +382,21 @@ android {
382382
}
383383
}
384384

385-
// RuntimeExecutor
386385
if (IS_NEW_ARCHITECTURE_ENABLED) {
386+
// RuntimeExecutor and CallInvokerHolder
387387
if (REACT_NATIVE_MINOR_VERSION <= 73) {
388-
srcDirs += "src/reactNativeVersionPatch/RuntimeExecutor/73"
388+
srcDirs += "src/reactNativeVersionPatch/NativeProxyFabric/73"
389389
} else if (REACT_NATIVE_MINOR_VERSION <= 74) {
390-
srcDirs += "src/reactNativeVersionPatch/RuntimeExecutor/74"
390+
srcDirs += "src/reactNativeVersionPatch/NativeProxyFabric/74"
391391
} else {
392-
srcDirs += "src/reactNativeVersionPatch/RuntimeExecutor/latest"
392+
srcDirs += "src/reactNativeVersionPatch/NativeProxyFabric/latest"
393+
}
394+
} else {
395+
// CallInvokerHolder
396+
if (REACT_NATIVE_MINOR_VERSION <= 74) {
397+
srcDirs += "src/reactNativeVersionPatch/NativeProxyPaper/74"
398+
} else {
399+
srcDirs += "src/reactNativeVersionPatch/NativeProxyPaper/latest"
393400
}
394401
}
395402

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public class NativeProxy extends NativeProxyCommon {
2121
public NativeProxy(ReactApplicationContext context, String valueUnpackerCode) {
2222
super(context);
2323
ReactFeatureFlagsWrapper.enableMountHooks();
24-
CallInvokerHolderImpl holder = (CallInvokerHolderImpl) context.getJSCallInvokerHolder();
24+
CallInvokerHolderImpl callInvokerHolder =
25+
(CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder();
2526

2627
FabricUIManager fabricUIManager =
2728
(FabricUIManager) UIManagerHelper.getUIManager(context, UIManagerType.FABRIC);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class NativeProxy extends NativeProxyCommon {
4747
valueUnpackerCode);
4848
} else {
4949
CallInvokerHolderImpl callInvokerHolder =
50-
(CallInvokerHolderImpl) context.getJSCallInvokerHolder();
50+
(CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder();
5151
mHybridData =
5252
initHybrid(
5353
Objects.requireNonNull(context.getJavaScriptContextHolder()).get(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
package com.swmansion.reanimated;
2+
3+
import static com.swmansion.reanimated.Utils.simplifyStringNumbersList;
4+
5+
import androidx.annotation.OptIn;
6+
import com.facebook.jni.HybridData;
7+
import com.facebook.proguard.annotations.DoNotStrip;
8+
import com.facebook.react.bridge.ReactApplicationContext;
9+
import com.facebook.react.bridge.queue.MessageQueueThread;
10+
import com.facebook.react.common.annotations.FrameworkAPI;
11+
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl;
12+
import com.swmansion.reanimated.layoutReanimation.LayoutAnimations;
13+
import com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder;
14+
import com.swmansion.reanimated.nativeProxy.NativeProxyCommon;
15+
import java.lang.ref.WeakReference;
16+
import java.util.HashMap;
17+
import java.util.Objects;
18+
19+
public class NativeProxy extends NativeProxyCommon {
20+
@DoNotStrip
21+
@SuppressWarnings("unused")
22+
private final HybridData mHybridData;
23+
24+
@OptIn(markerClass = FrameworkAPI.class)
25+
public NativeProxy(ReactApplicationContext context, String valueUnpackerCode) {
26+
super(context);
27+
CallInvokerHolderImpl holder =
28+
(CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder();
29+
LayoutAnimations LayoutAnimations = new LayoutAnimations(context);
30+
ReanimatedMessageQueueThread messageQueueThread = new ReanimatedMessageQueueThread();
31+
mHybridData =
32+
initHybrid(
33+
Objects.requireNonNull(context.getJavaScriptContextHolder()).get(),
34+
holder,
35+
mAndroidUIScheduler,
36+
LayoutAnimations,
37+
messageQueueThread,
38+
valueUnpackerCode);
39+
prepareLayoutAnimations(LayoutAnimations);
40+
installJSIBindings();
41+
if (BuildConfig.DEBUG) {
42+
checkCppVersion();
43+
}
44+
}
45+
46+
@OptIn(markerClass = FrameworkAPI.class)
47+
private native HybridData initHybrid(
48+
long jsContext,
49+
CallInvokerHolderImpl jsCallInvokerHolder,
50+
AndroidUIScheduler androidUIScheduler,
51+
LayoutAnimations LayoutAnimations,
52+
MessageQueueThread messageQueueThread,
53+
String valueUnpackerCode);
54+
55+
public native boolean isAnyHandlerWaitingForEvent(String eventName, int emitterReactTag);
56+
57+
public native void performOperations();
58+
59+
@Override
60+
protected HybridData getHybridData() {
61+
return mHybridData;
62+
}
63+
64+
public static NativeMethodsHolder createNativeMethodsHolder(LayoutAnimations layoutAnimations) {
65+
WeakReference<LayoutAnimations> weakLayoutAnimations = new WeakReference<>(layoutAnimations);
66+
return new NativeMethodsHolder() {
67+
@Override
68+
public void startAnimation(int tag, int type, HashMap<String, Object> values) {
69+
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
70+
if (layoutAnimations != null) {
71+
HashMap<String, String> preparedValues = new HashMap<>();
72+
for (String key : values.keySet()) {
73+
String stringValue = values.get(key).toString();
74+
if (key.endsWith("TransformMatrix")) {
75+
preparedValues.put(key, simplifyStringNumbersList(stringValue));
76+
} else {
77+
preparedValues.put(key, stringValue);
78+
}
79+
}
80+
layoutAnimations.startAnimationForTag(tag, type, preparedValues);
81+
}
82+
}
83+
84+
@Override
85+
public boolean shouldAnimateExiting(int tag, boolean shouldAnimate) {
86+
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
87+
if (layoutAnimations != null) {
88+
return layoutAnimations.shouldAnimateExiting(tag, shouldAnimate);
89+
}
90+
return false;
91+
}
92+
93+
@Override
94+
public boolean isLayoutAnimationEnabled() {
95+
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
96+
if (layoutAnimations != null) {
97+
return layoutAnimations.isLayoutAnimationEnabled();
98+
}
99+
return false;
100+
}
101+
102+
@Override
103+
public boolean hasAnimation(int tag, int type) {
104+
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
105+
if (layoutAnimations != null) {
106+
return layoutAnimations.hasAnimationForTag(tag, type);
107+
}
108+
return false;
109+
}
110+
111+
@Override
112+
public void clearAnimationConfig(int tag) {
113+
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
114+
if (layoutAnimations != null) {
115+
layoutAnimations.clearAnimationConfigForTag(tag);
116+
}
117+
}
118+
119+
@Override
120+
public void cancelAnimation(int tag) {
121+
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
122+
if (layoutAnimations != null) {
123+
layoutAnimations.cancelAnimationForTag(tag);
124+
}
125+
}
126+
127+
@Override
128+
public int findPrecedingViewTagForTransition(int tag) {
129+
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
130+
if (layoutAnimations != null) {
131+
return layoutAnimations.findPrecedingViewTagForTransition(tag);
132+
}
133+
return -1;
134+
}
135+
136+
public void checkDuplicateSharedTag(int viewTag, int screenTag) {
137+
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
138+
if (layoutAnimations != null) {
139+
layoutAnimations.checkDuplicateSharedTag(viewTag, screenTag);
140+
}
141+
}
142+
143+
public int[] getSharedGroup(int viewTag) {
144+
LayoutAnimations layoutAnimations = weakLayoutAnimations.get();
145+
if (layoutAnimations != null) {
146+
return layoutAnimations.getSharedGroup(viewTag);
147+
}
148+
return new int[] {};
149+
}
150+
};
151+
}
152+
}

0 commit comments

Comments
 (0)