diff --git a/packages/react-native-reanimated/android/build.gradle b/packages/react-native-reanimated/android/build.gradle index e50796a4fdb..612994412a7 100644 --- a/packages/react-native-reanimated/android/build.gradle +++ b/packages/react-native-reanimated/android/build.gradle @@ -382,14 +382,21 @@ android { } } - // RuntimeExecutor if (IS_NEW_ARCHITECTURE_ENABLED) { + // RuntimeExecutor and CallInvokerHolder if (REACT_NATIVE_MINOR_VERSION <= 73) { - srcDirs += "src/reactNativeVersionPatch/RuntimeExecutor/73" + srcDirs += "src/reactNativeVersionPatch/NativeProxyFabric/73" } else if (REACT_NATIVE_MINOR_VERSION <= 74) { - srcDirs += "src/reactNativeVersionPatch/RuntimeExecutor/74" + srcDirs += "src/reactNativeVersionPatch/NativeProxyFabric/74" } else { - srcDirs += "src/reactNativeVersionPatch/RuntimeExecutor/latest" + srcDirs += "src/reactNativeVersionPatch/NativeProxyFabric/latest" + } + } else { + // CallInvokerHolder + if (REACT_NATIVE_MINOR_VERSION <= 74) { + srcDirs += "src/reactNativeVersionPatch/NativeProxyPaper/74" + } else { + srcDirs += "src/reactNativeVersionPatch/NativeProxyPaper/latest" } } diff --git a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/RuntimeExecutor/73/com/swmansion/reanimated/NativeProxy.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/73/com/swmansion/reanimated/NativeProxy.java similarity index 96% rename from packages/react-native-reanimated/android/src/reactNativeVersionPatch/RuntimeExecutor/73/com/swmansion/reanimated/NativeProxy.java rename to packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/73/com/swmansion/reanimated/NativeProxy.java index d9b074a5597..85a6483d5a9 100644 --- a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/RuntimeExecutor/73/com/swmansion/reanimated/NativeProxy.java +++ b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/73/com/swmansion/reanimated/NativeProxy.java @@ -21,7 +21,8 @@ public class NativeProxy extends NativeProxyCommon { public NativeProxy(ReactApplicationContext context, String valueUnpackerCode) { super(context); ReactFeatureFlagsWrapper.enableMountHooks(); - CallInvokerHolderImpl holder = (CallInvokerHolderImpl) context.getJSCallInvokerHolder(); + CallInvokerHolderImpl callInvokerHolder = + (CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder(); FabricUIManager fabricUIManager = (FabricUIManager) UIManagerHelper.getUIManager(context, UIManagerType.FABRIC); diff --git a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/RuntimeExecutor/74/com/swmansion/reanimated/NativeProxy.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/74/com/swmansion/reanimated/NativeProxy.java similarity index 98% rename from packages/react-native-reanimated/android/src/reactNativeVersionPatch/RuntimeExecutor/74/com/swmansion/reanimated/NativeProxy.java rename to packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/74/com/swmansion/reanimated/NativeProxy.java index bb04b31e7e5..177fc0fad91 100644 --- a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/RuntimeExecutor/74/com/swmansion/reanimated/NativeProxy.java +++ b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/74/com/swmansion/reanimated/NativeProxy.java @@ -47,7 +47,7 @@ public class NativeProxy extends NativeProxyCommon { valueUnpackerCode); } else { CallInvokerHolderImpl callInvokerHolder = - (CallInvokerHolderImpl) context.getJSCallInvokerHolder(); + (CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder(); mHybridData = initHybrid( Objects.requireNonNull(context.getJavaScriptContextHolder()).get(), diff --git a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/RuntimeExecutor/latest/com/swmansion/reanimated/NativeProxy.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/latest/com/swmansion/reanimated/NativeProxy.java similarity index 100% rename from packages/react-native-reanimated/android/src/reactNativeVersionPatch/RuntimeExecutor/latest/com/swmansion/reanimated/NativeProxy.java rename to packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyFabric/latest/com/swmansion/reanimated/NativeProxy.java diff --git a/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/74/com/swmansion/reanimated/NativeProxy.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/74/com/swmansion/reanimated/NativeProxy.java new file mode 100644 index 00000000000..01637b1b86a --- /dev/null +++ b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/74/com/swmansion/reanimated/NativeProxy.java @@ -0,0 +1,152 @@ +package com.swmansion.reanimated; + +import static com.swmansion.reanimated.Utils.simplifyStringNumbersList; + +import androidx.annotation.OptIn; +import com.facebook.jni.HybridData; +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.queue.MessageQueueThread; +import com.facebook.react.common.annotations.FrameworkAPI; +import com.facebook.react.turbomodule.core.CallInvokerHolderImpl; +import com.swmansion.reanimated.layoutReanimation.LayoutAnimations; +import com.swmansion.reanimated.layoutReanimation.NativeMethodsHolder; +import com.swmansion.reanimated.nativeProxy.NativeProxyCommon; +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Objects; + +public class NativeProxy extends NativeProxyCommon { + @DoNotStrip + @SuppressWarnings("unused") + private final HybridData mHybridData; + + @OptIn(markerClass = FrameworkAPI.class) + public NativeProxy(ReactApplicationContext context, String valueUnpackerCode) { + super(context); + CallInvokerHolderImpl holder = + (CallInvokerHolderImpl) context.getCatalystInstance().getJSCallInvokerHolder(); + LayoutAnimations LayoutAnimations = new LayoutAnimations(context); + ReanimatedMessageQueueThread messageQueueThread = new ReanimatedMessageQueueThread(); + mHybridData = + initHybrid( + Objects.requireNonNull(context.getJavaScriptContextHolder()).get(), + holder, + mAndroidUIScheduler, + LayoutAnimations, + messageQueueThread, + valueUnpackerCode); + prepareLayoutAnimations(LayoutAnimations); + installJSIBindings(); + if (BuildConfig.DEBUG) { + checkCppVersion(); + } + } + + @OptIn(markerClass = FrameworkAPI.class) + private native HybridData initHybrid( + long jsContext, + CallInvokerHolderImpl jsCallInvokerHolder, + AndroidUIScheduler androidUIScheduler, + LayoutAnimations LayoutAnimations, + MessageQueueThread messageQueueThread, + String valueUnpackerCode); + + public native boolean isAnyHandlerWaitingForEvent(String eventName, int emitterReactTag); + + public native void performOperations(); + + @Override + protected HybridData getHybridData() { + return mHybridData; + } + + public static NativeMethodsHolder createNativeMethodsHolder(LayoutAnimations layoutAnimations) { + WeakReference weakLayoutAnimations = new WeakReference<>(layoutAnimations); + return new NativeMethodsHolder() { + @Override + public void startAnimation(int tag, int type, HashMap values) { + LayoutAnimations layoutAnimations = weakLayoutAnimations.get(); + if (layoutAnimations != null) { + HashMap preparedValues = new HashMap<>(); + for (String key : values.keySet()) { + String stringValue = values.get(key).toString(); + if (key.endsWith("TransformMatrix")) { + preparedValues.put(key, simplifyStringNumbersList(stringValue)); + } else { + preparedValues.put(key, stringValue); + } + } + layoutAnimations.startAnimationForTag(tag, type, preparedValues); + } + } + + @Override + public boolean shouldAnimateExiting(int tag, boolean shouldAnimate) { + LayoutAnimations layoutAnimations = weakLayoutAnimations.get(); + if (layoutAnimations != null) { + return layoutAnimations.shouldAnimateExiting(tag, shouldAnimate); + } + return false; + } + + @Override + public boolean isLayoutAnimationEnabled() { + LayoutAnimations layoutAnimations = weakLayoutAnimations.get(); + if (layoutAnimations != null) { + return layoutAnimations.isLayoutAnimationEnabled(); + } + return false; + } + + @Override + public boolean hasAnimation(int tag, int type) { + LayoutAnimations layoutAnimations = weakLayoutAnimations.get(); + if (layoutAnimations != null) { + return layoutAnimations.hasAnimationForTag(tag, type); + } + return false; + } + + @Override + public void clearAnimationConfig(int tag) { + LayoutAnimations layoutAnimations = weakLayoutAnimations.get(); + if (layoutAnimations != null) { + layoutAnimations.clearAnimationConfigForTag(tag); + } + } + + @Override + public void cancelAnimation(int tag) { + LayoutAnimations layoutAnimations = weakLayoutAnimations.get(); + if (layoutAnimations != null) { + layoutAnimations.cancelAnimationForTag(tag); + } + } + + @Override + public int findPrecedingViewTagForTransition(int tag) { + LayoutAnimations layoutAnimations = weakLayoutAnimations.get(); + if (layoutAnimations != null) { + return layoutAnimations.findPrecedingViewTagForTransition(tag); + } + return -1; + } + + public void checkDuplicateSharedTag(int viewTag, int screenTag) { + LayoutAnimations layoutAnimations = weakLayoutAnimations.get(); + if (layoutAnimations != null) { + layoutAnimations.checkDuplicateSharedTag(viewTag, screenTag); + } + } + + public int[] getSharedGroup(int viewTag) { + LayoutAnimations layoutAnimations = weakLayoutAnimations.get(); + if (layoutAnimations != null) { + return layoutAnimations.getSharedGroup(viewTag); + } + return new int[] {}; + } + }; + } +} diff --git a/packages/react-native-reanimated/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java b/packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/latest/com/swmansion/reanimated/NativeProxy.java similarity index 100% rename from packages/react-native-reanimated/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java rename to packages/react-native-reanimated/android/src/reactNativeVersionPatch/NativeProxyPaper/latest/com/swmansion/reanimated/NativeProxy.java