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
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
#include <jsi/jsi.h>
|
|
10
10
|
|
|
11
11
|
#include <memory>
|
|
12
|
+
#include <string>
|
|
12
13
|
#include <utility>
|
|
13
14
|
|
|
14
15
|
#if __has_include(<reacthermes/HermesExecutorFactory.h>)
|
|
@@ -41,6 +42,11 @@ class HermesExecutorRuntimeAdapter
|
|
|
41
42
|
thread_->quitSynchronous();
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
#if REACT_NATIVE_MINOR_VERSION >= 71
|
|
46
|
+
facebook::hermes::HermesRuntime &getRuntime() override {
|
|
47
|
+
return hermesRuntime_;
|
|
48
|
+
}
|
|
49
|
+
#else
|
|
44
50
|
facebook::jsi::Runtime &getRuntime() override {
|
|
45
51
|
return hermesRuntime_;
|
|
46
52
|
}
|
|
@@ -48,6 +54,7 @@ class HermesExecutorRuntimeAdapter
|
|
|
48
54
|
facebook::hermes::debugger::Debugger &getDebugger() override {
|
|
49
55
|
return hermesRuntime_.getDebugger();
|
|
50
56
|
}
|
|
57
|
+
#endif // REACT_NATIVE_MINOR_VERSION
|
|
51
58
|
|
|
52
59
|
// This is not empty in the original implementation, but we decided to tickle
|
|
53
60
|
// the runtime by running a small piece of code on every frame as using this
|
|
@@ -72,20 +79,62 @@ ReanimatedHermesRuntime::ReanimatedHermesRuntime(
|
|
|
72
79
|
#if HERMES_ENABLE_DEBUGGER
|
|
73
80
|
auto adapter =
|
|
74
81
|
std::make_unique<HermesExecutorRuntimeAdapter>(*runtime_, jsQueue);
|
|
82
|
+
#if REACT_NATIVE_MINOR_VERSION >= 71
|
|
83
|
+
debugToken_ = facebook::hermes::inspector::chrome::enableDebugging(
|
|
84
|
+
std::move(adapter), "Reanimated Runtime");
|
|
85
|
+
#else
|
|
75
86
|
facebook::hermes::inspector::chrome::enableDebugging(
|
|
76
87
|
std::move(adapter), "Reanimated Runtime");
|
|
88
|
+
#endif // REACT_NATIVE_MINOR_VERSION
|
|
77
89
|
#else
|
|
78
90
|
// This is required by iOS, because there is an assertion in the destructor
|
|
79
91
|
// that the thread was indeed `quit` before
|
|
80
92
|
jsQueue->quitSynchronous();
|
|
81
93
|
#endif
|
|
94
|
+
|
|
95
|
+
#ifdef DEBUG
|
|
96
|
+
facebook::hermes::HermesRuntime *wrappedRuntime = runtime_.get();
|
|
97
|
+
jsi::Value evalWithSourceMap = jsi::Function::createFromHostFunction(
|
|
98
|
+
*runtime_,
|
|
99
|
+
jsi::PropNameID::forAscii(*runtime_, "evalWithSourceMap"),
|
|
100
|
+
3,
|
|
101
|
+
[wrappedRuntime](
|
|
102
|
+
jsi::Runtime &rt,
|
|
103
|
+
const jsi::Value &thisValue,
|
|
104
|
+
const jsi::Value *args,
|
|
105
|
+
size_t count) -> jsi::Value {
|
|
106
|
+
auto code = std::make_shared<const jsi::StringBuffer>(
|
|
107
|
+
args[0].asString(rt).utf8(rt));
|
|
108
|
+
std::string sourceURL;
|
|
109
|
+
if (count > 1 && args[1].isString()) {
|
|
110
|
+
sourceURL = args[1].asString(rt).utf8(rt);
|
|
111
|
+
}
|
|
112
|
+
std::shared_ptr<const jsi::Buffer> sourceMap;
|
|
113
|
+
if (count > 2 && args[2].isString()) {
|
|
114
|
+
sourceMap = std::make_shared<const jsi::StringBuffer>(
|
|
115
|
+
args[2].asString(rt).utf8(rt));
|
|
116
|
+
}
|
|
117
|
+
#if REACT_NATIVE_MINOR_VERSION >= 65
|
|
118
|
+
return wrappedRuntime->evaluateJavaScriptWithSourceMap(
|
|
119
|
+
code, sourceMap, sourceURL);
|
|
120
|
+
#else
|
|
121
|
+
return wrappedRuntime->evaluateJavaScript(code, sourceURL);
|
|
122
|
+
#endif
|
|
123
|
+
});
|
|
124
|
+
runtime_->global().setProperty(
|
|
125
|
+
*runtime_, "evalWithSourceMap", evalWithSourceMap);
|
|
126
|
+
#endif // DEBUG
|
|
82
127
|
}
|
|
83
128
|
|
|
84
129
|
ReanimatedHermesRuntime::~ReanimatedHermesRuntime() {
|
|
85
130
|
#if HERMES_ENABLE_DEBUGGER
|
|
86
131
|
// We have to disable debugging before the runtime is destroyed.
|
|
132
|
+
#if REACT_NATIVE_MINOR_VERSION >= 71
|
|
133
|
+
facebook::hermes::inspector::chrome::disableDebugging(debugToken_);
|
|
134
|
+
#else
|
|
87
135
|
facebook::hermes::inspector::chrome::disableDebugging(*runtime_);
|
|
88
|
-
#endif
|
|
136
|
+
#endif // REACT_NATIVE_MINOR_VERSION
|
|
137
|
+
#endif // HERMES_ENABLE_DEBUGGER
|
|
89
138
|
}
|
|
90
139
|
|
|
91
140
|
} // namespace reanimated
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
#include <hermes/hermes.h>
|
|
26
26
|
#endif
|
|
27
27
|
|
|
28
|
+
#if REACT_NATIVE_MINOR_VERSION >= 71
|
|
29
|
+
#include <hermes/inspector/chrome/Registration.h>
|
|
30
|
+
#endif
|
|
31
|
+
|
|
28
32
|
namespace reanimated {
|
|
29
33
|
|
|
30
34
|
using namespace facebook;
|
|
@@ -116,8 +120,13 @@ class ReanimatedHermesRuntime
|
|
|
116
120
|
~ReanimatedHermesRuntime();
|
|
117
121
|
|
|
118
122
|
private:
|
|
119
|
-
std::
|
|
123
|
+
std::unique_ptr<facebook::hermes::HermesRuntime> runtime_;
|
|
120
124
|
ReanimatedReentrancyCheck reentrancyCheck_;
|
|
125
|
+
#if HERMES_ENABLE_DEBUGGER
|
|
126
|
+
#if REACT_NATIVE_MINOR_VERSION >= 71
|
|
127
|
+
facebook::hermes::inspector::chrome::DebugSessionToken debugToken_;
|
|
128
|
+
#endif // REACT_NATIVE_MINOR_VERSION >= 71
|
|
129
|
+
#endif // HERMES_ENABLE_DEBUGGER
|
|
121
130
|
};
|
|
122
131
|
|
|
123
132
|
} // namespace reanimated
|
|
@@ -11,8 +11,12 @@
|
|
|
11
11
|
#elif JS_RUNTIME_V8
|
|
12
12
|
#include <v8runtime/V8RuntimeFactory.h>
|
|
13
13
|
#else
|
|
14
|
+
#if REACT_NATIVE_MINOR_VERSION >= 71
|
|
15
|
+
#include <jsc/JSCRuntime.h>
|
|
16
|
+
#else
|
|
14
17
|
#include <jsi/JSCRuntime.h>
|
|
15
|
-
#endif
|
|
18
|
+
#endif // REACT_NATIVE_MINOR_VERSION
|
|
19
|
+
#endif // JS_RUNTIME
|
|
16
20
|
|
|
17
21
|
namespace reanimated {
|
|
18
22
|
|
|
@@ -10,7 +10,7 @@ void EventHandlerRegistry::registerEventHandler(
|
|
|
10
10
|
eventHandlers[eventHandler->id] = eventHandler;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
void EventHandlerRegistry::unregisterEventHandler(
|
|
13
|
+
void EventHandlerRegistry::unregisterEventHandler(uint64_t id) {
|
|
14
14
|
const std::lock_guard<std::mutex> lock(instanceMutex);
|
|
15
15
|
auto handlerIt = eventHandlers.find(id);
|
|
16
16
|
if (handlerIt != eventHandlers.end()) {
|
|
@@ -24,13 +24,9 @@ void EventHandlerRegistry::unregisterEventHandler(unsigned long id) {
|
|
|
24
24
|
|
|
25
25
|
void EventHandlerRegistry::processEvent(
|
|
26
26
|
jsi::Runtime &rt,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
jsi::Value &eventPayload
|
|
30
|
-
#else
|
|
31
|
-
std::string eventPayload
|
|
32
|
-
#endif
|
|
33
|
-
/**/) {
|
|
27
|
+
double eventTimestamp,
|
|
28
|
+
const std::string &eventName,
|
|
29
|
+
const jsi::Value &eventPayload) {
|
|
34
30
|
std::vector<std::shared_ptr<WorkletEventHandler>> handlersForEvent;
|
|
35
31
|
{
|
|
36
32
|
const std::lock_guard<std::mutex> lock(instanceMutex);
|
|
@@ -41,38 +37,16 @@ void EventHandlerRegistry::processEvent(
|
|
|
41
37
|
}
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
45
|
-
eventPayload.asObject(rt).setProperty(
|
|
46
|
-
rt, "eventName", jsi::String::createFromUtf8(rt, eventName));
|
|
47
|
-
for (auto handler : handlersForEvent) {
|
|
48
|
-
handler->process(rt, eventPayload);
|
|
49
|
-
}
|
|
50
|
-
#else
|
|
51
|
-
// We receive here a JS Map with JSON as a value of NativeMap key
|
|
52
|
-
// { NativeMap: { "jsonProp": "json value" } }
|
|
53
|
-
// So we need to extract only JSON part
|
|
54
|
-
std::string delimimter = "NativeMap:";
|
|
55
|
-
auto positionToSplit = eventPayload.find(delimimter) + delimimter.size();
|
|
56
|
-
auto lastBracketCharactedPosition = eventPayload.size() - positionToSplit - 1;
|
|
57
|
-
auto eventJSON =
|
|
58
|
-
eventPayload.substr(positionToSplit, lastBracketCharactedPosition);
|
|
59
40
|
|
|
60
|
-
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
auto eventObject = jsi::Value::createFromJsonUtf8(
|
|
65
|
-
rt, reinterpret_cast<uint8_t *>(&eventJSON[0]), eventJSON.size());
|
|
66
|
-
|
|
67
|
-
eventObject.asObject(rt).setProperty(
|
|
41
|
+
eventPayload.asObject(rt).setProperty(
|
|
68
42
|
rt, "eventName", jsi::String::createFromUtf8(rt, eventName));
|
|
69
43
|
for (auto handler : handlersForEvent) {
|
|
70
|
-
handler->process(
|
|
44
|
+
handler->process(eventTimestamp, eventPayload);
|
|
71
45
|
}
|
|
72
|
-
#endif
|
|
73
46
|
}
|
|
74
47
|
|
|
75
|
-
bool EventHandlerRegistry::isAnyHandlerWaitingForEvent(
|
|
48
|
+
bool EventHandlerRegistry::isAnyHandlerWaitingForEvent(
|
|
49
|
+
const std::string &eventName) {
|
|
76
50
|
const std::lock_guard<std::mutex> lock(instanceMutex);
|
|
77
51
|
auto it = eventMappings.find(eventName);
|
|
78
52
|
return (it != eventMappings.end()) && (!(it->second).empty());
|
|
@@ -18,28 +18,22 @@ class WorkletEventHandler;
|
|
|
18
18
|
class EventHandlerRegistry {
|
|
19
19
|
std::map<
|
|
20
20
|
std::string,
|
|
21
|
-
std::unordered_map<
|
|
21
|
+
std::unordered_map<uint64_t, std::shared_ptr<WorkletEventHandler>>>
|
|
22
22
|
eventMappings;
|
|
23
|
-
std::map<
|
|
23
|
+
std::map<uint64_t, std::shared_ptr<WorkletEventHandler>> eventHandlers;
|
|
24
24
|
std::mutex instanceMutex;
|
|
25
25
|
|
|
26
26
|
public:
|
|
27
27
|
void registerEventHandler(std::shared_ptr<WorkletEventHandler> eventHandler);
|
|
28
|
-
void unregisterEventHandler(
|
|
28
|
+
void unregisterEventHandler(uint64_t id);
|
|
29
29
|
|
|
30
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
31
30
|
void processEvent(
|
|
32
31
|
jsi::Runtime &rt,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
void processEvent(
|
|
37
|
-
jsi::Runtime &rt,
|
|
38
|
-
std::string eventName,
|
|
39
|
-
std::string eventPayload);
|
|
40
|
-
#endif
|
|
32
|
+
double eventTimestamp,
|
|
33
|
+
const std::string &eventName,
|
|
34
|
+
const jsi::Value &eventPayload);
|
|
41
35
|
|
|
42
|
-
bool isAnyHandlerWaitingForEvent(std::string eventName);
|
|
36
|
+
bool isAnyHandlerWaitingForEvent(const std::string &eventName);
|
|
43
37
|
};
|
|
44
38
|
|
|
45
39
|
} // namespace reanimated
|
|
@@ -11,9 +11,13 @@ CoreFunction::CoreFunction(
|
|
|
11
11
|
jsi::Runtime &rt = *runtimeHelper->rnRuntime();
|
|
12
12
|
auto workletObject = workletValue.asObject(rt);
|
|
13
13
|
rnFunction_ = std::make_unique<jsi::Function>(workletObject.asFunction(rt));
|
|
14
|
-
functionBody_ =
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
functionBody_ = workletObject.getPropertyAsObject(rt, "__initData")
|
|
15
|
+
.getProperty(rt, "code")
|
|
16
|
+
.asString(rt)
|
|
17
|
+
.utf8(rt);
|
|
18
|
+
location_ = "worklet_" +
|
|
19
|
+
std::to_string(static_cast<uint64_t>(
|
|
20
|
+
workletObject.getProperty(rt, "__workletHash").getNumber()));
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
std::unique_ptr<jsi::Function> &CoreFunction::getFunction(jsi::Runtime &rt) {
|
|
@@ -57,61 +61,8 @@ std::shared_ptr<Shareable> extractShareableOrThrow(
|
|
|
57
61
|
|
|
58
62
|
Shareable::~Shareable() {}
|
|
59
63
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
jsi::Value RetainingShareable::getJSValue(jsi::Runtime &rt) {
|
|
63
|
-
jsi::Value value;
|
|
64
|
-
if (runtimeHelper_->isRNRuntime(rt)) {
|
|
65
|
-
// TODO: it is suboptimal to generate new object every time getJS is called
|
|
66
|
-
// on host runtime – the objects we are generating already exists and we
|
|
67
|
-
// should possibly just grab a hold of such object and use it here instead
|
|
68
|
-
// of creating a new JS representation. As far as I understand the only
|
|
69
|
-
// case where it can be realistically called this way is when a shared
|
|
70
|
-
// value is created and then accessed on the same runtime
|
|
71
|
-
return toJSValue(rt);
|
|
72
|
-
} else if (remoteValue_ == nullptr) {
|
|
73
|
-
value = toJSValue(rt);
|
|
74
|
-
remoteValue_ = std::make_unique<jsi::WeakObject>(rt, value.asObject(rt));
|
|
75
|
-
} else {
|
|
76
|
-
value = remoteValue_->lock(rt);
|
|
77
|
-
if (value.isUndefined()) {
|
|
78
|
-
value = toJSValue(rt);
|
|
79
|
-
remoteValue_ = std::make_unique<jsi::WeakObject>(rt, value.asObject(rt));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return value;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
RetainingShareable::~RetainingShareable() {
|
|
86
|
-
if (runtimeHelper_->uiRuntimeDestroyed) {
|
|
87
|
-
// The below use of unique_ptr.release prevents the smart pointer from
|
|
88
|
-
// calling the destructor of the kept object. This effectively results in
|
|
89
|
-
// leaking some memory. We do this on purpose, as sometimes we would keep
|
|
90
|
-
// references to JSI objects past the lifetime of its runtime (e.g., shared
|
|
91
|
-
// values references from the RN VM holds reference to JSI objects on the
|
|
92
|
-
// UI runtime). When the UI runtime is terminated, the orphaned JSI objects
|
|
93
|
-
// would crash the app when their destructors are called, because they
|
|
94
|
-
// call into a memory that's managed by the terminated runtime. We accept
|
|
95
|
-
// the tradeoff of leaking memory here, as it has a limited impact. This
|
|
96
|
-
// scenario can only occur when the React instance is torn down which
|
|
97
|
-
// happens in development mode during app reloads, or in production when the
|
|
98
|
-
// app is being shut down gracefully by the system. An alternative solution
|
|
99
|
-
// would require us to keep track of all JSI values that are in use which
|
|
100
|
-
// would require additional data structure and compute spent on bookkeeping
|
|
101
|
-
// that only for the sake of destroying the values in time before the
|
|
102
|
-
// runtime is terminated. Note that the underlying memory that jsi::Value
|
|
103
|
-
// refers to is managed by the VM and gets freed along with the runtime.
|
|
104
|
-
remoteValue_.release();
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
#endif // HAS_JS_WEAK_OBJECTS
|
|
109
|
-
|
|
110
|
-
ShareableArray::ShareableArray(
|
|
111
|
-
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
|
|
112
|
-
jsi::Runtime &rt,
|
|
113
|
-
const jsi::Array &array)
|
|
114
|
-
: RetainingShareable(runtimeHelper, rt, ArrayType) {
|
|
64
|
+
ShareableArray::ShareableArray(jsi::Runtime &rt, const jsi::Array &array)
|
|
65
|
+
: Shareable(ArrayType) {
|
|
115
66
|
auto size = array.size(rt);
|
|
116
67
|
data_.reserve(size);
|
|
117
68
|
for (size_t i = 0; i < size; i++) {
|
|
@@ -119,11 +70,8 @@ ShareableArray::ShareableArray(
|
|
|
119
70
|
}
|
|
120
71
|
}
|
|
121
72
|
|
|
122
|
-
ShareableObject::ShareableObject(
|
|
123
|
-
|
|
124
|
-
jsi::Runtime &rt,
|
|
125
|
-
const jsi::Object &object)
|
|
126
|
-
: RetainingShareable(runtimeHelper, rt, ObjectType) {
|
|
73
|
+
ShareableObject::ShareableObject(jsi::Runtime &rt, const jsi::Object &object)
|
|
74
|
+
: Shareable(ObjectType) {
|
|
127
75
|
auto propertyNames = object.getPropertyNames(rt);
|
|
128
76
|
auto size = propertyNames.size(rt);
|
|
129
77
|
data_.reserve(size);
|
|
@@ -6,21 +6,37 @@
|
|
|
6
6
|
#include <utility>
|
|
7
7
|
#include <vector>
|
|
8
8
|
|
|
9
|
-
#ifdef RCT_NEW_ARCH_ENABLED
|
|
10
|
-
#include <react/renderer/uimanager/primitives.h>
|
|
11
|
-
#endif
|
|
12
|
-
|
|
13
9
|
#include "ReanimatedRuntime.h"
|
|
14
10
|
#include "RuntimeManager.h"
|
|
15
11
|
#include "Scheduler.h"
|
|
16
12
|
|
|
17
|
-
#define HAS_JS_WEAK_OBJECTS JS_RUNTIME_HERMES
|
|
18
|
-
|
|
19
13
|
using namespace facebook;
|
|
20
14
|
|
|
21
15
|
namespace reanimated {
|
|
22
16
|
|
|
23
|
-
class
|
|
17
|
+
class JSRuntimeHelper;
|
|
18
|
+
|
|
19
|
+
// Core functions are not allowed to capture outside variables, otherwise they'd
|
|
20
|
+
// try to access _closure variable which is something we want to avoid for
|
|
21
|
+
// simplicity reasons.
|
|
22
|
+
class CoreFunction {
|
|
23
|
+
private:
|
|
24
|
+
std::unique_ptr<jsi::Function> rnFunction_;
|
|
25
|
+
std::unique_ptr<jsi::Function> uiFunction_;
|
|
26
|
+
std::string functionBody_;
|
|
27
|
+
std::string location_;
|
|
28
|
+
JSRuntimeHelper
|
|
29
|
+
*runtimeHelper_; // runtime helper holds core function references, so we
|
|
30
|
+
// use normal pointer here to avoid ref cycles.
|
|
31
|
+
std::unique_ptr<jsi::Function> &getFunction(jsi::Runtime &rt);
|
|
32
|
+
|
|
33
|
+
public:
|
|
34
|
+
CoreFunction(JSRuntimeHelper *runtimeHelper, const jsi::Value &workletObject);
|
|
35
|
+
template <typename... Args>
|
|
36
|
+
jsi::Value call(jsi::Runtime &rt, Args &&...args) {
|
|
37
|
+
return getFunction(rt)->call(rt, args...);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
24
40
|
|
|
25
41
|
class JSRuntimeHelper {
|
|
26
42
|
private:
|
|
@@ -35,8 +51,9 @@ class JSRuntimeHelper {
|
|
|
35
51
|
const std::shared_ptr<Scheduler> &scheduler)
|
|
36
52
|
: rnRuntime_(rnRuntime), uiRuntime_(uiRuntime), scheduler_(scheduler) {}
|
|
37
53
|
|
|
38
|
-
volatile bool uiRuntimeDestroyed;
|
|
39
|
-
std::
|
|
54
|
+
volatile bool uiRuntimeDestroyed = false;
|
|
55
|
+
std::unique_ptr<CoreFunction> callGuard;
|
|
56
|
+
std::unique_ptr<CoreFunction> valueUnpacker;
|
|
40
57
|
|
|
41
58
|
inline jsi::Runtime *uiRuntime() const {
|
|
42
59
|
return uiRuntime_;
|
|
@@ -61,27 +78,19 @@ class JSRuntimeHelper {
|
|
|
61
78
|
void scheduleOnJS(std::function<void()> job) {
|
|
62
79
|
scheduler_->scheduleOnJS(job);
|
|
63
80
|
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// Core functions are not allowed to capture outside variables, otherwise they'd
|
|
67
|
-
// try to access _closure variable which is something we want to avoid for
|
|
68
|
-
// simplicity reasons.
|
|
69
|
-
class CoreFunction {
|
|
70
|
-
private:
|
|
71
|
-
std::unique_ptr<jsi::Function> rnFunction_;
|
|
72
|
-
std::unique_ptr<jsi::Function> uiFunction_;
|
|
73
|
-
std::string functionBody_;
|
|
74
|
-
std::string location_;
|
|
75
|
-
JSRuntimeHelper
|
|
76
|
-
*runtimeHelper_; // runtime helper holds core function references, so we
|
|
77
|
-
// use normal pointer here to avoid ref cycles.
|
|
78
|
-
std::unique_ptr<jsi::Function> &getFunction(jsi::Runtime &rt);
|
|
79
81
|
|
|
80
|
-
public:
|
|
81
|
-
CoreFunction(JSRuntimeHelper *runtimeHelper, const jsi::Value &workletObject);
|
|
82
82
|
template <typename... Args>
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
inline void runOnUIGuarded(const jsi::Value &function, Args &&...args) {
|
|
84
|
+
// We only use callGuard in debug mode, otherwise we call the provided
|
|
85
|
+
// function directly. CallGuard provides a way of capturing exceptions in
|
|
86
|
+
// JavaScript and propagating them to the main React Native thread such that
|
|
87
|
+
// they can be presented using RN's LogBox.
|
|
88
|
+
jsi::Runtime &rt = *uiRuntime_;
|
|
89
|
+
#ifdef DEBUG
|
|
90
|
+
callGuard->call(rt, function, args...);
|
|
91
|
+
#else
|
|
92
|
+
function.asObject(rt).asFunction(rt).call(rt, args...);
|
|
93
|
+
#endif
|
|
85
94
|
}
|
|
86
95
|
};
|
|
87
96
|
|
|
@@ -106,9 +115,7 @@ class Shareable {
|
|
|
106
115
|
RemoteFunctionType,
|
|
107
116
|
HandleType,
|
|
108
117
|
SynchronizedDataHolder,
|
|
109
|
-
|
|
110
|
-
ShadowNode,
|
|
111
|
-
#endif
|
|
118
|
+
HostObjectType,
|
|
112
119
|
};
|
|
113
120
|
|
|
114
121
|
explicit Shareable(ValueType valueType) : valueType_(valueType) {}
|
|
@@ -126,34 +133,57 @@ class Shareable {
|
|
|
126
133
|
ValueType valueType_;
|
|
127
134
|
};
|
|
128
135
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
std::shared_ptr<JSRuntimeHelper> runtimeHelper_;
|
|
132
|
-
|
|
133
|
-
#if HAS_JS_WEAK_OBJECTS
|
|
134
|
-
|
|
136
|
+
template <typename BaseClass>
|
|
137
|
+
class RetainingShareable : virtual public BaseClass {
|
|
135
138
|
private:
|
|
136
|
-
std::
|
|
137
|
-
|
|
138
|
-
public:
|
|
139
|
-
jsi::Value getJSValue(jsi::Runtime &rt) final;
|
|
140
|
-
|
|
141
|
-
RetainingShareable(
|
|
142
|
-
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
|
|
143
|
-
jsi::Runtime &rt,
|
|
144
|
-
ValueType valueType)
|
|
145
|
-
: Shareable(valueType), runtimeHelper_(runtimeHelper) {}
|
|
146
|
-
|
|
147
|
-
~RetainingShareable();
|
|
148
|
-
#else
|
|
139
|
+
std::shared_ptr<JSRuntimeHelper> runtimeHelper_;
|
|
140
|
+
std::unique_ptr<jsi::Value> remoteValue_;
|
|
149
141
|
|
|
150
142
|
public:
|
|
143
|
+
template <typename... Args>
|
|
151
144
|
RetainingShareable(
|
|
152
145
|
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
146
|
+
Args &&...args)
|
|
147
|
+
: BaseClass(std::forward<Args>(args)...), runtimeHelper_(runtimeHelper) {}
|
|
148
|
+
jsi::Value getJSValue(jsi::Runtime &rt) {
|
|
149
|
+
if (runtimeHelper_->isRNRuntime(rt)) {
|
|
150
|
+
// TODO: it is suboptimal to generate new object every time getJS is
|
|
151
|
+
// called on host runtime – the objects we are generating already exists
|
|
152
|
+
// and we should possibly just grab a hold of such object and use it here
|
|
153
|
+
// instead of creating a new JS representation. As far as I understand the
|
|
154
|
+
// only case where it can be realistically called this way is when a
|
|
155
|
+
// shared value is created and then accessed on the same runtime
|
|
156
|
+
return BaseClass::toJSValue(rt);
|
|
157
|
+
} else if (remoteValue_ == nullptr) {
|
|
158
|
+
auto value = BaseClass::toJSValue(rt);
|
|
159
|
+
remoteValue_ = std::make_unique<jsi::Value>(rt, value);
|
|
160
|
+
return value;
|
|
161
|
+
}
|
|
162
|
+
return jsi::Value(rt, *remoteValue_);
|
|
163
|
+
}
|
|
164
|
+
~RetainingShareable() {
|
|
165
|
+
if (runtimeHelper_->uiRuntimeDestroyed) {
|
|
166
|
+
// The below use of unique_ptr.release prevents the smart pointer from
|
|
167
|
+
// calling the destructor of the kept object. This effectively results in
|
|
168
|
+
// leaking some memory. We do this on purpose, as sometimes we would keep
|
|
169
|
+
// references to JSI objects past the lifetime of its runtime (e.g.,
|
|
170
|
+
// shared values references from the RN VM holds reference to JSI objects
|
|
171
|
+
// on the UI runtime). When the UI runtime is terminated, the orphaned JSI
|
|
172
|
+
// objects would crash the app when their destructors are called, because
|
|
173
|
+
// they call into a memory that's managed by the terminated runtime. We
|
|
174
|
+
// accept the tradeoff of leaking memory here, as it has a limited impact.
|
|
175
|
+
// This scenario can only occur when the React instance is torn down which
|
|
176
|
+
// happens in development mode during app reloads, or in production when
|
|
177
|
+
// the app is being shut down gracefully by the system. An alternative
|
|
178
|
+
// solution would require us to keep track of all JSI values that are in
|
|
179
|
+
// use which would require additional data structure and compute spent on
|
|
180
|
+
// bookkeeping that only for the sake of destroying the values in time
|
|
181
|
+
// before the runtime is terminated. Note that the underlying memory that
|
|
182
|
+
// jsi::Value refers to is managed by the VM and gets freed along with the
|
|
183
|
+
// runtime.
|
|
184
|
+
remoteValue_.release();
|
|
185
|
+
}
|
|
186
|
+
}
|
|
157
187
|
};
|
|
158
188
|
|
|
159
189
|
class ShareableJSRef : public jsi::HostObject {
|
|
@@ -195,12 +225,9 @@ std::shared_ptr<T> extractShareableOrThrow(
|
|
|
195
225
|
return res;
|
|
196
226
|
}
|
|
197
227
|
|
|
198
|
-
class ShareableArray : public
|
|
228
|
+
class ShareableArray : public Shareable {
|
|
199
229
|
public:
|
|
200
|
-
ShareableArray(
|
|
201
|
-
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
|
|
202
|
-
jsi::Runtime &rt,
|
|
203
|
-
const jsi::Array &array);
|
|
230
|
+
ShareableArray(jsi::Runtime &rt, const jsi::Array &array);
|
|
204
231
|
|
|
205
232
|
jsi::Value toJSValue(jsi::Runtime &rt) override {
|
|
206
233
|
auto size = data_.size();
|
|
@@ -215,12 +242,9 @@ class ShareableArray : public RetainingShareable {
|
|
|
215
242
|
std::vector<std::shared_ptr<Shareable>> data_;
|
|
216
243
|
};
|
|
217
244
|
|
|
218
|
-
class ShareableObject : public
|
|
245
|
+
class ShareableObject : public Shareable {
|
|
219
246
|
public:
|
|
220
|
-
ShareableObject(
|
|
221
|
-
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
|
|
222
|
-
jsi::Runtime &rt,
|
|
223
|
-
const jsi::Object &object);
|
|
247
|
+
ShareableObject(jsi::Runtime &rt, const jsi::Object &object);
|
|
224
248
|
jsi::Value toJSValue(jsi::Runtime &rt) override {
|
|
225
249
|
auto obj = jsi::Object(rt);
|
|
226
250
|
for (size_t i = 0, size = data_.size(); i < size; i++) {
|
|
@@ -234,34 +258,31 @@ class ShareableObject : public RetainingShareable {
|
|
|
234
258
|
std::vector<std::pair<std::string, std::shared_ptr<Shareable>>> data_;
|
|
235
259
|
};
|
|
236
260
|
|
|
237
|
-
|
|
238
|
-
class ShareableShadowNodeWrapper : public Shareable {
|
|
239
|
-
private:
|
|
240
|
-
react::ShadowNode::Shared shadowNode_;
|
|
241
|
-
|
|
261
|
+
class ShareableHostObject : public Shareable {
|
|
242
262
|
public:
|
|
243
|
-
|
|
263
|
+
ShareableHostObject(
|
|
244
264
|
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
|
|
245
265
|
jsi::Runtime &rt,
|
|
246
|
-
const jsi::
|
|
247
|
-
: Shareable(
|
|
248
|
-
shadowNode_ =
|
|
249
|
-
wrapperObject.getHostObject<ShadowNodeWrapper>(rt)->shadowNode;
|
|
250
|
-
}
|
|
266
|
+
const std::shared_ptr<jsi::HostObject> &hostObject)
|
|
267
|
+
: Shareable(HostObjectType), hostObject_(hostObject) {}
|
|
251
268
|
jsi::Value toJSValue(jsi::Runtime &rt) override {
|
|
252
|
-
return jsi::Object::createFromHostObject(
|
|
253
|
-
rt, std::make_shared<ShadowNodeWrapper>(shadowNode_));
|
|
269
|
+
return jsi::Object::createFromHostObject(rt, hostObject_);
|
|
254
270
|
}
|
|
271
|
+
|
|
272
|
+
protected:
|
|
273
|
+
std::shared_ptr<jsi::HostObject> hostObject_;
|
|
255
274
|
};
|
|
256
|
-
#endif
|
|
257
275
|
|
|
258
276
|
class ShareableWorklet : public ShareableObject {
|
|
277
|
+
private:
|
|
278
|
+
std::shared_ptr<JSRuntimeHelper> runtimeHelper_;
|
|
279
|
+
|
|
259
280
|
public:
|
|
260
281
|
ShareableWorklet(
|
|
261
282
|
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
|
|
262
283
|
jsi::Runtime &rt,
|
|
263
284
|
const jsi::Object &worklet)
|
|
264
|
-
: ShareableObject(
|
|
285
|
+
: ShareableObject(rt, worklet), runtimeHelper_(runtimeHelper) {
|
|
265
286
|
valueType_ = WorkletType;
|
|
266
287
|
}
|
|
267
288
|
jsi::Value toJSValue(jsi::Runtime &rt) override {
|
|
@@ -271,18 +292,20 @@ class ShareableWorklet : public ShareableObject {
|
|
|
271
292
|
};
|
|
272
293
|
|
|
273
294
|
class ShareableRemoteFunction
|
|
274
|
-
: public
|
|
295
|
+
: public Shareable,
|
|
275
296
|
public std::enable_shared_from_this<ShareableRemoteFunction> {
|
|
276
297
|
private:
|
|
277
298
|
jsi::Function function_;
|
|
299
|
+
std::shared_ptr<JSRuntimeHelper> runtimeHelper_;
|
|
278
300
|
|
|
279
301
|
public:
|
|
280
302
|
ShareableRemoteFunction(
|
|
281
303
|
const std::shared_ptr<JSRuntimeHelper> &runtimeHelper,
|
|
282
304
|
jsi::Runtime &rt,
|
|
283
305
|
jsi::Function &&function)
|
|
284
|
-
:
|
|
285
|
-
function_(std::move(function))
|
|
306
|
+
: Shareable(RemoteFunctionType),
|
|
307
|
+
function_(std::move(function)),
|
|
308
|
+
runtimeHelper_(runtimeHelper) {}
|
|
286
309
|
jsi::Value toJSValue(jsi::Runtime &rt) override {
|
|
287
310
|
if (runtimeHelper_->isUIRuntime(rt)) {
|
|
288
311
|
#ifdef DEBUG
|
|
@@ -311,8 +334,7 @@ class ShareableHandle : public Shareable {
|
|
|
311
334
|
jsi::Runtime &rt,
|
|
312
335
|
const jsi::Object &initializerObject)
|
|
313
336
|
: Shareable(HandleType), runtimeHelper_(runtimeHelper) {
|
|
314
|
-
initializer_ =
|
|
315
|
-
std::make_unique<ShareableObject>(runtimeHelper, rt, initializerObject);
|
|
337
|
+
initializer_ = std::make_unique<ShareableObject>(rt, initializerObject);
|
|
316
338
|
}
|
|
317
339
|
~ShareableHandle() {
|
|
318
340
|
if (runtimeHelper_->uiRuntimeDestroyed) {
|
|
@@ -357,7 +379,7 @@ class ShareableSynchronizedDataHolder
|
|
|
357
379
|
std::shared_ptr<Shareable> data_;
|
|
358
380
|
std::shared_ptr<jsi::Value> uiValue_;
|
|
359
381
|
std::shared_ptr<jsi::Value> rnValue_;
|
|
360
|
-
std::mutex
|
|
382
|
+
std::mutex dataAccessMutex_; // Protects `data_`.
|
|
361
383
|
|
|
362
384
|
public:
|
|
363
385
|
ShareableSynchronizedDataHolder(
|
|
@@ -369,7 +391,7 @@ class ShareableSynchronizedDataHolder
|
|
|
369
391
|
data_(extractShareableOrThrow(rt, initialValue)) {}
|
|
370
392
|
|
|
371
393
|
jsi::Value get(jsi::Runtime &rt) {
|
|
372
|
-
std::unique_lock<std::mutex> read_lock(
|
|
394
|
+
std::unique_lock<std::mutex> read_lock(dataAccessMutex_);
|
|
373
395
|
if (runtimeHelper_->isUIRuntime(rt)) {
|
|
374
396
|
if (uiValue_ == nullptr) {
|
|
375
397
|
auto value = data_->getJSValue(rt);
|
|
@@ -390,7 +412,7 @@ class ShareableSynchronizedDataHolder
|
|
|
390
412
|
}
|
|
391
413
|
|
|
392
414
|
void set(jsi::Runtime &rt, const jsi::Value &data) {
|
|
393
|
-
std::unique_lock<std::mutex> write_lock(
|
|
415
|
+
std::unique_lock<std::mutex> write_lock(dataAccessMutex_);
|
|
394
416
|
data_ = extractShareableOrThrow(rt, data);
|
|
395
417
|
uiValue_.reset();
|
|
396
418
|
rnValue_.reset();
|
|
@@ -403,16 +425,14 @@ class ShareableSynchronizedDataHolder
|
|
|
403
425
|
|
|
404
426
|
class ShareableString : public Shareable {
|
|
405
427
|
public:
|
|
406
|
-
ShareableString(
|
|
407
|
-
: Shareable(StringType) {
|
|
408
|
-
data = string.utf8(rt);
|
|
409
|
-
}
|
|
428
|
+
explicit ShareableString(const std::string &string)
|
|
429
|
+
: Shareable(StringType), data_(string) {}
|
|
410
430
|
jsi::Value toJSValue(jsi::Runtime &rt) override {
|
|
411
|
-
return jsi::String::createFromUtf8(rt,
|
|
431
|
+
return jsi::String::createFromUtf8(rt, data_);
|
|
412
432
|
}
|
|
413
433
|
|
|
414
434
|
protected:
|
|
415
|
-
std::string
|
|
435
|
+
std::string data_;
|
|
416
436
|
};
|
|
417
437
|
|
|
418
438
|
class ShareableScalar : public Shareable {
|