From d7d6a4fe7bcf60559963344aebe90e51b18644b6 Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Thu, 9 May 2024 17:42:47 +0200 Subject: [PATCH 1/3] fix: use proper classes for bridgeless --- android/build.gradle | 7 + .../reanimated}/NativeProxyCommon.java | 0 .../reanimated/NativeProxyCommon.java | 276 ++++++++++++++++++ 3 files changed, 283 insertions(+) rename android/src/{main/java/com/swmansion/reanimated/nativeProxy => reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated}/NativeProxyCommon.java (100%) create mode 100644 android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/NativeProxyCommon.java diff --git a/android/build.gradle b/android/build.gradle index b9aab4871d12..0667684c187e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -380,6 +380,13 @@ android { srcDirs += "src/reactNativeVersionPatch/ReanimatedUIManager/latest" } + // ReactHost + if (REACT_NATIVE_MINOR_VERSION <= 72) { + srcDirs += "src/reactNativeVersionPatch/ReactHost/72" + } else { + srcDirs += "src/reactNativeVersionPatch/ReactHost/latest" + } + // ReactFeatureFlags if (IS_NEW_ARCHITECTURE_ENABLED) { if (REACT_NATIVE_MINOR_VERSION <= 72) { diff --git a/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java b/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/NativeProxyCommon.java similarity index 100% rename from android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java rename to android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/NativeProxyCommon.java diff --git a/android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/NativeProxyCommon.java b/android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/NativeProxyCommon.java new file mode 100644 index 000000000000..11f8e5b06d9b --- /dev/null +++ b/android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/NativeProxyCommon.java @@ -0,0 +1,276 @@ +package com.swmansion.reanimated.nativeProxy; + +import android.content.ContentResolver; +import android.os.SystemClock; +import android.provider.Settings; +import android.util.Log; +import com.facebook.jni.HybridData; +import com.facebook.proguard.annotations.DoNotStrip; +import com.facebook.react.ReactApplication; +import com.facebook.react.bridge.NativeModule; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.bridge.ReadableArray; +import com.facebook.react.bridge.ReadableMap; +import com.facebook.react.bridge.ReadableNativeArray; +import com.facebook.react.devsupport.interfaces.DevSupportManager; +import com.facebook.soloader.SoLoader; +import com.swmansion.common.GestureHandlerStateManager; +import com.swmansion.reanimated.AndroidUIScheduler; +import com.swmansion.reanimated.BuildConfig; +import com.swmansion.reanimated.NativeProxy; +import com.swmansion.reanimated.NodesManager; +import com.swmansion.reanimated.ReanimatedModule; +import com.swmansion.reanimated.Utils; +import com.swmansion.reanimated.keyboard.KeyboardAnimationManager; +import com.swmansion.reanimated.keyboard.KeyboardWorkletWrapper; +import com.swmansion.reanimated.layoutReanimation.AnimationsManager; +import com.swmansion.reanimated.layoutReanimation.LayoutAnimations; +import com.swmansion.reanimated.sensor.ReanimatedSensorContainer; +import com.swmansion.reanimated.sensor.ReanimatedSensorType; +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public abstract class NativeProxyCommon { + static { + SoLoader.loadLibrary("reanimated"); + } + + protected NodesManager mNodesManager; + protected final WeakReference mContext; + protected AndroidUIScheduler mAndroidUIScheduler; + private ReanimatedSensorContainer reanimatedSensorContainer; + private final GestureHandlerStateManager gestureHandlerStateManager; + private KeyboardAnimationManager keyboardAnimationManager; + private Long firstUptime = SystemClock.uptimeMillis(); + private boolean slowAnimationsEnabled = false; + protected String cppVersion = null; + + protected NativeProxyCommon(ReactApplicationContext context) { + mAndroidUIScheduler = new AndroidUIScheduler(context); + mContext = new WeakReference<>(context); + reanimatedSensorContainer = new ReanimatedSensorContainer(mContext); + keyboardAnimationManager = new KeyboardAnimationManager(mContext); + addDevMenuOption(); + + GestureHandlerStateManager tempHandlerStateManager; + try { + Class gestureHandlerModuleClass = + (Class) + Class.forName("com.swmansion.gesturehandler.react.RNGestureHandlerModule"); + tempHandlerStateManager = + (GestureHandlerStateManager) context.getNativeModule(gestureHandlerModuleClass); + } catch (ClassCastException | ClassNotFoundException e) { + tempHandlerStateManager = null; + } + gestureHandlerStateManager = tempHandlerStateManager; + } + + protected native void installJSIBindings(); + + public AndroidUIScheduler getAndroidUIScheduler() { + return mAndroidUIScheduler; + } + + private void toggleSlowAnimations() { + slowAnimationsEnabled = !slowAnimationsEnabled; + if (slowAnimationsEnabled) { + firstUptime = SystemClock.uptimeMillis(); + } + } + + private void addDevMenuOption() { + // In Expo, `ApplicationContext` is not an instance of `ReactApplication` + if (mContext.get().getApplicationContext() instanceof ReactApplication) { + DevSupportManager devSupportManager; + if (mContext.get().isBridgeless()) { + devSupportManager = + ((ReactApplication) mContext.get().getApplicationContext()) + .getReactHost().getDevSupportManager(); + } else { + devSupportManager = + ((ReactApplication) mContext.get().getApplicationContext()) + .getReactNativeHost() + .getReactInstanceManager() + .getDevSupportManager(); + } + + if (devSupportManager != null) { + devSupportManager.addCustomDevOption( + "Toggle slow animations (Reanimated)", this::toggleSlowAnimations); + } else { + throw new RuntimeException("[Reanimated] DevSupportManager is not available"); + } + } + } + + @DoNotStrip + public void requestRender(AnimationFrameCallback callback) { + mNodesManager.postOnAnimation(callback); + } + + @DoNotStrip + public String getReanimatedJavaVersion() { + return BuildConfig.REANIMATED_VERSION_JAVA; + } + + @DoNotStrip + @SuppressWarnings("unused") + // It turns out it's pretty difficult to set a member of a class + // instance through JNI so we decided to use a setter instead. + protected void setCppVersion(String version) { + cppVersion = version; + } + + protected void checkCppVersion() { + if (cppVersion == null) { + throw new RuntimeException( + "[Reanimated] Java side failed to resolve C++ code version. " + + "See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#java-side-failed-to-resolve-c-code-version for more information."); + } + String javaVersion = getReanimatedJavaVersion(); + if (!cppVersion.equals(javaVersion)) { + throw new RuntimeException( + "[Reanimated] Mismatch between Java code version and C++ code version (" + + javaVersion + + " vs. " + + cppVersion + + " respectively). See " + + "https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-java-code-version-and-c-code-version for more information."); + } + } + + @DoNotStrip + public void updateProps(int viewTag, Map props) { + mNodesManager.updateProps(viewTag, props); + } + + @DoNotStrip + public void synchronouslyUpdateUIProps(int viewTag, ReadableMap uiProps) { + mNodesManager.synchronouslyUpdateUIProps(viewTag, uiProps); + } + + @DoNotStrip + public String obtainProp(int viewTag, String propName) { + return mNodesManager.obtainProp(viewTag, propName); + } + + @DoNotStrip + public void scrollTo(int viewTag, double x, double y, boolean animated) { + mNodesManager.scrollTo(viewTag, x, y, animated); + } + + @DoNotStrip + public void dispatchCommand(int viewTag, String commandId, ReadableArray commandArgs) { + mNodesManager.dispatchCommand(viewTag, commandId, commandArgs); + } + + @DoNotStrip + public void setGestureState(int handlerTag, int newState) { + if (gestureHandlerStateManager != null) { + gestureHandlerStateManager.setGestureHandlerState(handlerTag, newState); + } + } + + @DoNotStrip + public long getAnimationTimestamp() { + if (slowAnimationsEnabled) { + final long ANIMATIONS_DRAG_FACTOR = 10; + return this.firstUptime + + (SystemClock.uptimeMillis() - this.firstUptime) / ANIMATIONS_DRAG_FACTOR; + } else { + return SystemClock.uptimeMillis(); + } + } + + @DoNotStrip + public float[] measure(int viewTag) { + return mNodesManager.measure(viewTag); + } + + @DoNotStrip + public void configureProps(ReadableNativeArray uiProps, ReadableNativeArray nativeProps) { + Set uiPropsSet = convertProps(uiProps); + Set nativePropsSet = convertProps(nativeProps); + mNodesManager.configureProps(uiPropsSet, nativePropsSet); + } + + private Set convertProps(ReadableNativeArray props) { + Set propsSet = new HashSet<>(); + ArrayList propsList = props.toArrayList(); + for (int i = 0; i < propsList.size(); i++) { + propsSet.add((String) propsList.get(i)); + } + return propsSet; + } + + @DoNotStrip + public void registerEventHandler(EventHandler handler) { + handler.mCustomEventNamesResolver = mNodesManager.getEventNameResolver(); + mNodesManager.registerEventHandler(handler); + } + + @DoNotStrip + public int registerSensor(int sensorType, int interval, SensorSetter setter) { + return reanimatedSensorContainer.registerSensor( + ReanimatedSensorType.getInstanceById(sensorType), interval, setter); + } + + @DoNotStrip + public void unregisterSensor(int sensorId) { + reanimatedSensorContainer.unregisterSensor(sensorId); + } + + @DoNotStrip + public int subscribeForKeyboardEvents( + KeyboardWorkletWrapper keyboardWorkletWrapper, boolean isStatusBarTranslucent) { + return keyboardAnimationManager.subscribeForKeyboardUpdates( + keyboardWorkletWrapper, isStatusBarTranslucent); + } + + @DoNotStrip + public void unsubscribeFromKeyboardEvents(int listenerId) { + keyboardAnimationManager.unsubscribeFromKeyboardUpdates(listenerId); + } + + protected abstract HybridData getHybridData(); + + public void invalidate() { + mAndroidUIScheduler.deactivate(); + } + + public void prepareLayoutAnimations(LayoutAnimations layoutAnimations) { + if (Utils.isChromeDebugger) { + Log.w("[REANIMATED]", "You can not use LayoutAnimation with enabled Chrome Debugger"); + return; + } + mNodesManager = mContext.get().getNativeModule(ReanimatedModule.class).getNodesManager(); + + AnimationsManager animationsManager = + mContext + .get() + .getNativeModule(ReanimatedModule.class) + .getNodesManager() + .getAnimationsManager(); + + animationsManager.setNativeMethods(NativeProxy.createNativeMethodsHolder(layoutAnimations)); + } + + @DoNotStrip + public boolean getIsReducedMotion() { + ContentResolver mContentResolver = mContext.get().getContentResolver(); + String rawValue = + Settings.Global.getString(mContentResolver, Settings.Global.TRANSITION_ANIMATION_SCALE); + float parsedValue = rawValue != null ? Float.parseFloat(rawValue) : 1f; + return parsedValue == 0f; + } + + @DoNotStrip + void maybeFlushUIUpdatesQueue() { + if (!mNodesManager.isAnimationRunning()) { + mNodesManager.performOperations(); + } + } +} From 69c89af7e9797d5cebc1085a416aef127b9b707b Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Mon, 13 May 2024 12:00:01 +0200 Subject: [PATCH 2/3] chore: move only the method to new class --- .../nativeProxy}/NativeProxyCommon.java | 14 +- .../swmansion/reanimated/DevMenuUtils.java | 18 ++ .../swmansion/reanimated/DevMenuUtils.java | 34 +++ .../reanimated/NativeProxyCommon.java | 276 ------------------ 4 files changed, 54 insertions(+), 288 deletions(-) rename android/src/{reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated => main/java/com/swmansion/reanimated/nativeProxy}/NativeProxyCommon.java (94%) create mode 100644 android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java create mode 100644 android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/DevMenuUtils.java delete mode 100644 android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/NativeProxyCommon.java diff --git a/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/NativeProxyCommon.java b/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java similarity index 94% rename from android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/NativeProxyCommon.java rename to android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java index 427b6c832bd4..05231d5db19b 100644 --- a/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/NativeProxyCommon.java +++ b/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java @@ -6,17 +6,16 @@ import android.util.Log; import com.facebook.jni.HybridData; import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.react.ReactApplication; import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReadableArray; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableNativeArray; -import com.facebook.react.devsupport.interfaces.DevSupportManager; import com.facebook.soloader.SoLoader; import com.swmansion.common.GestureHandlerStateManager; import com.swmansion.reanimated.AndroidUIScheduler; import com.swmansion.reanimated.BuildConfig; +import com.swmansion.reanimated.DevMenuUtils; import com.swmansion.reanimated.NativeProxy; import com.swmansion.reanimated.NodesManager; import com.swmansion.reanimated.ReanimatedModule; @@ -83,16 +82,7 @@ private void toggleSlowAnimations() { private void addDevMenuOption() { // In Expo, `ApplicationContext` is not an instance of `ReactApplication` - if (mContext.get().getApplicationContext() instanceof ReactApplication) { - final DevSupportManager devSupportManager = - ((ReactApplication) mContext.get().getApplicationContext()) - .getReactNativeHost() - .getReactInstanceManager() - .getDevSupportManager(); - - devSupportManager.addCustomDevOption( - "Toggle slow animations (Reanimated)", this::toggleSlowAnimations); - } + DevMenuUtils.addDevMenuOption(mContext.get(), this::toggleSlowAnimations); } @DoNotStrip diff --git a/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java b/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java new file mode 100644 index 000000000000..ba49554c0896 --- /dev/null +++ b/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java @@ -0,0 +1,18 @@ +package com.swmansion.reanimated; + +public class DevMenuUtils { + + private void addDevMenuOption(ReactApplicationContext context, , DevOptionHandler handler) { + // In Expo, `ApplicationContext` is not an instance of `ReactApplication` + if (context.get().getApplicationContext() instanceof ReactApplication) { + final DevSupportManager devSupportManager = + ((ReactApplication) context.get().getApplicationContext()) + .getReactNativeHost() + .getReactInstanceManager() + .getDevSupportManager(); + + devSupportManager.addCustomDevOption( + "Toggle slow animations (Reanimated)", handler); + } + } +} diff --git a/android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/DevMenuUtils.java b/android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/DevMenuUtils.java new file mode 100644 index 000000000000..36b14cee3b72 --- /dev/null +++ b/android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/DevMenuUtils.java @@ -0,0 +1,34 @@ +package com.swmansion.reanimated; + +import com.facebook.react.ReactApplication; +import com.facebook.react.bridge.ReactApplicationContext; +import com.facebook.react.devsupport.interfaces.DevOptionHandler; +import com.facebook.react.devsupport.interfaces.DevSupportManager; + +public class DevMenuUtils { + + public static void addDevMenuOption(ReactApplicationContext context, DevOptionHandler handler) { + // In Expo, `ApplicationContext` is not an instance of `ReactApplication` + if (context.getApplicationContext() instanceof ReactApplication) { + DevSupportManager devSupportManager; + if (context.isBridgeless()) { + devSupportManager = + ((ReactApplication) context.getApplicationContext()) + .getReactHost().getDevSupportManager(); + } else { + devSupportManager = + ((ReactApplication) context.getApplicationContext()) + .getReactNativeHost() + .getReactInstanceManager() + .getDevSupportManager(); + } + + if (devSupportManager != null) { + devSupportManager.addCustomDevOption( + "Toggle slow animations (Reanimated)", handler); + } else { + throw new RuntimeException("[Reanimated] DevSupportManager is not available"); + } + } + } +} diff --git a/android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/NativeProxyCommon.java b/android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/NativeProxyCommon.java deleted file mode 100644 index 11f8e5b06d9b..000000000000 --- a/android/src/reactNativeVersionPatch/ReactHost/latest/com/swmansion/reanimated/NativeProxyCommon.java +++ /dev/null @@ -1,276 +0,0 @@ -package com.swmansion.reanimated.nativeProxy; - -import android.content.ContentResolver; -import android.os.SystemClock; -import android.provider.Settings; -import android.util.Log; -import com.facebook.jni.HybridData; -import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.react.ReactApplication; -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReadableArray; -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.bridge.ReadableNativeArray; -import com.facebook.react.devsupport.interfaces.DevSupportManager; -import com.facebook.soloader.SoLoader; -import com.swmansion.common.GestureHandlerStateManager; -import com.swmansion.reanimated.AndroidUIScheduler; -import com.swmansion.reanimated.BuildConfig; -import com.swmansion.reanimated.NativeProxy; -import com.swmansion.reanimated.NodesManager; -import com.swmansion.reanimated.ReanimatedModule; -import com.swmansion.reanimated.Utils; -import com.swmansion.reanimated.keyboard.KeyboardAnimationManager; -import com.swmansion.reanimated.keyboard.KeyboardWorkletWrapper; -import com.swmansion.reanimated.layoutReanimation.AnimationsManager; -import com.swmansion.reanimated.layoutReanimation.LayoutAnimations; -import com.swmansion.reanimated.sensor.ReanimatedSensorContainer; -import com.swmansion.reanimated.sensor.ReanimatedSensorType; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public abstract class NativeProxyCommon { - static { - SoLoader.loadLibrary("reanimated"); - } - - protected NodesManager mNodesManager; - protected final WeakReference mContext; - protected AndroidUIScheduler mAndroidUIScheduler; - private ReanimatedSensorContainer reanimatedSensorContainer; - private final GestureHandlerStateManager gestureHandlerStateManager; - private KeyboardAnimationManager keyboardAnimationManager; - private Long firstUptime = SystemClock.uptimeMillis(); - private boolean slowAnimationsEnabled = false; - protected String cppVersion = null; - - protected NativeProxyCommon(ReactApplicationContext context) { - mAndroidUIScheduler = new AndroidUIScheduler(context); - mContext = new WeakReference<>(context); - reanimatedSensorContainer = new ReanimatedSensorContainer(mContext); - keyboardAnimationManager = new KeyboardAnimationManager(mContext); - addDevMenuOption(); - - GestureHandlerStateManager tempHandlerStateManager; - try { - Class gestureHandlerModuleClass = - (Class) - Class.forName("com.swmansion.gesturehandler.react.RNGestureHandlerModule"); - tempHandlerStateManager = - (GestureHandlerStateManager) context.getNativeModule(gestureHandlerModuleClass); - } catch (ClassCastException | ClassNotFoundException e) { - tempHandlerStateManager = null; - } - gestureHandlerStateManager = tempHandlerStateManager; - } - - protected native void installJSIBindings(); - - public AndroidUIScheduler getAndroidUIScheduler() { - return mAndroidUIScheduler; - } - - private void toggleSlowAnimations() { - slowAnimationsEnabled = !slowAnimationsEnabled; - if (slowAnimationsEnabled) { - firstUptime = SystemClock.uptimeMillis(); - } - } - - private void addDevMenuOption() { - // In Expo, `ApplicationContext` is not an instance of `ReactApplication` - if (mContext.get().getApplicationContext() instanceof ReactApplication) { - DevSupportManager devSupportManager; - if (mContext.get().isBridgeless()) { - devSupportManager = - ((ReactApplication) mContext.get().getApplicationContext()) - .getReactHost().getDevSupportManager(); - } else { - devSupportManager = - ((ReactApplication) mContext.get().getApplicationContext()) - .getReactNativeHost() - .getReactInstanceManager() - .getDevSupportManager(); - } - - if (devSupportManager != null) { - devSupportManager.addCustomDevOption( - "Toggle slow animations (Reanimated)", this::toggleSlowAnimations); - } else { - throw new RuntimeException("[Reanimated] DevSupportManager is not available"); - } - } - } - - @DoNotStrip - public void requestRender(AnimationFrameCallback callback) { - mNodesManager.postOnAnimation(callback); - } - - @DoNotStrip - public String getReanimatedJavaVersion() { - return BuildConfig.REANIMATED_VERSION_JAVA; - } - - @DoNotStrip - @SuppressWarnings("unused") - // It turns out it's pretty difficult to set a member of a class - // instance through JNI so we decided to use a setter instead. - protected void setCppVersion(String version) { - cppVersion = version; - } - - protected void checkCppVersion() { - if (cppVersion == null) { - throw new RuntimeException( - "[Reanimated] Java side failed to resolve C++ code version. " - + "See https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#java-side-failed-to-resolve-c-code-version for more information."); - } - String javaVersion = getReanimatedJavaVersion(); - if (!cppVersion.equals(javaVersion)) { - throw new RuntimeException( - "[Reanimated] Mismatch between Java code version and C++ code version (" - + javaVersion - + " vs. " - + cppVersion - + " respectively). See " - + "https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-java-code-version-and-c-code-version for more information."); - } - } - - @DoNotStrip - public void updateProps(int viewTag, Map props) { - mNodesManager.updateProps(viewTag, props); - } - - @DoNotStrip - public void synchronouslyUpdateUIProps(int viewTag, ReadableMap uiProps) { - mNodesManager.synchronouslyUpdateUIProps(viewTag, uiProps); - } - - @DoNotStrip - public String obtainProp(int viewTag, String propName) { - return mNodesManager.obtainProp(viewTag, propName); - } - - @DoNotStrip - public void scrollTo(int viewTag, double x, double y, boolean animated) { - mNodesManager.scrollTo(viewTag, x, y, animated); - } - - @DoNotStrip - public void dispatchCommand(int viewTag, String commandId, ReadableArray commandArgs) { - mNodesManager.dispatchCommand(viewTag, commandId, commandArgs); - } - - @DoNotStrip - public void setGestureState(int handlerTag, int newState) { - if (gestureHandlerStateManager != null) { - gestureHandlerStateManager.setGestureHandlerState(handlerTag, newState); - } - } - - @DoNotStrip - public long getAnimationTimestamp() { - if (slowAnimationsEnabled) { - final long ANIMATIONS_DRAG_FACTOR = 10; - return this.firstUptime - + (SystemClock.uptimeMillis() - this.firstUptime) / ANIMATIONS_DRAG_FACTOR; - } else { - return SystemClock.uptimeMillis(); - } - } - - @DoNotStrip - public float[] measure(int viewTag) { - return mNodesManager.measure(viewTag); - } - - @DoNotStrip - public void configureProps(ReadableNativeArray uiProps, ReadableNativeArray nativeProps) { - Set uiPropsSet = convertProps(uiProps); - Set nativePropsSet = convertProps(nativeProps); - mNodesManager.configureProps(uiPropsSet, nativePropsSet); - } - - private Set convertProps(ReadableNativeArray props) { - Set propsSet = new HashSet<>(); - ArrayList propsList = props.toArrayList(); - for (int i = 0; i < propsList.size(); i++) { - propsSet.add((String) propsList.get(i)); - } - return propsSet; - } - - @DoNotStrip - public void registerEventHandler(EventHandler handler) { - handler.mCustomEventNamesResolver = mNodesManager.getEventNameResolver(); - mNodesManager.registerEventHandler(handler); - } - - @DoNotStrip - public int registerSensor(int sensorType, int interval, SensorSetter setter) { - return reanimatedSensorContainer.registerSensor( - ReanimatedSensorType.getInstanceById(sensorType), interval, setter); - } - - @DoNotStrip - public void unregisterSensor(int sensorId) { - reanimatedSensorContainer.unregisterSensor(sensorId); - } - - @DoNotStrip - public int subscribeForKeyboardEvents( - KeyboardWorkletWrapper keyboardWorkletWrapper, boolean isStatusBarTranslucent) { - return keyboardAnimationManager.subscribeForKeyboardUpdates( - keyboardWorkletWrapper, isStatusBarTranslucent); - } - - @DoNotStrip - public void unsubscribeFromKeyboardEvents(int listenerId) { - keyboardAnimationManager.unsubscribeFromKeyboardUpdates(listenerId); - } - - protected abstract HybridData getHybridData(); - - public void invalidate() { - mAndroidUIScheduler.deactivate(); - } - - public void prepareLayoutAnimations(LayoutAnimations layoutAnimations) { - if (Utils.isChromeDebugger) { - Log.w("[REANIMATED]", "You can not use LayoutAnimation with enabled Chrome Debugger"); - return; - } - mNodesManager = mContext.get().getNativeModule(ReanimatedModule.class).getNodesManager(); - - AnimationsManager animationsManager = - mContext - .get() - .getNativeModule(ReanimatedModule.class) - .getNodesManager() - .getAnimationsManager(); - - animationsManager.setNativeMethods(NativeProxy.createNativeMethodsHolder(layoutAnimations)); - } - - @DoNotStrip - public boolean getIsReducedMotion() { - ContentResolver mContentResolver = mContext.get().getContentResolver(); - String rawValue = - Settings.Global.getString(mContentResolver, Settings.Global.TRANSITION_ANIMATION_SCALE); - float parsedValue = rawValue != null ? Float.parseFloat(rawValue) : 1f; - return parsedValue == 0f; - } - - @DoNotStrip - void maybeFlushUIUpdatesQueue() { - if (!mNodesManager.isAnimationRunning()) { - mNodesManager.performOperations(); - } - } -} From 7fcdd1ceb79be695787d8f11a8a6762348028e1a Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Mon, 13 May 2024 13:14:03 +0200 Subject: [PATCH 3/3] fix: v72 --- .../ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java b/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java index ba49554c0896..d39c8d6d78e9 100644 --- a/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java +++ b/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java @@ -2,11 +2,11 @@ public class DevMenuUtils { - private void addDevMenuOption(ReactApplicationContext context, , DevOptionHandler handler) { + private void addDevMenuOption(ReactApplicationContext context, DevOptionHandler handler) { // In Expo, `ApplicationContext` is not an instance of `ReactApplication` - if (context.get().getApplicationContext() instanceof ReactApplication) { + if (context.getApplicationContext() instanceof ReactApplication) { final DevSupportManager devSupportManager = - ((ReactApplication) context.get().getApplicationContext()) + ((ReactApplication) context.getApplicationContext()) .getReactNativeHost() .getReactInstanceManager() .getDevSupportManager();