react-native-reanimated 2.3.3 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +72 -0
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +30 -1
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +64 -39
- package/Common/cpp/Tools/RuntimeDecorator.cpp +2 -0
- package/Common/cpp/headers/AnimatedSensor/AnimatedSensorModule.h +41 -0
- package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +14 -0
- package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +14 -0
- package/Common/cpp/headers/SharedItems/MutableValue.h +4 -1
- package/Common/cpp/headers/SharedItems/ShareableValue.h +3 -0
- package/Common/cpp/headers/SharedItems/ValueWrapper.h +3 -0
- package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +11 -0
- package/Common/cpp/headers/Tools/RuntimeDecorator.h +2 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.2/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.2/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/7.2/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/CMakeLists.txt +198 -0
- package/android/README.md +15 -0
- package/android/build.gradle +686 -73
- package/android/empty.cpp +1 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +25 -0
- package/android/gradlew +234 -0
- package/android/gradlew.bat +89 -0
- package/android/react-native-reanimated-64-hermes.aar +0 -0
- package/android/react-native-reanimated-64-jsc.aar +0 -0
- package/android/react-native-reanimated-65-hermes.aar +0 -0
- package/android/react-native-reanimated-65-jsc.aar +0 -0
- package/android/react-native-reanimated-66-hermes.aar +0 -0
- package/android/react-native-reanimated-66-jsc.aar +0 -0
- package/android/react-native-reanimated-67-hermes.aar +0 -0
- package/android/react-native-reanimated-67-jsc.aar +0 -0
- package/android/react-native-reanimated-68-hermes.aar +0 -0
- package/android/react-native-reanimated-68-jsc.aar +0 -0
- package/android/rnVersionPatch/62/layoutReanimation/ReanimatedNativeHierarchyManager.java +412 -0
- package/android/rnVersionPatch/62/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- package/android/rnVersionPatch/65/.gitkeep +0 -0
- package/android/rnVersionPatch/66/.gitkeep +0 -0
- package/android/rnVersionPatch/67/.gitkeep +0 -0
- package/android/rnVersionPatch/68/.gitkeep +0 -0
- package/android/rnVersionPatch/backup/.gitkeep +0 -0
- package/android/settings.gradle +1 -0
- package/android/spotless.gradle +9 -0
- package/android/src/{AndroidManifest.xml → main/AndroidManifest.xml} +0 -0
- package/android/src/main/cpp/AndroidErrorHandler.cpp +42 -0
- package/android/src/main/cpp/AndroidLogger.cpp +27 -0
- package/android/src/main/cpp/AndroidScheduler.cpp +59 -0
- package/android/src/main/cpp/JNIHelper.cpp +59 -0
- package/android/src/main/cpp/LayoutAnimations.cpp +103 -0
- package/android/src/main/cpp/NativeProxy.cpp +327 -0
- package/android/src/main/cpp/OnLoad.cpp +17 -0
- package/android/src/main/cpp/TurboModule.cpp +44 -0
- package/android/src/main/cpp/headers/AndroidErrorHandler.h +30 -0
- package/android/src/main/cpp/headers/AndroidLogger.h +16 -0
- package/android/src/main/cpp/headers/AndroidScheduler.h +41 -0
- package/android/src/main/cpp/headers/JNIHelper.h +30 -0
- package/android/src/main/cpp/headers/LayoutAnimations.h +42 -0
- package/android/src/main/cpp/headers/NativeProxy.h +170 -0
- package/android/src/main/cpp/headers/TurboModule.h +70 -0
- package/android/src/main/java/com/facebook/react/uimanager/UIManagerReanimatedHelper.java +15 -0
- package/android/src/main/java/com/swmansion/common/GestureHandlerStateManager.java +5 -0
- package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +8 -0
- package/android/src/main/java/com/swmansion/reanimated/CopiedEvent.java +43 -0
- package/android/src/main/java/com/swmansion/reanimated/MapUtils.java +26 -0
- package/android/src/main/java/com/swmansion/reanimated/NativeMethodsHelper.java +117 -0
- package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +285 -0
- package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +682 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +29 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedModule.java +251 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +96 -0
- package/android/src/main/java/com/swmansion/reanimated/Scheduler.java +51 -0
- package/android/src/main/java/com/swmansion/reanimated/UpdateContext.java +11 -0
- package/android/src/main/java/com/swmansion/reanimated/Utils.java +32 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +517 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +56 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +11 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +410 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +292 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +121 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ViewHierarchyObserver.java +12 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/AlwaysNode.java +29 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/BezierNode.java +87 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/BlockNode.java +24 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/CallFuncNode.java +49 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ClockNode.java +38 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ClockOpNode.java +73 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ConcatNode.java +36 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/CondNode.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/DebugNode.java +33 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/EventNode.java +83 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/FinalNode.java +5 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/FunctionNode.java +20 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/JSCallNode.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/Node.java +139 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/NoopNode.java +37 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/OperatorNode.java +377 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ParamNode.java +71 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/PropsNode.java +153 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/SetNode.java +32 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/StyleNode.java +40 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/TransformNode.java +84 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ValueNode.java +40 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +40 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorType.java +35 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/ChangeTransition.java +84 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/SaneSidePropagation.java +25 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/Scale.java +86 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionModule.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionUtils.java +161 -0
- package/ios/LayoutReanimation/REAAnimationsManager.h +1 -1
- package/ios/LayoutReanimation/REAAnimationsManager.m +18 -4
- package/ios/REAModule.m +8 -9
- package/ios/REANodesManager.h +4 -1
- package/ios/REANodesManager.m +75 -3
- package/ios/native/NativeMethods.h +1 -1
- package/ios/native/NativeProxy.mm +85 -5
- package/ios/sensor/ReanimatedSensor.h +21 -0
- package/ios/sensor/ReanimatedSensor.m +169 -0
- package/ios/sensor/ReanimatedSensorContainer.h +13 -0
- package/ios/sensor/ReanimatedSensorContainer.m +41 -0
- package/ios/sensor/ReanimatedSensorType.h +7 -0
- package/lib/ConfigHelper.js +2 -2
- package/lib/createAnimatedComponent.js +3 -4
- package/lib/reanimated1/core/AnimatedFunction.js +1 -1
- package/lib/reanimated1/derived/interpolate.js +2 -4
- package/lib/reanimated2/Colors.js +3 -98
- package/lib/reanimated2/Easing.js +5 -0
- package/lib/reanimated2/NativeMethods.js +15 -5
- package/lib/reanimated2/NativeReanimated/NativeReanimated.js +25 -12
- package/lib/reanimated2/NativeReanimated/index.js +2 -6
- package/lib/reanimated2/ViewDescriptorsSet.js +2 -2
- package/lib/reanimated2/animation/styleAnimation.js +2 -1
- package/lib/reanimated2/core.js +30 -24
- package/lib/reanimated2/globals.d.ts +6 -0
- package/lib/reanimated2/hook/index.js +1 -0
- package/lib/reanimated2/hook/useAnimatedGestureHandler.js +1 -2
- package/lib/reanimated2/hook/useAnimatedSensor.js +66 -0
- package/lib/reanimated2/hook/useAnimatedStyle.js +31 -14
- package/lib/reanimated2/hook/utils.js +14 -11
- package/lib/reanimated2/index.js +2 -0
- package/lib/reanimated2/interpolateColor.js +98 -0
- package/lib/reanimated2/interpolation.js +1 -1
- package/lib/reanimated2/jestUtils.js +9 -4
- package/lib/reanimated2/js-reanimated/JSReanimated.js +24 -3
- package/lib/reanimated2/js-reanimated/commonTypes.js +1 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +8 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +2 -1
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +32 -42
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +20 -38
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +32 -44
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -16
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +6 -10
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +20 -36
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -20
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +8 -12
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +32 -48
- package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +22 -18
- package/lib/reanimated2/mock.js +3 -2
- package/mock.js +6 -4
- package/package.json +44 -36
- package/plugin.js +3 -0
- package/react-native-reanimated.d.ts +102 -15
- package/src/ConfigHelper.ts +4 -4
- package/src/createAnimatedComponent.tsx +3 -3
- package/src/reanimated1/core/AnimatedFunction.js +1 -1
- package/src/reanimated1/derived/interpolate.js +2 -4
- package/src/reanimated2/Colors.ts +8 -151
- package/src/reanimated2/Easing.ts +11 -0
- package/src/reanimated2/NativeMethods.ts +19 -6
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +42 -14
- package/src/reanimated2/NativeReanimated/index.ts +2 -8
- package/src/reanimated2/ViewDescriptorsSet.ts +2 -3
- package/src/reanimated2/animation/commonTypes.ts +44 -40
- package/src/reanimated2/animation/decay.ts +1 -1
- package/src/reanimated2/animation/delay.ts +2 -16
- package/src/reanimated2/animation/index.ts +8 -8
- package/src/reanimated2/animation/repeat.ts +2 -12
- package/src/reanimated2/animation/sequence.ts +3 -10
- package/src/reanimated2/animation/spring.ts +1 -1
- package/src/reanimated2/animation/styleAnimation.ts +11 -25
- package/src/reanimated2/animation/timing.ts +4 -2
- package/src/reanimated2/animation/util.ts +22 -20
- package/src/reanimated2/commonTypes.ts +68 -1
- package/src/reanimated2/component/FlatList.tsx +2 -1
- package/src/reanimated2/core.ts +35 -29
- package/src/reanimated2/globals.d.ts +6 -0
- package/src/reanimated2/hook/commonTypes.ts +5 -0
- package/src/reanimated2/hook/index.ts +1 -0
- package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -2
- package/src/reanimated2/hook/useAnimatedRef.ts +1 -5
- package/src/reanimated2/hook/useAnimatedSensor.ts +91 -0
- package/src/reanimated2/hook/useAnimatedStyle.ts +35 -16
- package/src/reanimated2/hook/utils.ts +20 -18
- package/src/reanimated2/index.ts +2 -0
- package/src/reanimated2/interpolateColor.ts +178 -0
- package/src/reanimated2/interpolation.ts +2 -6
- package/src/reanimated2/jestUtils.ts +9 -4
- package/src/reanimated2/js-reanimated/JSReanimated.ts +28 -6
- package/src/reanimated2/js-reanimated/Mapper.ts +1 -1
- package/src/reanimated2/js-reanimated/MapperRegistry.ts +1 -1
- package/src/reanimated2/js-reanimated/commonTypes.ts +51 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +13 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -3
- package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +51 -21
- package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +40 -10
- package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +48 -12
- package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +16 -4
- package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -2
- package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +16 -4
- package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +32 -8
- package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -10
- package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +16 -4
- package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +64 -16
- package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +32 -21
- package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +2 -1
- package/src/reanimated2/mock.ts +3 -2
- package/src/reanimated2/utils.ts +1 -1
- package/android/react-native-reanimated-63-hermes.aar +0 -0
- package/android/react-native-reanimated-63-jsc.aar +0 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedProxyPackage.java +0 -15
- package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
- package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
- package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
- package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
package com.swmansion.reanimated.layoutReanimation;
|
|
2
|
+
|
|
3
|
+
import android.util.DisplayMetrics;
|
|
4
|
+
import android.util.Log;
|
|
5
|
+
import android.view.View;
|
|
6
|
+
import android.view.ViewGroup;
|
|
7
|
+
import android.view.ViewParent;
|
|
8
|
+
import com.facebook.react.bridge.JavaOnlyMap;
|
|
9
|
+
import com.facebook.react.bridge.ReactContext;
|
|
10
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
11
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
12
|
+
import com.facebook.react.bridge.WritableMap;
|
|
13
|
+
import com.facebook.react.uimanager.IViewManagerWithChildren;
|
|
14
|
+
import com.facebook.react.uimanager.IllegalViewOperationException;
|
|
15
|
+
import com.facebook.react.uimanager.PixelUtil;
|
|
16
|
+
import com.facebook.react.uimanager.ReactStylesDiffMap;
|
|
17
|
+
import com.facebook.react.uimanager.RootView;
|
|
18
|
+
import com.facebook.react.uimanager.UIImplementation;
|
|
19
|
+
import com.facebook.react.uimanager.UIManagerModule;
|
|
20
|
+
import com.facebook.react.uimanager.ViewGroupManager;
|
|
21
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
22
|
+
import com.swmansion.reanimated.Scheduler;
|
|
23
|
+
import java.lang.ref.WeakReference;
|
|
24
|
+
import java.util.ArrayList;
|
|
25
|
+
import java.util.HashMap;
|
|
26
|
+
import java.util.HashSet;
|
|
27
|
+
import java.util.Map;
|
|
28
|
+
|
|
29
|
+
public class AnimationsManager implements ViewHierarchyObserver {
|
|
30
|
+
private static final String[] LAYOUT_KEYS = {
|
|
31
|
+
Snapshot.ORIGIN_X, Snapshot.ORIGIN_Y, Snapshot.WIDTH, Snapshot.HEIGHT
|
|
32
|
+
};
|
|
33
|
+
private WeakReference<Scheduler> mScheduler;
|
|
34
|
+
private ReactContext mContext;
|
|
35
|
+
private UIImplementation mUIImplementation;
|
|
36
|
+
private UIManagerModule mUIManager;
|
|
37
|
+
private NativeMethodsHolder mNativeMethodsHolder;
|
|
38
|
+
|
|
39
|
+
private HashMap<Integer, ViewState> mStates;
|
|
40
|
+
private HashMap<Integer, View> mViewForTag;
|
|
41
|
+
private HashSet<Integer> mToRemove;
|
|
42
|
+
private HashMap<Integer, ViewManager> mViewManager;
|
|
43
|
+
private HashMap<Integer, ViewManager> mParentViewManager;
|
|
44
|
+
private HashMap<Integer, View> mParent;
|
|
45
|
+
private HashMap<Integer, Runnable> mCallbacks;
|
|
46
|
+
private boolean mCleaningScheduled = false;
|
|
47
|
+
private ReanimatedNativeHierarchyManager mReanimatedNativeHierarchyManager;
|
|
48
|
+
private boolean isCatalystInstanceDestroyed = false;
|
|
49
|
+
|
|
50
|
+
public void setReanimatedNativeHierarchyManager(
|
|
51
|
+
ReanimatedNativeHierarchyManager reanimatedNativeHierarchyManager) {
|
|
52
|
+
this.mReanimatedNativeHierarchyManager = reanimatedNativeHierarchyManager;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public ReanimatedNativeHierarchyManager getReanimatedNativeHierarchyManager() {
|
|
56
|
+
return mReanimatedNativeHierarchyManager;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public void setScheduler(Scheduler scheduler) {
|
|
60
|
+
mScheduler = new WeakReference<>(scheduler);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public enum ViewState {
|
|
64
|
+
Inactive,
|
|
65
|
+
Appearing,
|
|
66
|
+
Disappearing,
|
|
67
|
+
Layout,
|
|
68
|
+
ToRemove;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public AnimationsManager(
|
|
72
|
+
ReactContext context, UIImplementation uiImplementation, UIManagerModule uiManagerModule) {
|
|
73
|
+
mContext = context;
|
|
74
|
+
mUIImplementation = uiImplementation;
|
|
75
|
+
mUIManager = uiManagerModule;
|
|
76
|
+
mStates = new HashMap<>();
|
|
77
|
+
mViewForTag = new HashMap<>();
|
|
78
|
+
mToRemove = new HashSet<>();
|
|
79
|
+
mViewManager = new HashMap<>();
|
|
80
|
+
mParentViewManager = new HashMap<>();
|
|
81
|
+
mParent = new HashMap();
|
|
82
|
+
mCallbacks = new HashMap<>();
|
|
83
|
+
isCatalystInstanceDestroyed = false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public void onCatalystInstanceDestroy() {
|
|
87
|
+
isCatalystInstanceDestroyed = true;
|
|
88
|
+
mNativeMethodsHolder = null;
|
|
89
|
+
mContext = null;
|
|
90
|
+
mUIImplementation = null;
|
|
91
|
+
mUIManager = null;
|
|
92
|
+
mStates = null;
|
|
93
|
+
mToRemove = null;
|
|
94
|
+
mViewForTag = null;
|
|
95
|
+
mViewManager = null;
|
|
96
|
+
mParent = null;
|
|
97
|
+
mParentViewManager = null;
|
|
98
|
+
mCallbacks = null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@Override
|
|
102
|
+
public void onViewRemoval(View view, ViewGroup parent, Snapshot before, Runnable callback) {
|
|
103
|
+
if (isCatalystInstanceDestroyed) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
Integer tag = view.getId();
|
|
107
|
+
HashMap<String, Object> currentValues = before.toCurrentMap();
|
|
108
|
+
ViewState state = mStates.get(view.getId());
|
|
109
|
+
|
|
110
|
+
if (state == ViewState.Disappearing || state == ViewState.ToRemove) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
mCallbacks.put(tag, callback);
|
|
114
|
+
if (state == ViewState.Inactive || state == null) {
|
|
115
|
+
if (currentValues != null) {
|
|
116
|
+
mStates.put(view.getId(), ViewState.ToRemove);
|
|
117
|
+
mToRemove.add(view.getId());
|
|
118
|
+
scheduleCleaning();
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
mStates.put(tag, ViewState.Disappearing);
|
|
123
|
+
HashMap<String, Float> preparedValues = prepareDataForAnimationWorklet(currentValues, false);
|
|
124
|
+
mNativeMethodsHolder.startAnimationForTag(tag, "exiting", preparedValues);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@Override
|
|
128
|
+
public void onViewCreate(View view, ViewGroup parent, Snapshot after) {
|
|
129
|
+
if (isCatalystInstanceDestroyed) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
Scheduler strongScheduler = mScheduler.get();
|
|
133
|
+
if (strongScheduler != null) {
|
|
134
|
+
strongScheduler.triggerUI();
|
|
135
|
+
}
|
|
136
|
+
if (!mStates.containsKey(view.getId())) {
|
|
137
|
+
mStates.put(view.getId(), ViewState.Inactive);
|
|
138
|
+
mViewForTag.put(view.getId(), view);
|
|
139
|
+
mViewManager.put(view.getId(), after.viewManager);
|
|
140
|
+
mParentViewManager.put(view.getId(), after.parentViewManager);
|
|
141
|
+
mParent.put(view.getId(), after.parent);
|
|
142
|
+
}
|
|
143
|
+
Integer tag = view.getId();
|
|
144
|
+
HashMap<String, Object> targetValues = after.toTargetMap();
|
|
145
|
+
ViewState state = mStates.get(view.getId());
|
|
146
|
+
|
|
147
|
+
if (state == ViewState.Inactive) { // it can be a fresh view
|
|
148
|
+
if (targetValues != null) {
|
|
149
|
+
HashMap<String, Float> preparedValues = prepareDataForAnimationWorklet(targetValues, true);
|
|
150
|
+
mNativeMethodsHolder.startAnimationForTag(tag, "entering", preparedValues);
|
|
151
|
+
}
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@Override
|
|
157
|
+
public void onViewUpdate(View view, Snapshot before, Snapshot after) {
|
|
158
|
+
if (isCatalystInstanceDestroyed) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
Integer tag = view.getId();
|
|
162
|
+
HashMap<String, Object> targetValues = after.toTargetMap();
|
|
163
|
+
HashMap<String, Object> startValues = before.toCurrentMap();
|
|
164
|
+
ViewState state = mStates.get(view.getId());
|
|
165
|
+
if (state == null
|
|
166
|
+
|| state == ViewState.Disappearing
|
|
167
|
+
|| state == ViewState.ToRemove
|
|
168
|
+
|| state == ViewState.Inactive) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
// If startValues are equal to targetValues it means that there was no UI Operation changing
|
|
172
|
+
// layout of the View. So dirtiness of that View is false positive
|
|
173
|
+
if (state == ViewState.Appearing) {
|
|
174
|
+
boolean doNotStartLayout = true;
|
|
175
|
+
for (int i = 0; i < Snapshot.targetKeysToTransform.size(); ++i) {
|
|
176
|
+
double startV =
|
|
177
|
+
((Number) startValues.get(Snapshot.currentKeysToTransform.get(i))).doubleValue();
|
|
178
|
+
double targetV =
|
|
179
|
+
((Number) targetValues.get(Snapshot.targetKeysToTransform.get(i))).doubleValue();
|
|
180
|
+
if (startV != targetV) {
|
|
181
|
+
doNotStartLayout = false;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (doNotStartLayout) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// View must be in Layout state
|
|
190
|
+
mStates.put(view.getId(), ViewState.Layout);
|
|
191
|
+
HashMap<String, Float> preparedStartValues = prepareDataForAnimationWorklet(startValues, false);
|
|
192
|
+
HashMap<String, Float> preparedTargetValues =
|
|
193
|
+
prepareDataForAnimationWorklet(targetValues, true);
|
|
194
|
+
HashMap<String, Float> preparedValues = new HashMap<>(preparedTargetValues);
|
|
195
|
+
for (String key : preparedStartValues.keySet()) {
|
|
196
|
+
preparedValues.put(key, preparedStartValues.get(key));
|
|
197
|
+
}
|
|
198
|
+
mNativeMethodsHolder.startAnimationForTag(tag, "layout", preparedValues);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public void notifyAboutProgress(Map<String, Object> newStyle, Integer tag) {
|
|
202
|
+
ViewState state = mStates.get(tag);
|
|
203
|
+
if (state == ViewState.Inactive) {
|
|
204
|
+
mStates.put(tag, ViewState.Appearing);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
setNewProps(
|
|
208
|
+
newStyle,
|
|
209
|
+
mViewForTag.get(tag),
|
|
210
|
+
mViewManager.get(tag),
|
|
211
|
+
mParentViewManager.get(tag),
|
|
212
|
+
mParent.get(tag).getId());
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
public void notifyAboutEnd(int tag, boolean cancelled) {
|
|
216
|
+
if (!cancelled) {
|
|
217
|
+
ViewState state = mStates.get(tag);
|
|
218
|
+
if (state == ViewState.Appearing) {
|
|
219
|
+
mStates.put(tag, ViewState.Layout);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (state == ViewState.Disappearing) {
|
|
223
|
+
mStates.put(tag, ViewState.ToRemove);
|
|
224
|
+
mToRemove.add(tag);
|
|
225
|
+
scheduleCleaning();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private void removeLeftovers() {
|
|
231
|
+
HashSet<Integer> roots = new HashSet<>();
|
|
232
|
+
// go through ready to remove from bottom to top
|
|
233
|
+
for (int tag : mToRemove) {
|
|
234
|
+
View view = mViewForTag.get(tag);
|
|
235
|
+
if (view == null) {
|
|
236
|
+
try {
|
|
237
|
+
view = mUIManager.resolveView(tag);
|
|
238
|
+
mViewForTag.put(tag, view);
|
|
239
|
+
} catch (IllegalViewOperationException ignored) {
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
findRoot(view, roots);
|
|
244
|
+
}
|
|
245
|
+
for (int tag : roots) {
|
|
246
|
+
View view = mViewForTag.get(tag);
|
|
247
|
+
if (view != null) {
|
|
248
|
+
dfs(view, view, mToRemove);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
public void printSubTree(View view, int level) {
|
|
254
|
+
if (level == 0) {
|
|
255
|
+
Log.v("rea", "----------------------");
|
|
256
|
+
}
|
|
257
|
+
if (view == null) {
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
StringBuilder out = new StringBuilder();
|
|
261
|
+
for (int i = 0; i < level; ++i) {
|
|
262
|
+
out.append("+");
|
|
263
|
+
}
|
|
264
|
+
out.append(" TAG:");
|
|
265
|
+
out.append(view.getId());
|
|
266
|
+
out.append(" STATE:");
|
|
267
|
+
out.append(this.mStates.get(view.getId()));
|
|
268
|
+
out.append(" CLASS:");
|
|
269
|
+
out.append(view.getClass().getSimpleName());
|
|
270
|
+
Log.v("rea", out.toString());
|
|
271
|
+
|
|
272
|
+
if (view instanceof ViewGroup) {
|
|
273
|
+
for (int i = 0; i < ((ViewGroup) view).getChildCount(); ++i) {
|
|
274
|
+
printSubTree(((ViewGroup) view).getChildAt(i), level + 1);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
private void scheduleCleaning() {
|
|
280
|
+
if (mCleaningScheduled) return;
|
|
281
|
+
mCleaningScheduled = true;
|
|
282
|
+
WeakReference<AnimationsManager> animationsManagerWeakReference = new WeakReference<>(this);
|
|
283
|
+
mContext.runOnUiQueueThread(
|
|
284
|
+
() -> {
|
|
285
|
+
mCleaningScheduled = false;
|
|
286
|
+
AnimationsManager thiz = animationsManagerWeakReference.get();
|
|
287
|
+
if (thiz == null) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
removeLeftovers();
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private void findRoot(View view, HashSet<Integer> roots) {
|
|
295
|
+
View currentView = view;
|
|
296
|
+
int lastToRemoveTag = -1;
|
|
297
|
+
while (currentView != null) {
|
|
298
|
+
ViewState state = mStates.get(currentView.getId());
|
|
299
|
+
if (state == ViewState.Disappearing) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (state == ViewState.ToRemove) {
|
|
303
|
+
lastToRemoveTag = currentView.getId();
|
|
304
|
+
}
|
|
305
|
+
if (currentView.getParent() instanceof View) {
|
|
306
|
+
currentView = (View) currentView.getParent();
|
|
307
|
+
} else {
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
if (lastToRemoveTag != -1) {
|
|
312
|
+
roots.add(lastToRemoveTag);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
private boolean dfs(View root, View view, HashSet<Integer> cands) {
|
|
317
|
+
if ((!cands.contains(view.getId())) && (mStates.containsKey(view.getId()))) {
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
boolean cannotStripe = false;
|
|
321
|
+
if (view instanceof ViewGroup && mViewManager.get(view.getId()) instanceof ViewGroupManager) {
|
|
322
|
+
ViewGroup vg = (ViewGroup) view;
|
|
323
|
+
ViewGroupManager vgm = (ViewGroupManager) mViewManager.get(vg.getId());
|
|
324
|
+
ArrayList<View> children = new ArrayList<>();
|
|
325
|
+
for (int i = 0; i < vgm.getChildCount(vg); ++i) {
|
|
326
|
+
children.add(vgm.getChildAt(vg, i));
|
|
327
|
+
}
|
|
328
|
+
for (View child : children) {
|
|
329
|
+
cannotStripe = cannotStripe || dfs(root, child, cands);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if (!cannotStripe) {
|
|
334
|
+
View parentView = (View) view.getParent();
|
|
335
|
+
if (mCallbacks.containsKey(view.getId())) {
|
|
336
|
+
Runnable runnable = mCallbacks.get(view.getId());
|
|
337
|
+
mCallbacks.remove(view.getId());
|
|
338
|
+
runnable.run();
|
|
339
|
+
}
|
|
340
|
+
if (mParent.containsKey(view.getId())) {
|
|
341
|
+
ViewGroup parent = (ViewGroup) mParent.get(view.getId());
|
|
342
|
+
if (parent != null) {
|
|
343
|
+
parent.removeView(view);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
View curView = view;
|
|
347
|
+
mStates.remove(curView.getId());
|
|
348
|
+
mViewForTag.remove(curView.getId());
|
|
349
|
+
mViewManager.remove(curView.getId());
|
|
350
|
+
mParentViewManager.remove(curView.getId());
|
|
351
|
+
mParent.remove(curView.getId());
|
|
352
|
+
mNativeMethodsHolder.removeConfigForTag(curView.getId());
|
|
353
|
+
mToRemove.remove(view.getId());
|
|
354
|
+
}
|
|
355
|
+
return cannotStripe;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
public HashMap<String, Float> prepareDataForAnimationWorklet(
|
|
359
|
+
HashMap<String, Object> values, boolean isTargetValues) {
|
|
360
|
+
HashMap<String, Float> preparedValues = new HashMap<>();
|
|
361
|
+
ArrayList<String> keys;
|
|
362
|
+
if (isTargetValues) {
|
|
363
|
+
keys = Snapshot.targetKeysToTransform;
|
|
364
|
+
} else {
|
|
365
|
+
keys = Snapshot.currentKeysToTransform;
|
|
366
|
+
}
|
|
367
|
+
for (String key : keys) {
|
|
368
|
+
preparedValues.put(key, PixelUtil.toDIPFromPixel((int) values.get(key)));
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
DisplayMetrics displaymetrics = new DisplayMetrics();
|
|
372
|
+
mContext.getCurrentActivity().getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
|
|
373
|
+
int height = displaymetrics.heightPixels;
|
|
374
|
+
int width = displaymetrics.widthPixels;
|
|
375
|
+
preparedValues.put("windowWidth", PixelUtil.toDIPFromPixel(width));
|
|
376
|
+
preparedValues.put("windowHeight", PixelUtil.toDIPFromPixel(height));
|
|
377
|
+
return preparedValues;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
public void setNativeMethods(NativeMethodsHolder nativeMethods) {
|
|
381
|
+
mNativeMethodsHolder = nativeMethods;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
public void setNewProps(
|
|
385
|
+
Map<String, Object> props,
|
|
386
|
+
View view,
|
|
387
|
+
ViewManager viewManager,
|
|
388
|
+
ViewManager parentViewManager,
|
|
389
|
+
Integer parentTag) {
|
|
390
|
+
float x =
|
|
391
|
+
(props.get(Snapshot.ORIGIN_X) != null)
|
|
392
|
+
? ((Double) props.get(Snapshot.ORIGIN_X)).floatValue()
|
|
393
|
+
: PixelUtil.toDIPFromPixel(view.getLeft());
|
|
394
|
+
float y =
|
|
395
|
+
(props.get(Snapshot.ORIGIN_Y) != null)
|
|
396
|
+
? ((Double) props.get(Snapshot.ORIGIN_Y)).floatValue()
|
|
397
|
+
: PixelUtil.toDIPFromPixel(view.getTop());
|
|
398
|
+
float width =
|
|
399
|
+
(props.get(Snapshot.WIDTH) != null)
|
|
400
|
+
? ((Double) props.get(Snapshot.WIDTH)).floatValue()
|
|
401
|
+
: PixelUtil.toDIPFromPixel(view.getWidth());
|
|
402
|
+
float height =
|
|
403
|
+
(props.get(Snapshot.HEIGHT) != null)
|
|
404
|
+
? ((Double) props.get(Snapshot.HEIGHT)).floatValue()
|
|
405
|
+
: PixelUtil.toDIPFromPixel(view.getHeight());
|
|
406
|
+
updateLayout(view, parentViewManager, parentTag, view.getId(), x, y, width, height);
|
|
407
|
+
props.remove(Snapshot.ORIGIN_X);
|
|
408
|
+
props.remove(Snapshot.ORIGIN_Y);
|
|
409
|
+
props.remove(Snapshot.WIDTH);
|
|
410
|
+
props.remove(Snapshot.HEIGHT);
|
|
411
|
+
|
|
412
|
+
if (props.size() == 0) {
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
JavaOnlyMap javaOnlyMap = new JavaOnlyMap();
|
|
417
|
+
for (String key : props.keySet()) {
|
|
418
|
+
addProp(javaOnlyMap, key, props.get(key));
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
viewManager.updateProperties(view, new ReactStylesDiffMap(javaOnlyMap));
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
private static void addProp(WritableMap propMap, String key, Object value) {
|
|
425
|
+
if (value == null) {
|
|
426
|
+
propMap.putNull(key);
|
|
427
|
+
} else if (value instanceof Double) {
|
|
428
|
+
propMap.putDouble(key, (Double) value);
|
|
429
|
+
} else if (value instanceof Integer) {
|
|
430
|
+
propMap.putInt(key, (Integer) value);
|
|
431
|
+
} else if (value instanceof Number) {
|
|
432
|
+
propMap.putDouble(key, ((Number) value).doubleValue());
|
|
433
|
+
} else if (value instanceof Boolean) {
|
|
434
|
+
propMap.putBoolean(key, (Boolean) value);
|
|
435
|
+
} else if (value instanceof String) {
|
|
436
|
+
propMap.putString(key, (String) value);
|
|
437
|
+
} else if (value instanceof ReadableArray) {
|
|
438
|
+
propMap.putArray(key, (ReadableArray) value);
|
|
439
|
+
} else if (value instanceof ReadableMap) {
|
|
440
|
+
propMap.putMap(key, (ReadableMap) value);
|
|
441
|
+
} else {
|
|
442
|
+
throw new IllegalStateException("Unknown type of animated value [Layout Aniamtions]");
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
public void updateLayout(
|
|
447
|
+
View viewToUpdate,
|
|
448
|
+
ViewManager parentViewManager,
|
|
449
|
+
int parentTag,
|
|
450
|
+
int tag,
|
|
451
|
+
float xf,
|
|
452
|
+
float yf,
|
|
453
|
+
float widthf,
|
|
454
|
+
float heightf) {
|
|
455
|
+
|
|
456
|
+
int x = Math.round(PixelUtil.toPixelFromDIP(xf));
|
|
457
|
+
int y = Math.round(PixelUtil.toPixelFromDIP(yf));
|
|
458
|
+
int width = Math.round(PixelUtil.toPixelFromDIP(widthf));
|
|
459
|
+
int height = Math.round(PixelUtil.toPixelFromDIP(heightf));
|
|
460
|
+
// Even though we have exact dimensions, we still call measure because some platform views
|
|
461
|
+
// (e.g.
|
|
462
|
+
// Switch) assume that method will always be called before onLayout and onDraw. They use it to
|
|
463
|
+
// calculate and cache information used in the draw pass. For most views, onMeasure can be
|
|
464
|
+
// stubbed out to only call setMeasuredDimensions. For ViewGroups, onLayout should be stubbed
|
|
465
|
+
// out to not recursively call layout on its children: React Native already handles doing
|
|
466
|
+
// that.
|
|
467
|
+
//
|
|
468
|
+
// Also, note measure and layout need to be called *after* all View properties have been
|
|
469
|
+
// updated
|
|
470
|
+
// because of caching and calculation that may occur in onMeasure and onLayout. Layout
|
|
471
|
+
// operations should also follow the native view hierarchy and go top to bottom for
|
|
472
|
+
// consistency
|
|
473
|
+
// with standard layout passes (some views may depend on this).
|
|
474
|
+
|
|
475
|
+
viewToUpdate.measure(
|
|
476
|
+
View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY),
|
|
477
|
+
View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
|
|
478
|
+
|
|
479
|
+
// We update the layout of the ReactRootView when there is a change in the layout of its
|
|
480
|
+
// child.
|
|
481
|
+
// This is required to re-measure the size of the native View container (usually a
|
|
482
|
+
// FrameLayout) that is configured with layout_height = WRAP_CONTENT or layout_width =
|
|
483
|
+
// WRAP_CONTENT
|
|
484
|
+
//
|
|
485
|
+
// This code is going to be executed ONLY when there is a change in the size of the Root
|
|
486
|
+
// View defined in the js side. Changes in the layout of inner views will not trigger an
|
|
487
|
+
// update
|
|
488
|
+
// on the layout of the Root View.
|
|
489
|
+
ViewParent parent = viewToUpdate.getParent();
|
|
490
|
+
if (parent instanceof RootView) {
|
|
491
|
+
parent.requestLayout();
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// Check if the parent of the view has to layout the view, or the child has to lay itself out.
|
|
495
|
+
if (parentTag % 10 == 1) { // ParentIsARoot
|
|
496
|
+
IViewManagerWithChildren parentViewManagerWithChildren;
|
|
497
|
+
if (parentViewManager instanceof IViewManagerWithChildren) {
|
|
498
|
+
parentViewManagerWithChildren = (IViewManagerWithChildren) parentViewManager;
|
|
499
|
+
} else {
|
|
500
|
+
throw new IllegalViewOperationException(
|
|
501
|
+
"Trying to use view with tag "
|
|
502
|
+
+ parentTag
|
|
503
|
+
+ " as a parent, but its Manager doesn't implement IViewManagerWithChildren");
|
|
504
|
+
}
|
|
505
|
+
if (parentViewManagerWithChildren != null
|
|
506
|
+
&& !parentViewManagerWithChildren.needsCustomLayoutForChildren()) {
|
|
507
|
+
viewToUpdate.layout(x, y, x + width, y + height);
|
|
508
|
+
}
|
|
509
|
+
} else {
|
|
510
|
+
viewToUpdate.layout(x, y, x + width, y + height);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
public boolean isLayoutAnimationEnabled() {
|
|
515
|
+
return mNativeMethodsHolder != null && mNativeMethodsHolder.isLayoutAnimationEnabled();
|
|
516
|
+
}
|
|
517
|
+
}
|
package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
package com.swmansion.reanimated.layoutReanimation;
|
|
2
|
+
|
|
3
|
+
import com.facebook.jni.HybridData;
|
|
4
|
+
import com.facebook.proguard.annotations.DoNotStrip;
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
+
import com.swmansion.reanimated.ReanimatedModule;
|
|
7
|
+
import java.lang.ref.WeakReference;
|
|
8
|
+
import java.util.Map;
|
|
9
|
+
|
|
10
|
+
public class LayoutAnimations {
|
|
11
|
+
static {
|
|
12
|
+
System.loadLibrary("reanimated");
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@DoNotStrip
|
|
16
|
+
@SuppressWarnings("unused")
|
|
17
|
+
private final HybridData mHybridData;
|
|
18
|
+
|
|
19
|
+
private WeakReference<ReactApplicationContext> mContext;
|
|
20
|
+
|
|
21
|
+
public LayoutAnimations(ReactApplicationContext context) {
|
|
22
|
+
mContext = new WeakReference<>(context);
|
|
23
|
+
mHybridData = initHybrid();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
private native HybridData initHybrid();
|
|
27
|
+
|
|
28
|
+
// LayoutReanimation
|
|
29
|
+
public native void startAnimationForTag(int tag, String type, Map<String, String> values);
|
|
30
|
+
|
|
31
|
+
public native void removeConfigForTag(int tag);
|
|
32
|
+
|
|
33
|
+
public native boolean isLayoutAnimationEnabled();
|
|
34
|
+
|
|
35
|
+
private void notifyAboutEnd(int tag, int cancelledInt) {
|
|
36
|
+
ReactApplicationContext context = mContext.get();
|
|
37
|
+
if (context != null) {
|
|
38
|
+
context
|
|
39
|
+
.getNativeModule(ReanimatedModule.class)
|
|
40
|
+
.getNodesManager()
|
|
41
|
+
.getAnimationsManager()
|
|
42
|
+
.notifyAboutEnd(tag, (cancelledInt == 0) ? false : true);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private void notifyAboutProgress(Map<String, Object> newStyle, int tag) {
|
|
47
|
+
ReactApplicationContext context = mContext.get();
|
|
48
|
+
if (context != null) {
|
|
49
|
+
context
|
|
50
|
+
.getNativeModule(ReanimatedModule.class)
|
|
51
|
+
.getNodesManager()
|
|
52
|
+
.getAnimationsManager()
|
|
53
|
+
.notifyAboutProgress(newStyle, tag);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
package com.swmansion.reanimated.layoutReanimation;
|
|
2
|
+
|
|
3
|
+
import java.util.HashMap;
|
|
4
|
+
|
|
5
|
+
public interface NativeMethodsHolder {
|
|
6
|
+
public void startAnimationForTag(int tag, String type, HashMap<String, Float> values);
|
|
7
|
+
|
|
8
|
+
public void removeConfigForTag(int tag);
|
|
9
|
+
|
|
10
|
+
public boolean isLayoutAnimationEnabled();
|
|
11
|
+
}
|