react-native-reanimated 3.0.0-rc.8 → 3.0.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 +30 -12
- package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +2 -0
- package/Common/cpp/Fabric/FabricUtils.cpp +3 -107
- package/Common/cpp/Fabric/FabricUtils.h +3 -24
- package/Common/cpp/Fabric/ReanimatedUIManagerBinding.cpp +54 -37
- package/Common/cpp/LayoutAnimations/LayoutAnimationType.h +8 -0
- package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +81 -26
- package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +20 -3
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +122 -121
- package/Common/cpp/NativeModules/NativeReanimatedModule.h +21 -14
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +15 -7
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +8 -4
- package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.cpp +50 -1
- package/Common/cpp/ReanimatedRuntime/ReanimatedHermesRuntime.h +10 -1
- package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +5 -1
- package/Common/cpp/Registries/EventHandlerRegistry.cpp +8 -34
- package/Common/cpp/Registries/EventHandlerRegistry.h +7 -13
- package/Common/cpp/SharedItems/Shareables.cpp +11 -63
- package/Common/cpp/SharedItems/Shareables.h +113 -93
- package/Common/cpp/Tools/CollectionUtils.h +14 -0
- package/Common/cpp/Tools/JsiUtils.cpp +26 -0
- package/Common/cpp/Tools/JsiUtils.h +176 -0
- package/Common/cpp/Tools/PlatformDepMethodsHolder.h +5 -5
- package/Common/cpp/Tools/ReanimatedVersion.cpp +17 -0
- package/Common/cpp/Tools/ReanimatedVersion.h +11 -0
- package/Common/cpp/Tools/RuntimeDecorator.cpp +67 -247
- package/Common/cpp/Tools/RuntimeDecorator.h +2 -3
- package/Common/cpp/Tools/WorkletEventHandler.cpp +3 -2
- package/Common/cpp/Tools/WorkletEventHandler.h +14 -6
- package/RNReanimated.podspec +2 -1
- package/android/CMakeLists.txt +188 -181
- package/android/build.gradle +362 -311
- package/android/proguard-rules.pro +2 -0
- package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +63 -295
- package/android/src/main/cpp/LayoutAnimations.cpp +35 -5
- package/android/src/main/cpp/LayoutAnimations.h +23 -6
- package/android/src/main/cpp/NativeProxy.cpp +143 -98
- package/android/src/main/cpp/NativeProxy.h +22 -28
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +5 -4
- package/android/src/main/java/com/swmansion/reanimated/Utils.java +7 -1
- package/android/src/main/java/com/swmansion/reanimated/keyboardObserver/ReanimatedKeyboardEventListener.java +10 -3
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +218 -35
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +43 -17
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +6 -2
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedElement.java +19 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/SharedTransitionManager.java +610 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +93 -23
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/AnimationFrameCallback.java +19 -0
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/EventHandler.java +35 -0
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/KeyboardEventDataUpdater.java +16 -0
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java +206 -0
- package/android/src/main/java/com/swmansion/reanimated/nativeProxy/SensorSetter.java +17 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +9 -3
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +3 -4
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -7
- package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +90 -307
- package/android/src/reactNativeVersionPatch/ReanimatedUIManager/70/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +16 -0
- package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/ReanimatedUIManagerFactory.java +63 -0
- package/android/src/reactNativeVersionPatch/ReanimatedUIManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +271 -0
- package/android/src/reactNativeVersionPatch/nativeHierarchyManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +76 -20
- package/ios/LayoutReanimation/REAAnimationsManager.h +31 -5
- package/ios/LayoutReanimation/REAAnimationsManager.m +265 -77
- package/ios/LayoutReanimation/REAFrame.h +10 -0
- package/ios/LayoutReanimation/REAFrame.m +15 -0
- package/ios/LayoutReanimation/REAScreensHelper.h +19 -0
- package/ios/LayoutReanimation/REAScreensHelper.m +106 -0
- package/ios/LayoutReanimation/REASharedElement.h +15 -0
- package/ios/LayoutReanimation/REASharedElement.m +16 -0
- package/ios/LayoutReanimation/REASharedTransitionManager.h +17 -0
- package/ios/LayoutReanimation/REASharedTransitionManager.m +632 -0
- package/ios/LayoutReanimation/REASnapshot.h +1 -0
- package/ios/LayoutReanimation/REASnapshot.m +96 -11
- package/ios/LayoutReanimation/REAUIManager.mm +67 -60
- package/ios/REAModule.mm +2 -7
- package/ios/REANodesManager.mm +1 -21
- package/ios/keyboardObserver/REAKeyboardEventObserver.m +72 -36
- package/ios/native/NativeProxy.mm +75 -114
- package/ios/native/REAInitializer.mm +2 -7
- package/ios/native/REAJSIUtils.h +60 -2
- package/ios/sensor/ReanimatedSensor.h +6 -2
- package/ios/sensor/ReanimatedSensor.m +43 -7
- package/ios/sensor/ReanimatedSensorContainer.h +4 -1
- package/ios/sensor/ReanimatedSensorContainer.m +8 -2
- package/lib/commonjs/createAnimatedComponent.js +232 -28
- package/lib/commonjs/createAnimatedComponent.js.map +1 -1
- package/lib/commonjs/reanimated2/Colors.js +43 -22
- package/lib/commonjs/reanimated2/Colors.js.map +1 -1
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +18 -35
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/styleAnimation.js +5 -1
- package/lib/commonjs/reanimated2/animation/styleAnimation.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/util.js +17 -15
- package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
- package/lib/commonjs/reanimated2/commonTypes.js +33 -1
- package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/component/FlatList.js +19 -3
- package/lib/commonjs/reanimated2/component/FlatList.js.map +1 -1
- package/lib/commonjs/reanimated2/core.js +34 -83
- package/lib/commonjs/reanimated2/core.js.map +1 -1
- package/lib/commonjs/reanimated2/errors.js +66 -0
- package/lib/commonjs/reanimated2/errors.js.map +1 -0
- package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
- package/lib/commonjs/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
- package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/index.js +0 -6
- package/lib/commonjs/reanimated2/hook/index.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +5 -2
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js +13 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedReaction.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +89 -16
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +43 -50
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useDerivedValue.js +13 -1
- package/lib/commonjs/reanimated2/hook/useDerivedValue.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js +2 -2
- package/lib/commonjs/reanimated2/hook/useScrollViewOffset.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/utils.js +18 -65
- package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
- package/lib/commonjs/reanimated2/index.js +13 -0
- package/lib/commonjs/reanimated2/index.js.map +1 -1
- package/lib/commonjs/reanimated2/initializers.js +196 -0
- package/lib/commonjs/reanimated2/initializers.js.map +1 -0
- package/lib/commonjs/reanimated2/interpolateColor.js +96 -19
- package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
- package/lib/commonjs/reanimated2/jestUtils.js +1 -1
- package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +101 -16
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/Mapper.js +22 -0
- package/lib/commonjs/reanimated2/js-reanimated/Mapper.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js +2 -0
- package/lib/commonjs/reanimated2/js-reanimated/WebSensor.js.map +1 -0
- package/lib/commonjs/reanimated2/js-reanimated/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/global.js +4 -9
- package/lib/commonjs/reanimated2/js-reanimated/global.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/index.js +0 -1
- package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +11 -0
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js +8 -0
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +16 -12
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -23
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -14
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -14
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -15
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -23
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/index.js +13 -0
- package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js +94 -0
- package/lib/commonjs/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
- package/lib/commonjs/reanimated2/mappers.js +18 -6
- package/lib/commonjs/reanimated2/mappers.js.map +1 -1
- package/lib/commonjs/reanimated2/mock.js +45 -0
- package/lib/commonjs/reanimated2/mock.js.map +1 -1
- package/lib/commonjs/reanimated2/mutables.js +4 -2
- package/lib/commonjs/reanimated2/mutables.js.map +1 -1
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +42 -0
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +1 -0
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js +15 -0
- package/lib/commonjs/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
- package/lib/commonjs/reanimated2/pluginUtils.js +11 -0
- package/lib/commonjs/reanimated2/pluginUtils.js.map +1 -0
- package/lib/commonjs/reanimated2/shareables.js +38 -11
- package/lib/commonjs/reanimated2/shareables.js.map +1 -1
- package/lib/commonjs/reanimated2/threads.js +114 -4
- package/lib/commonjs/reanimated2/threads.js.map +1 -1
- package/lib/commonjs/reanimated2/utils.js +7 -0
- package/lib/commonjs/reanimated2/utils.js.map +1 -1
- package/lib/commonjs/reanimated2/valueSetter.js +1 -3
- package/lib/commonjs/reanimated2/valueSetter.js.map +1 -1
- package/lib/module/createAnimatedComponent.js +229 -29
- package/lib/module/createAnimatedComponent.js.map +1 -1
- package/lib/module/reanimated2/Colors.js +35 -19
- package/lib/module/reanimated2/Colors.js.map +1 -1
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +18 -34
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/module/reanimated2/animation/styleAnimation.js +5 -1
- package/lib/module/reanimated2/animation/styleAnimation.js.map +1 -1
- package/lib/module/reanimated2/animation/util.js +17 -16
- package/lib/module/reanimated2/animation/util.js.map +1 -1
- package/lib/module/reanimated2/commonTypes.js +29 -0
- package/lib/module/reanimated2/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/component/FlatList.js +18 -4
- package/lib/module/reanimated2/component/FlatList.js.map +1 -1
- package/lib/module/reanimated2/core.js +30 -76
- package/lib/module/reanimated2/core.js.map +1 -1
- package/lib/module/reanimated2/errors.js +58 -0
- package/lib/module/reanimated2/errors.js.map +1 -0
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js +2 -2
- package/lib/module/reanimated2/frameCallback/FrameCallbackRegistryUI.js.map +1 -1
- package/lib/module/reanimated2/globals.d.js.map +1 -1
- package/lib/module/reanimated2/hook/index.js +1 -1
- package/lib/module/reanimated2/hook/index.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +5 -2
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedReaction.js +12 -1
- package/lib/module/reanimated2/hook/useAnimatedReaction.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedRef.js +2 -2
- package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedSensor.js +88 -13
- package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedStyle.js +45 -52
- package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/module/reanimated2/hook/useDerivedValue.js +12 -1
- package/lib/module/reanimated2/hook/useDerivedValue.js.map +1 -1
- package/lib/module/reanimated2/hook/useScrollViewOffset.js +2 -2
- package/lib/module/reanimated2/hook/useScrollViewOffset.js.map +1 -1
- package/lib/module/reanimated2/hook/utils.js +17 -60
- package/lib/module/reanimated2/hook/utils.js.map +1 -1
- package/lib/module/reanimated2/index.js +1 -0
- package/lib/module/reanimated2/index.js.map +1 -1
- package/lib/module/reanimated2/initializers.js +182 -0
- package/lib/module/reanimated2/initializers.js.map +1 -0
- package/lib/module/reanimated2/interpolateColor.js +96 -19
- package/lib/module/reanimated2/interpolateColor.js.map +1 -1
- package/lib/module/reanimated2/jestUtils.js +1 -1
- package/lib/module/reanimated2/jestUtils.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js +101 -16
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/Mapper.js +21 -0
- package/lib/module/reanimated2/js-reanimated/Mapper.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/WebSensor.js +2 -0
- package/lib/module/reanimated2/js-reanimated/WebSensor.js.map +1 -0
- package/lib/module/reanimated2/js-reanimated/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/global.js +4 -9
- package/lib/module/reanimated2/js-reanimated/global.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/index.js +0 -1
- package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +9 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js +1 -0
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js +15 -10
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +16 -21
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Bounce.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -12
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Roll.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js +8 -13
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Slide.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +16 -21
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Zoom.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/index.js +1 -0
- package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js +82 -0
- package/lib/module/reanimated2/layoutReanimation/sharedTransitions/index.js.map +1 -0
- package/lib/module/reanimated2/mappers.js +16 -6
- package/lib/module/reanimated2/mappers.js.map +1 -1
- package/lib/module/reanimated2/mock.js +45 -0
- package/lib/module/reanimated2/mock.js.map +1 -1
- package/lib/module/reanimated2/mutables.js +4 -2
- package/lib/module/reanimated2/mutables.js.map +1 -1
- package/lib/module/reanimated2/platform-specific/checkVersion.js +35 -0
- package/lib/module/reanimated2/platform-specific/checkVersion.js.map +1 -0
- package/lib/module/reanimated2/platform-specific/checkVersion.web.js +8 -0
- package/lib/module/reanimated2/platform-specific/checkVersion.web.js.map +1 -0
- package/lib/module/reanimated2/pluginUtils.js +4 -0
- package/lib/module/reanimated2/pluginUtils.js.map +1 -0
- package/lib/module/reanimated2/shareables.js +38 -9
- package/lib/module/reanimated2/shareables.js.map +1 -1
- package/lib/module/reanimated2/threads.js +105 -4
- package/lib/module/reanimated2/threads.js.map +1 -1
- package/lib/module/reanimated2/utils.js +5 -0
- package/lib/module/reanimated2/utils.js.map +1 -1
- package/lib/module/reanimated2/valueSetter.js +1 -2
- package/lib/module/reanimated2/valueSetter.js.map +1 -1
- package/package.json +9 -8
- package/{plugin.js → plugin/index.js} +173 -228
- package/react-native-reanimated.d.ts +57 -10
- package/scripts/reanimated_utils.rb +15 -2
- package/src/createAnimatedComponent.tsx +238 -28
- package/src/reanimated2/Colors.ts +38 -11
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +63 -41
- package/src/reanimated2/animation/styleAnimation.ts +8 -1
- package/src/reanimated2/animation/util.ts +29 -16
- package/src/reanimated2/commonTypes.ts +28 -1
- package/src/reanimated2/component/FlatList.tsx +30 -5
- package/src/reanimated2/core.ts +45 -75
- package/src/reanimated2/errors.ts +57 -0
- package/src/reanimated2/frameCallback/FrameCallbackRegistryUI.ts +2 -2
- package/src/reanimated2/globals.d.ts +34 -18
- package/src/reanimated2/hook/index.ts +1 -1
- package/src/reanimated2/hook/useAnimatedKeyboard.ts +10 -4
- package/src/reanimated2/hook/useAnimatedReaction.ts +12 -5
- package/src/reanimated2/hook/useAnimatedRef.ts +1 -4
- package/src/reanimated2/hook/useAnimatedSensor.ts +88 -11
- package/src/reanimated2/hook/useAnimatedStyle.ts +43 -45
- package/src/reanimated2/hook/useDerivedValue.ts +8 -1
- package/src/reanimated2/hook/useScrollViewOffset.ts +2 -2
- package/src/reanimated2/hook/utils.ts +15 -61
- package/src/reanimated2/index.ts +1 -0
- package/src/reanimated2/initializers.ts +184 -0
- package/src/reanimated2/interpolateColor.ts +104 -20
- package/src/reanimated2/jestUtils.ts +1 -1
- package/src/reanimated2/js-reanimated/JSReanimated.ts +105 -18
- package/src/reanimated2/js-reanimated/Mapper.ts +32 -0
- package/src/reanimated2/js-reanimated/WebSensor.ts +34 -0
- package/src/reanimated2/js-reanimated/commonTypes.ts +0 -1
- package/src/reanimated2/js-reanimated/global.ts +4 -8
- package/src/reanimated2/js-reanimated/index.ts +0 -1
- package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +13 -1
- package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
- package/src/reanimated2/layoutReanimation/animationsManager.ts +17 -12
- package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +16 -19
- package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +14 -11
- package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +21 -11
- package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -11
- package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +36 -19
- package/src/reanimated2/layoutReanimation/index.ts +1 -0
- package/src/reanimated2/layoutReanimation/sharedTransitions/index.ts +87 -0
- package/src/reanimated2/mappers.ts +17 -6
- package/src/reanimated2/mock.ts +128 -0
- package/src/reanimated2/mutables.ts +2 -0
- package/src/reanimated2/platform-specific/checkVersion.ts +39 -0
- package/src/reanimated2/platform-specific/checkVersion.web.ts +6 -0
- package/src/reanimated2/pluginUtils.ts +8 -0
- package/src/reanimated2/shareables.ts +47 -11
- package/src/reanimated2/threads.ts +103 -1
- package/src/reanimated2/utils.ts +6 -0
- package/src/reanimated2/valueSetter.ts +1 -2
- package/lib/commonjs/reanimated2/time.js +0 -55
- package/lib/commonjs/reanimated2/time.js.map +0 -1
- package/lib/module/reanimated2/time.js +0 -37
- package/lib/module/reanimated2/time.js.map +0 -1
- package/src/reanimated2/time.ts +0 -30
- /package/android/src/{main/java → reactNativeVersionPatch/ReanimatedUIManager/70}/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +0 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
#import <RNReanimated/REAFrame.h>
|
|
2
|
+
#import <RNReanimated/REAScreensHelper.h>
|
|
3
|
+
#import <RNReanimated/REASharedElement.h>
|
|
4
|
+
#import <RNReanimated/REASharedTransitionManager.h>
|
|
5
|
+
#import <objc/runtime.h>
|
|
6
|
+
|
|
7
|
+
@implementation REASharedTransitionManager {
|
|
8
|
+
NSMutableDictionary<NSNumber *, UIView *> *_sharedTransitionParent;
|
|
9
|
+
NSMutableDictionary<NSNumber *, NSNumber *> *_sharedTransitionInParentIndex;
|
|
10
|
+
NSMutableDictionary<NSNumber *, REASnapshot *> *_snapshotRegistry;
|
|
11
|
+
NSMutableDictionary<NSNumber *, UIView *> *_currentSharedTransitionViews;
|
|
12
|
+
REAFindPrecedingViewTagForTransitionBlock _findPrecedingViewTagForTransition;
|
|
13
|
+
REACancelAnimationBlock _cancelLayoutAnimation;
|
|
14
|
+
UIView *_transitionContainer;
|
|
15
|
+
NSMutableArray<UIView *> *_addedSharedViews;
|
|
16
|
+
BOOL _isSharedTransitionActive;
|
|
17
|
+
NSMutableArray<REASharedElement *> *_sharedElements;
|
|
18
|
+
REAAnimationsManager *_animationManager;
|
|
19
|
+
NSMutableSet<NSNumber *> *_viewsToHide;
|
|
20
|
+
NSMutableArray<UIView *> *_removedViews;
|
|
21
|
+
NSMutableSet<UIView *> *_viewsWithCanceledAnimation;
|
|
22
|
+
NSMutableDictionary<NSNumber *, NSNumber *> *_disableCleaningForView;
|
|
23
|
+
NSMutableSet<NSNumber *> *_layoutedSharedViewsTags;
|
|
24
|
+
NSMutableDictionary<NSNumber *, REAFrame *> *_layoutedSharedViewsFrame;
|
|
25
|
+
BOOL _isAsyncSharedTransitionConfigured;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
`_sharedTransitionManager` provides access to current REASharedTransitionManager
|
|
30
|
+
instance from swizzled methods in react-native-screens. Swizzled method has
|
|
31
|
+
different context of execution (self != REASharedTransitionManager)
|
|
32
|
+
*/
|
|
33
|
+
static REASharedTransitionManager *_sharedTransitionManager;
|
|
34
|
+
|
|
35
|
+
- (instancetype)initWithAnimationsManager:(REAAnimationsManager *)animationManager
|
|
36
|
+
{
|
|
37
|
+
if (self = [super init]) {
|
|
38
|
+
_snapshotRegistry = [NSMutableDictionary new];
|
|
39
|
+
_currentSharedTransitionViews = [NSMutableDictionary new];
|
|
40
|
+
_addedSharedViews = [NSMutableArray new];
|
|
41
|
+
_sharedTransitionParent = [NSMutableDictionary new];
|
|
42
|
+
_sharedTransitionInParentIndex = [NSMutableDictionary new];
|
|
43
|
+
_isSharedTransitionActive = NO;
|
|
44
|
+
_sharedElements = [NSMutableArray new];
|
|
45
|
+
_animationManager = animationManager;
|
|
46
|
+
_viewsToHide = [NSMutableSet new];
|
|
47
|
+
_sharedTransitionManager = self;
|
|
48
|
+
_viewsWithCanceledAnimation = [NSMutableSet new];
|
|
49
|
+
_disableCleaningForView = [NSMutableDictionary new];
|
|
50
|
+
_layoutedSharedViewsTags = [NSMutableSet new];
|
|
51
|
+
_layoutedSharedViewsFrame = [NSMutableDictionary new];
|
|
52
|
+
_isAsyncSharedTransitionConfigured = NO;
|
|
53
|
+
[self swizzleScreensMethods];
|
|
54
|
+
}
|
|
55
|
+
return self;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
- (void)invalidate
|
|
59
|
+
{
|
|
60
|
+
_snapshotRegistry = nil;
|
|
61
|
+
_currentSharedTransitionViews = nil;
|
|
62
|
+
_addedSharedViews = nil;
|
|
63
|
+
_sharedTransitionParent = nil;
|
|
64
|
+
_sharedTransitionInParentIndex = nil;
|
|
65
|
+
_sharedElements = nil;
|
|
66
|
+
_animationManager = nil;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
- (UIView *)getTransitioningView:(NSNumber *)tag
|
|
70
|
+
{
|
|
71
|
+
return _currentSharedTransitionViews[tag];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
- (void)notifyAboutNewView:(UIView *)view
|
|
75
|
+
{
|
|
76
|
+
[_addedSharedViews addObject:view];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
- (void)notifyAboutViewLayout:(UIView *)view withViewFrame:(CGRect)frame
|
|
80
|
+
{
|
|
81
|
+
[_layoutedSharedViewsTags addObject:view.reactTag];
|
|
82
|
+
float x = frame.origin.x;
|
|
83
|
+
float y = frame.origin.y;
|
|
84
|
+
float width = frame.size.width;
|
|
85
|
+
float height = frame.size.height;
|
|
86
|
+
_layoutedSharedViewsFrame[view.reactTag] = [[REAFrame alloc] initWithX:x y:y width:width height:height];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
- (void)viewsDidLayout
|
|
90
|
+
{
|
|
91
|
+
[self configureAsyncSharedTransitionForViews:_addedSharedViews];
|
|
92
|
+
[_addedSharedViews removeAllObjects];
|
|
93
|
+
[self maybeRestartAnimationWithNewLayout];
|
|
94
|
+
[_layoutedSharedViewsTags removeAllObjects];
|
|
95
|
+
[_layoutedSharedViewsFrame removeAllObjects];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
- (void)configureAsyncSharedTransitionForViews:(NSArray<UIView *> *)views
|
|
99
|
+
{
|
|
100
|
+
if ([views count] > 0) {
|
|
101
|
+
NSArray *sharedViews = [self sortViewsByTags:views];
|
|
102
|
+
_sharedElements = [self getSharedElementForCurrentTransition:sharedViews withNewElements:YES];
|
|
103
|
+
_isAsyncSharedTransitionConfigured = YES;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
- (void)maybeRestartAnimationWithNewLayout
|
|
108
|
+
{
|
|
109
|
+
if ([_layoutedSharedViewsTags count] == 0 || [_currentSharedTransitionViews count] == 0) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
NSMutableArray<REASharedElement *> *sharedElementToRestart = [NSMutableArray new];
|
|
113
|
+
for (REASharedElement *sharedElement in _sharedElements) {
|
|
114
|
+
NSNumber *viewTag = sharedElement.targetView.reactTag;
|
|
115
|
+
if ([_layoutedSharedViewsTags containsObject:viewTag] && _currentSharedTransitionViews[viewTag]) {
|
|
116
|
+
[sharedElementToRestart addObject:sharedElement];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
for (REASharedElement *sharedElement in sharedElementToRestart) {
|
|
121
|
+
UIView *sourceView = sharedElement.sourceView;
|
|
122
|
+
UIView *targetView = sharedElement.targetView;
|
|
123
|
+
|
|
124
|
+
REASnapshot *newSourceViewSnapshot = [[REASnapshot alloc] initWithAbsolutePosition:sourceView];
|
|
125
|
+
REASnapshot *currentTargetViewSnapshot = _snapshotRegistry[targetView.reactTag];
|
|
126
|
+
REAFrame *frameData = _layoutedSharedViewsFrame[targetView.reactTag];
|
|
127
|
+
float currentOriginX = [currentTargetViewSnapshot.values[@"originX"] floatValue];
|
|
128
|
+
float currentOriginY = [currentTargetViewSnapshot.values[@"originY"] floatValue];
|
|
129
|
+
float currentOriginXByParent = [currentTargetViewSnapshot.values[@"originXByParent"] floatValue];
|
|
130
|
+
float currentOriginYByParent = [currentTargetViewSnapshot.values[@"originYByParent"] floatValue];
|
|
131
|
+
NSNumber *newOriginX = @(currentOriginX - currentOriginXByParent + frameData.x);
|
|
132
|
+
NSNumber *newOriginY = @(currentOriginY - currentOriginYByParent + frameData.y);
|
|
133
|
+
currentTargetViewSnapshot.values[@"width"] = @(frameData.width);
|
|
134
|
+
currentTargetViewSnapshot.values[@"height"] = @(frameData.height);
|
|
135
|
+
currentTargetViewSnapshot.values[@"originX"] = newOriginX;
|
|
136
|
+
currentTargetViewSnapshot.values[@"originY"] = newOriginY;
|
|
137
|
+
currentTargetViewSnapshot.values[@"globalOriginX"] = newOriginX;
|
|
138
|
+
currentTargetViewSnapshot.values[@"globalOriginY"] = newOriginY;
|
|
139
|
+
currentTargetViewSnapshot.values[@"originXByParent"] = @(frameData.x);
|
|
140
|
+
currentTargetViewSnapshot.values[@"originYByParent"] = @(frameData.y);
|
|
141
|
+
sharedElement.sourceViewSnapshot = newSourceViewSnapshot;
|
|
142
|
+
|
|
143
|
+
[self disableCleaningForViewTag:sourceView.reactTag];
|
|
144
|
+
[self disableCleaningForViewTag:targetView.reactTag];
|
|
145
|
+
}
|
|
146
|
+
[self startSharedTransition:sharedElementToRestart];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
- (BOOL)configureAndStartSharedTransitionForViews:(NSArray<UIView *> *)views
|
|
150
|
+
{
|
|
151
|
+
NSArray *sharedViews = [self sortViewsByTags:views];
|
|
152
|
+
NSArray<REASharedElement *> *sharedElements = [self getSharedElementForCurrentTransition:sharedViews
|
|
153
|
+
withNewElements:NO];
|
|
154
|
+
if ([sharedElements count] == 0) {
|
|
155
|
+
return NO;
|
|
156
|
+
}
|
|
157
|
+
[self configureTransitionContainer];
|
|
158
|
+
[self reparentSharedViewsForCurrentTransition:sharedElements];
|
|
159
|
+
[self startSharedTransition:sharedElements];
|
|
160
|
+
return YES;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
- (NSArray *)sortViewsByTags:(NSArray *)views
|
|
164
|
+
{
|
|
165
|
+
/*
|
|
166
|
+
All shared views during the transition have the same parent. It is problematic if parent
|
|
167
|
+
view and their children are in the same transition. To keep the valid order in the z-axis,
|
|
168
|
+
we need to sort views by tags. Parent tag is lower than children tags.
|
|
169
|
+
*/
|
|
170
|
+
return [views sortedArrayUsingComparator:^NSComparisonResult(UIView *view1, UIView *view2) {
|
|
171
|
+
return [view2.reactTag compare:view1.reactTag];
|
|
172
|
+
}];
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
- (NSMutableArray<REASharedElement *> *)getSharedElementForCurrentTransition:(NSArray *)sharedViews
|
|
176
|
+
withNewElements:(BOOL)addedNewScreen
|
|
177
|
+
{
|
|
178
|
+
NSMutableArray<UIView *> *newTransitionViews = [NSMutableArray new];
|
|
179
|
+
NSMutableArray<REASharedElement *> *sharedElements = [NSMutableArray new];
|
|
180
|
+
NSMutableSet<NSNumber *> *currentSharedViewsTags = [NSMutableSet new];
|
|
181
|
+
for (UIView *sharedView in sharedViews) {
|
|
182
|
+
[currentSharedViewsTags addObject:sharedView.reactTag];
|
|
183
|
+
}
|
|
184
|
+
for (UIView *sharedView in sharedViews) {
|
|
185
|
+
// add observers
|
|
186
|
+
UIView *sharedViewScreen = [REAScreensHelper getScreenForView:sharedView];
|
|
187
|
+
UIView *stack = [REAScreensHelper getStackForView:sharedViewScreen];
|
|
188
|
+
|
|
189
|
+
// find sibling for shared view
|
|
190
|
+
NSNumber *siblingViewTag = _findPrecedingViewTagForTransition(sharedView.reactTag);
|
|
191
|
+
UIView *siblingView = nil;
|
|
192
|
+
do {
|
|
193
|
+
siblingView = [_animationManager viewForTag:siblingViewTag];
|
|
194
|
+
if (siblingView == nil) {
|
|
195
|
+
[self clearAllSharedConfigsForViewTag:siblingViewTag];
|
|
196
|
+
siblingViewTag = _findPrecedingViewTagForTransition(sharedView.reactTag);
|
|
197
|
+
}
|
|
198
|
+
} while (siblingView == nil && siblingViewTag != nil);
|
|
199
|
+
|
|
200
|
+
if (siblingView == nil) {
|
|
201
|
+
// the sibling of shared view doesn't exist yet
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
UIView *viewSource;
|
|
206
|
+
UIView *viewTarget;
|
|
207
|
+
if (addedNewScreen) {
|
|
208
|
+
viewSource = siblingView;
|
|
209
|
+
viewTarget = sharedView;
|
|
210
|
+
} else {
|
|
211
|
+
viewSource = sharedView;
|
|
212
|
+
viewTarget = siblingView;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
bool isInCurrentTransition = false;
|
|
216
|
+
if (_currentSharedTransitionViews[viewSource.reactTag] || _currentSharedTransitionViews[viewTarget.reactTag]) {
|
|
217
|
+
isInCurrentTransition = true;
|
|
218
|
+
if (addedNewScreen) {
|
|
219
|
+
siblingViewTag = _findPrecedingViewTagForTransition(siblingView.reactTag);
|
|
220
|
+
siblingView = [_animationManager viewForTag:siblingViewTag];
|
|
221
|
+
|
|
222
|
+
viewSource = siblingView;
|
|
223
|
+
viewTarget = sharedView;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if ([currentSharedViewsTags containsObject:viewSource.reactTag] &&
|
|
228
|
+
[currentSharedViewsTags containsObject:viewTarget.reactTag]) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
bool isModal = [REAScreensHelper isScreenModal:sharedViewScreen];
|
|
233
|
+
// check valid target screen configuration
|
|
234
|
+
int screensCount = [stack.reactSubviews count];
|
|
235
|
+
if (addedNewScreen && !isModal) {
|
|
236
|
+
// is under top
|
|
237
|
+
if (screensCount < 2) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
UIView *viewSourceParentScreen = [REAScreensHelper getScreenForView:viewSource];
|
|
241
|
+
UIView *screenUnderStackTop = stack.reactSubviews[screensCount - 2];
|
|
242
|
+
if (![screenUnderStackTop.reactTag isEqual:viewSourceParentScreen.reactTag] && !isInCurrentTransition) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
} else if (!addedNewScreen) {
|
|
246
|
+
// is on top
|
|
247
|
+
UIView *viewTargetParentScreen = [REAScreensHelper getScreenForView:viewTarget];
|
|
248
|
+
UIView *stackTarget = viewTargetParentScreen.reactViewController.navigationController.topViewController.view;
|
|
249
|
+
if (stackTarget != viewTargetParentScreen) {
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (isModal) {
|
|
255
|
+
[_viewsToHide addObject:viewSource.reactTag];
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
REASnapshot *sourceViewSnapshot = [[REASnapshot alloc] initWithAbsolutePosition:viewSource];
|
|
259
|
+
if (addedNewScreen && !_currentSharedTransitionViews[viewSource.reactTag]) {
|
|
260
|
+
_snapshotRegistry[viewSource.reactTag] = sourceViewSnapshot;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
REASnapshot *targetViewSnapshot;
|
|
264
|
+
if (addedNewScreen) {
|
|
265
|
+
targetViewSnapshot = [[REASnapshot alloc] initWithAbsolutePosition:viewTarget];
|
|
266
|
+
_snapshotRegistry[viewTarget.reactTag] = targetViewSnapshot;
|
|
267
|
+
} else {
|
|
268
|
+
targetViewSnapshot = _snapshotRegistry[viewTarget.reactTag];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
[newTransitionViews addObject:viewSource];
|
|
272
|
+
[newTransitionViews addObject:viewTarget];
|
|
273
|
+
|
|
274
|
+
REASharedElement *sharedElement = [[REASharedElement alloc] initWithSourceView:viewSource
|
|
275
|
+
sourceViewSnapshot:sourceViewSnapshot
|
|
276
|
+
targetView:viewTarget
|
|
277
|
+
targetViewSnapshot:targetViewSnapshot];
|
|
278
|
+
[sharedElements addObject:sharedElement];
|
|
279
|
+
}
|
|
280
|
+
if ([newTransitionViews count] > 0) {
|
|
281
|
+
for (NSNumber *viewTag in _currentSharedTransitionViews) {
|
|
282
|
+
UIView *view = _currentSharedTransitionViews[viewTag];
|
|
283
|
+
if ([newTransitionViews containsObject:view]) {
|
|
284
|
+
[self disableCleaningForViewTag:viewTag];
|
|
285
|
+
} else {
|
|
286
|
+
[_viewsWithCanceledAnimation addObject:view];
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
[_currentSharedTransitionViews removeAllObjects];
|
|
290
|
+
for (UIView *view in newTransitionViews) {
|
|
291
|
+
_currentSharedTransitionViews[view.reactTag] = view;
|
|
292
|
+
}
|
|
293
|
+
for (UIView *view in [_viewsWithCanceledAnimation copy]) {
|
|
294
|
+
[self cancelAnimation:view.reactTag];
|
|
295
|
+
[self finishSharedAnimation:view];
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if ([sharedElements count] != 0) {
|
|
299
|
+
_sharedElements = sharedElements;
|
|
300
|
+
}
|
|
301
|
+
return sharedElements;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/*
|
|
305
|
+
Method swizzling is used to get notification from react-native-screens
|
|
306
|
+
about push or pop screen from stack.
|
|
307
|
+
*/
|
|
308
|
+
- (void)swizzleScreensMethods
|
|
309
|
+
{
|
|
310
|
+
#if LOAD_SCREENS_HEADERS
|
|
311
|
+
static dispatch_once_t onceToken;
|
|
312
|
+
dispatch_once(&onceToken, ^{
|
|
313
|
+
// it replaces method for RNSScreenView class, so it can be done only once
|
|
314
|
+
[self swizzleMethod:@selector(viewDidLayoutSubviews)
|
|
315
|
+
with:@selector(swizzled_viewDidLayoutSubviews)
|
|
316
|
+
forClass:[RNSScreen class]];
|
|
317
|
+
[self swizzleMethod:@selector(notifyWillDisappear)
|
|
318
|
+
with:@selector(swizzled_notifyWillDisappear)
|
|
319
|
+
forClass:[RNSScreenView class]];
|
|
320
|
+
});
|
|
321
|
+
#endif
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
- (void)swizzleMethod:(SEL)originalSelector with:(SEL)swizzledSelector forClass:(Class)originalClass
|
|
325
|
+
{
|
|
326
|
+
Class class = [self class];
|
|
327
|
+
Method originalMethod = class_getInstanceMethod(originalClass, originalSelector);
|
|
328
|
+
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
|
|
329
|
+
IMP originalImp = method_getImplementation(originalMethod);
|
|
330
|
+
IMP swizzledImp = method_getImplementation(swizzledMethod);
|
|
331
|
+
class_replaceMethod(originalClass, swizzledSelector, originalImp, method_getTypeEncoding(originalMethod));
|
|
332
|
+
class_replaceMethod(originalClass, originalSelector, swizzledImp, method_getTypeEncoding(swizzledMethod));
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
- (void)swizzled_viewDidLayoutSubviews
|
|
336
|
+
{
|
|
337
|
+
// call original method from react-native-screens, self == RNScreen
|
|
338
|
+
[self swizzled_viewDidLayoutSubviews];
|
|
339
|
+
UIView *screen = [self valueForKey:@"screenView"];
|
|
340
|
+
[_sharedTransitionManager screenAddedToStack:screen];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
- (void)swizzled_notifyWillDisappear
|
|
344
|
+
{
|
|
345
|
+
// call original method from react-native-screens, self == RNSScreenView
|
|
346
|
+
[self swizzled_notifyWillDisappear];
|
|
347
|
+
[_sharedTransitionManager screenRemovedFromStack:(UIView *)self];
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
- (void)screenAddedToStack:(UIView *)screen
|
|
351
|
+
{
|
|
352
|
+
if (screen.superview != nil) {
|
|
353
|
+
[self runAsyncSharedTransition];
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
- (void)screenRemovedFromStack:(UIView *)screen
|
|
358
|
+
{
|
|
359
|
+
UIView *stack = [REAScreensHelper getStackForView:screen];
|
|
360
|
+
bool isModal = [REAScreensHelper isScreenModal:screen];
|
|
361
|
+
bool isRemovedInParentStack = [self isRemovedFromHigherStack:screen];
|
|
362
|
+
if ((stack != nil || isModal) && !isRemovedInParentStack) {
|
|
363
|
+
bool isInteractive =
|
|
364
|
+
[[[screen.reactViewController valueForKey:@"transitionCoordinator"] valueForKey:@"interactive"] boolValue];
|
|
365
|
+
// screen is removed from React tree (navigation.navigate(<screenName>))
|
|
366
|
+
bool isScreenRemovedFromReactTree = [self isScreen:screen outsideStack:stack];
|
|
367
|
+
// click on button goBack on native header
|
|
368
|
+
bool isTriggeredByGoBackButton = [self isScreen:screen onTopOfStack:stack];
|
|
369
|
+
bool shouldRunTransition = !isInteractive && (isScreenRemovedFromReactTree || isTriggeredByGoBackButton);
|
|
370
|
+
if (shouldRunTransition) {
|
|
371
|
+
[self runSharedTransitionForSharedViewsOnScreen:screen];
|
|
372
|
+
} else {
|
|
373
|
+
[self makeSnapshotForScreenViews:screen];
|
|
374
|
+
}
|
|
375
|
+
[self restoreViewsVisibility];
|
|
376
|
+
} else {
|
|
377
|
+
// removed stack
|
|
378
|
+
[self clearConfigForStack:stack];
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
- (void)makeSnapshotForScreenViews:(UIView *)screen
|
|
383
|
+
{
|
|
384
|
+
REANodeFind(screen, ^int(id<RCTComponent> view) {
|
|
385
|
+
NSNumber *viewTag = view.reactTag;
|
|
386
|
+
if (self->_currentSharedTransitionViews[viewTag]) {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
if ([self->_animationManager hasAnimationForTag:viewTag type:SHARED_ELEMENT_TRANSITION]) {
|
|
390
|
+
REASnapshot *snapshot = [[REASnapshot alloc] initWithAbsolutePosition:(UIView *)view];
|
|
391
|
+
self->_snapshotRegistry[viewTag] = snapshot;
|
|
392
|
+
}
|
|
393
|
+
return false;
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
- (void)restoreViewsVisibility
|
|
398
|
+
{
|
|
399
|
+
for (NSNumber *viewTag in _viewsToHide) {
|
|
400
|
+
UIView *view = [_animationManager viewForTag:viewTag];
|
|
401
|
+
view.hidden = NO;
|
|
402
|
+
}
|
|
403
|
+
[_viewsToHide removeAllObjects];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
- (void)clearConfigForStack:(UIView *)stack
|
|
407
|
+
{
|
|
408
|
+
for (UIView *child in stack.reactSubviews) {
|
|
409
|
+
REANodeFind(child, ^int(id<RCTComponent> _Nonnull view) {
|
|
410
|
+
[self clearAllSharedConfigsForViewTag:view.reactTag];
|
|
411
|
+
return false;
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
- (BOOL)isScreen:(UIView *)screen outsideStack:(UIView *)stack
|
|
417
|
+
{
|
|
418
|
+
for (UIView *child in stack.reactSubviews) {
|
|
419
|
+
if ([child.reactTag isEqual:screen.reactTag]) {
|
|
420
|
+
return NO;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
return YES;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
- (BOOL)isScreen:(UIView *)screen onTopOfStack:(UIView *)stack
|
|
427
|
+
{
|
|
428
|
+
int screenCount = stack.reactSubviews.count;
|
|
429
|
+
return screenCount > 0 && screen == stack.reactSubviews.lastObject;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
- (BOOL)isRemovedFromHigherStack:(UIView *)screen
|
|
433
|
+
{
|
|
434
|
+
UIView *stack = screen.reactSuperview;
|
|
435
|
+
while (stack != nil) {
|
|
436
|
+
screen = stack.reactViewController.navigationController.topViewController.view;
|
|
437
|
+
if (screen == nil) {
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
if (screen.superview == nil) {
|
|
441
|
+
return YES;
|
|
442
|
+
}
|
|
443
|
+
stack = screen.reactSuperview;
|
|
444
|
+
}
|
|
445
|
+
return NO;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
- (void)runSharedTransitionForSharedViewsOnScreen:(UIView *)screen
|
|
449
|
+
{
|
|
450
|
+
NSMutableArray<UIView *> *removedViews = [NSMutableArray new];
|
|
451
|
+
REANodeFind(screen, ^int(id<RCTComponent> view) {
|
|
452
|
+
if ([self->_animationManager hasAnimationForTag:view.reactTag type:SHARED_ELEMENT_TRANSITION]) {
|
|
453
|
+
[removedViews addObject:(UIView *)view];
|
|
454
|
+
}
|
|
455
|
+
return false;
|
|
456
|
+
});
|
|
457
|
+
BOOL startedAnimation = [self configureAndStartSharedTransitionForViews:removedViews];
|
|
458
|
+
if (startedAnimation) {
|
|
459
|
+
_removedViews = removedViews;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
- (void)runAsyncSharedTransition
|
|
464
|
+
{
|
|
465
|
+
if ([_sharedElements count] == 0 || !_isAsyncSharedTransitionConfigured) {
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
for (REASharedElement *sharedElement in _sharedElements) {
|
|
469
|
+
UIView *viewTarget = sharedElement.targetView;
|
|
470
|
+
REASnapshot *targetViewSnapshot = [[REASnapshot alloc] initWithAbsolutePosition:viewTarget];
|
|
471
|
+
_snapshotRegistry[viewTarget.reactTag] = targetViewSnapshot;
|
|
472
|
+
sharedElement.targetViewSnapshot = targetViewSnapshot;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
[self configureTransitionContainer];
|
|
476
|
+
[self reparentSharedViewsForCurrentTransition:_sharedElements];
|
|
477
|
+
[self startSharedTransition:_sharedElements];
|
|
478
|
+
[_addedSharedViews removeAllObjects];
|
|
479
|
+
_isAsyncSharedTransitionConfigured = NO;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
- (void)configureTransitionContainer
|
|
483
|
+
{
|
|
484
|
+
if (!_isSharedTransitionActive) {
|
|
485
|
+
_isSharedTransitionActive = YES;
|
|
486
|
+
UIView *mainWindow = UIApplication.sharedApplication.keyWindow;
|
|
487
|
+
if (_transitionContainer == nil) {
|
|
488
|
+
_transitionContainer = [UIView new];
|
|
489
|
+
}
|
|
490
|
+
[mainWindow addSubview:_transitionContainer];
|
|
491
|
+
[mainWindow bringSubviewToFront:_transitionContainer];
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
- (void)reparentSharedViewsForCurrentTransition:(NSArray *)sharedElements
|
|
496
|
+
{
|
|
497
|
+
for (REASharedElement *sharedElement in sharedElements) {
|
|
498
|
+
UIView *viewSource = sharedElement.sourceView;
|
|
499
|
+
UIView *viewTarget = sharedElement.targetView;
|
|
500
|
+
if (_sharedTransitionParent[viewSource.reactTag] == nil) {
|
|
501
|
+
_sharedTransitionParent[viewSource.reactTag] = viewSource.superview;
|
|
502
|
+
_sharedTransitionInParentIndex[viewSource.reactTag] = @([viewSource.superview.subviews indexOfObject:viewSource]);
|
|
503
|
+
[viewSource removeFromSuperview];
|
|
504
|
+
[_transitionContainer addSubview:viewSource];
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
if (_sharedTransitionParent[viewTarget.reactTag] == nil) {
|
|
508
|
+
_sharedTransitionParent[viewTarget.reactTag] = viewTarget.superview;
|
|
509
|
+
_sharedTransitionInParentIndex[viewTarget.reactTag] = @([viewTarget.superview.subviews indexOfObject:viewTarget]);
|
|
510
|
+
[viewTarget removeFromSuperview];
|
|
511
|
+
[_transitionContainer addSubview:viewTarget];
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
- (void)startSharedTransition:(NSArray *)sharedElements
|
|
517
|
+
{
|
|
518
|
+
for (REASharedElement *sharedElement in sharedElements) {
|
|
519
|
+
[self onViewTransition:sharedElement.sourceView
|
|
520
|
+
before:sharedElement.sourceViewSnapshot
|
|
521
|
+
after:sharedElement.targetViewSnapshot];
|
|
522
|
+
[self onViewTransition:sharedElement.targetView
|
|
523
|
+
before:sharedElement.sourceViewSnapshot
|
|
524
|
+
after:sharedElement.targetViewSnapshot];
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
- (void)onViewTransition:(UIView *)view before:(REASnapshot *)before after:(REASnapshot *)after
|
|
529
|
+
{
|
|
530
|
+
NSMutableDictionary *targetValues = after.values;
|
|
531
|
+
NSMutableDictionary *currentValues = before.values;
|
|
532
|
+
[view.superview bringSubviewToFront:view];
|
|
533
|
+
NSDictionary *preparedValues = [_animationManager prepareDataForLayoutAnimatingWorklet:currentValues
|
|
534
|
+
targetValues:targetValues];
|
|
535
|
+
[_animationManager startAnimationForTag:view.reactTag
|
|
536
|
+
type:SHARED_ELEMENT_TRANSITION
|
|
537
|
+
yogaValues:preparedValues
|
|
538
|
+
depth:@(0)];
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
- (void)finishSharedAnimation:(UIView *)view
|
|
542
|
+
{
|
|
543
|
+
NSNumber *viewTag = view.reactTag;
|
|
544
|
+
if (_disableCleaningForView[viewTag]) {
|
|
545
|
+
[self enableCleaningForViewTag:viewTag];
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
548
|
+
if (_currentSharedTransitionViews[viewTag] || [_viewsWithCanceledAnimation containsObject:view]) {
|
|
549
|
+
[view removeFromSuperview];
|
|
550
|
+
UIView *parent = _sharedTransitionParent[viewTag];
|
|
551
|
+
int childIndex = [_sharedTransitionInParentIndex[viewTag] intValue];
|
|
552
|
+
UIView *screen = [REAScreensHelper getScreenForView:parent];
|
|
553
|
+
bool isScreenInReactTree = screen.reactSuperview != nil;
|
|
554
|
+
if (isScreenInReactTree) {
|
|
555
|
+
[parent insertSubview:view atIndex:childIndex];
|
|
556
|
+
REASnapshot *viewSourcePreviousSnapshot = _snapshotRegistry[viewTag];
|
|
557
|
+
[_animationManager progressLayoutAnimationWithStyle:viewSourcePreviousSnapshot.values
|
|
558
|
+
forTag:viewTag
|
|
559
|
+
isSharedTransition:YES];
|
|
560
|
+
float originXByParent = [viewSourcePreviousSnapshot.values[@"originXByParent"] floatValue];
|
|
561
|
+
float originYByParent = [viewSourcePreviousSnapshot.values[@"originYByParent"] floatValue];
|
|
562
|
+
CGRect frame = CGRectMake(originXByParent, originYByParent, view.frame.size.width, view.frame.size.height);
|
|
563
|
+
[view setFrame:frame];
|
|
564
|
+
}
|
|
565
|
+
if ([_viewsToHide containsObject:viewTag]) {
|
|
566
|
+
view.hidden = YES;
|
|
567
|
+
}
|
|
568
|
+
[_currentSharedTransitionViews removeObjectForKey:viewTag];
|
|
569
|
+
[_sharedTransitionParent removeObjectForKey:viewTag];
|
|
570
|
+
[_sharedTransitionInParentIndex removeObjectForKey:viewTag];
|
|
571
|
+
[_viewsWithCanceledAnimation removeObject:view];
|
|
572
|
+
if ([_removedViews containsObject:view]) {
|
|
573
|
+
[_animationManager clearAnimationConfigForTag:viewTag];
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if ([_currentSharedTransitionViews count] == 0) {
|
|
577
|
+
[_transitionContainer removeFromSuperview];
|
|
578
|
+
[_removedViews removeAllObjects];
|
|
579
|
+
[_sharedElements removeAllObjects];
|
|
580
|
+
_isSharedTransitionActive = NO;
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
- (void)setFindPrecedingViewTagForTransitionBlock:
|
|
585
|
+
(REAFindPrecedingViewTagForTransitionBlock)findPrecedingViewTagForTransition
|
|
586
|
+
{
|
|
587
|
+
_findPrecedingViewTagForTransition = findPrecedingViewTagForTransition;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
- (void)setCancelAnimationBlock:(REACancelAnimationBlock)cancelAnimationBlock
|
|
591
|
+
{
|
|
592
|
+
_cancelLayoutAnimation = cancelAnimationBlock;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
- (void)clearAllSharedConfigsForViewTag:(NSNumber *)viewTag
|
|
596
|
+
{
|
|
597
|
+
if (viewTag != nil) {
|
|
598
|
+
[_snapshotRegistry removeObjectForKey:viewTag];
|
|
599
|
+
[_animationManager clearAnimationConfigForTag:viewTag];
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
- (void)cancelAnimation:(NSNumber *)viewTag
|
|
604
|
+
{
|
|
605
|
+
_cancelLayoutAnimation(viewTag, SHARED_ELEMENT_TRANSITION, YES, YES);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
- (void)disableCleaningForViewTag:(NSNumber *)viewTag
|
|
609
|
+
{
|
|
610
|
+
NSNumber *counter = _disableCleaningForView[viewTag];
|
|
611
|
+
if (counter != nil) {
|
|
612
|
+
_disableCleaningForView[viewTag] = @([counter intValue] + 1);
|
|
613
|
+
} else {
|
|
614
|
+
_disableCleaningForView[viewTag] = @(1);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
- (void)enableCleaningForViewTag:(NSNumber *)viewTag
|
|
619
|
+
{
|
|
620
|
+
NSNumber *counter = _disableCleaningForView[viewTag];
|
|
621
|
+
if (counter == nil) {
|
|
622
|
+
return;
|
|
623
|
+
}
|
|
624
|
+
int counterInt = [counter intValue];
|
|
625
|
+
if (counterInt == 1) {
|
|
626
|
+
[_disableCleaningForView removeObjectForKey:viewTag];
|
|
627
|
+
} else {
|
|
628
|
+
_disableCleaningForView[viewTag] = @(counterInt - 1);
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
@end
|