react-native-reanimated 2.3.0-alpha.1 → 2.3.0-beta.2
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/LayoutAnimations/LayoutAnimationsProxy.cpp +15 -8
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +170 -166
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +36 -34
- package/Common/cpp/Registries/EventHandlerRegistry.cpp +13 -6
- package/Common/cpp/Registries/MapperRegistry.cpp +19 -15
- package/Common/cpp/Registries/WorkletsCache.cpp +19 -9
- package/Common/cpp/SharedItems/FrozenObject.cpp +19 -8
- package/Common/cpp/SharedItems/MutableValue.cpp +38 -25
- package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +11 -7
- package/Common/cpp/SharedItems/RemoteObject.cpp +9 -5
- package/Common/cpp/SharedItems/ShareableValue.cpp +216 -143
- package/Common/cpp/Tools/JSIStoreValueUser.cpp +36 -24
- package/Common/cpp/Tools/Mapper.cpp +41 -29
- package/Common/cpp/Tools/RuntimeDecorator.cpp +103 -84
- package/Common/cpp/Tools/Scheduler.cpp +14 -6
- package/Common/cpp/Tools/WorkletEventHandler.cpp +1 -1
- package/Common/cpp/headers/LayoutAnimations/LayoutAnimationsProxy.h +12 -11
- package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +45 -34
- package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +28 -16
- package/Common/cpp/headers/Registries/EventHandlerRegistry.h +14 -8
- package/Common/cpp/headers/Registries/MapperRegistry.h +4 -4
- package/Common/cpp/headers/Registries/WorkletsCache.h +9 -7
- package/Common/cpp/headers/SharedItems/FrozenObject.h +15 -11
- package/Common/cpp/headers/SharedItems/HostFunctionHandler.h +6 -4
- package/Common/cpp/headers/SharedItems/MutableValue.h +21 -12
- package/Common/cpp/headers/SharedItems/MutableValueSetterProxy.h +10 -7
- package/Common/cpp/headers/SharedItems/RemoteObject.h +16 -8
- package/Common/cpp/headers/SharedItems/RuntimeManager.h +39 -21
- package/Common/cpp/headers/SharedItems/ShareableValue.h +31 -27
- package/Common/cpp/headers/SharedItems/SharedParent.h +7 -4
- package/Common/cpp/headers/SharedItems/ValueWrapper.h +80 -61
- package/Common/cpp/headers/SpecTools/ErrorHandler.h +17 -19
- package/Common/cpp/headers/Tools/JSIStoreValueUser.h +18 -13
- package/Common/cpp/headers/Tools/Mapper.h +24 -18
- package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +12 -7
- package/Common/cpp/headers/Tools/ReanimatedHiddenHeaders.h +7 -7
- package/Common/cpp/headers/Tools/RuntimeDecorator.h +29 -23
- package/Common/cpp/headers/Tools/Scheduler.h +28 -33
- package/Common/cpp/headers/Tools/WorkletEventHandler.h +9 -7
- package/Common/cpp/hidden_headers/Logger.h +14 -14
- package/Common/cpp/hidden_headers/LoggerInterface.h +8 -9
- package/Common/cpp/hidden_headers/SpeedChecker.h +7 -8
- package/README.md +1 -1
- package/RNReanimated.podspec +4 -4
- package/android/build.gradle +80 -3
- package/android/react-native-reanimated-63-hermes.aar +0 -0
- package/android/react-native-reanimated-63-jsc.aar +0 -0
- package/android/react-native-reanimated-64-hermes.aar +0 -0
- package/android/react-native-reanimated-64-jsc.aar +0 -0
- package/android/react-native-reanimated-65-hermes.aar +0 -0
- package/android/react-native-reanimated-65-jsc.aar +0 -0
- package/android/react-native-reanimated-66-hermes.aar +0 -0
- package/android/react-native-reanimated-66-jsc.aar +0 -0
- package/ios/LayoutReanimation/REAAnimationsManager.h +19 -10
- package/ios/LayoutReanimation/REAAnimationsManager.m +195 -200
- package/ios/LayoutReanimation/REASnapshot.h +13 -0
- package/ios/LayoutReanimation/REASnapshot.m +29 -0
- package/ios/LayoutReanimation/REAUIManager.h +16 -0
- package/ios/LayoutReanimation/REAUIManager.mm +348 -0
- package/ios/Nodes/REAAlwaysNode.m +14 -15
- package/ios/Nodes/REABezierNode.m +8 -7
- package/ios/Nodes/REABlockNode.m +1 -1
- package/ios/Nodes/REACallFuncNode.h +0 -1
- package/ios/Nodes/REACallFuncNode.m +10 -8
- package/ios/Nodes/REAClockNodes.m +22 -20
- package/ios/Nodes/REAConcatNode.h +0 -1
- package/ios/Nodes/REAConcatNode.m +2 -2
- package/ios/Nodes/REACondNode.m +7 -5
- package/ios/Nodes/READebugNode.m +5 -4
- package/ios/Nodes/REAEventNode.m +1 -1
- package/ios/Nodes/REAFunctionNode.h +0 -1
- package/ios/Nodes/REAFunctionNode.m +2 -2
- package/ios/Nodes/REAJSCallNode.m +4 -5
- package/ios/Nodes/REANode.h +3 -4
- package/ios/Nodes/REANode.m +9 -11
- package/ios/Nodes/REAOperatorNode.m +68 -67
- package/ios/Nodes/REAParamNode.h +1 -3
- package/ios/Nodes/REAParamNode.m +15 -17
- package/ios/Nodes/REAPropsNode.h +1 -3
- package/ios/Nodes/REAPropsNode.m +19 -22
- package/ios/Nodes/REASetNode.h +0 -1
- package/ios/Nodes/REASetNode.m +7 -5
- package/ios/Nodes/REAStyleNode.h +0 -1
- package/ios/Nodes/REAStyleNode.m +2 -4
- package/ios/Nodes/REATransformNode.h +0 -1
- package/ios/Nodes/REATransformNode.m +3 -5
- package/ios/Nodes/REAValueNode.m +5 -7
- package/ios/REAEventDispatcher.m +3 -3
- package/ios/REAModule.h +0 -2
- package/ios/REAModule.m +29 -40
- package/ios/REANodesManager.h +11 -19
- package/ios/REANodesManager.m +105 -130
- package/ios/REAUtils.h +5 -3
- package/ios/Transitioning/RCTConvert+REATransition.m +45 -29
- package/ios/Transitioning/REAAllTransitions.h +2 -2
- package/ios/Transitioning/REAAllTransitions.m +14 -25
- package/ios/Transitioning/REATransition.h +8 -7
- package/ios/Transitioning/REATransition.m +19 -16
- package/ios/Transitioning/REATransitionAnimation.h +1 -1
- package/ios/Transitioning/REATransitionAnimation.m +2 -3
- package/ios/Transitioning/REATransitionManager.m +3 -3
- package/ios/native/NativeMethods.h +15 -5
- package/ios/native/NativeProxy.h +4 -3
- package/ios/native/NativeProxy.mm +19 -5
- package/ios/native/REAIOSErrorHandler.h +13 -10
- package/ios/native/REAIOSLogger.h +8 -8
- package/ios/native/REAIOSScheduler.h +5 -5
- package/ios/native/REAIOSScheduler.mm +7 -5
- package/ios/native/REAInitializer.h +37 -0
- package/ios/native/REAInitializer.mm +63 -0
- package/ios/native/UIResponder+Reanimated.mm +9 -48
- package/lib/ConfigHelper.js +1 -0
- package/lib/ReanimatedModule.native.js +10 -2
- package/lib/createAnimatedComponent.js +64 -30
- package/lib/reanimated1/core/AnimatedAlways.js +1 -1
- package/lib/reanimated1/core/AnimatedBezier.js +1 -1
- package/lib/reanimated1/core/AnimatedBlock.js +1 -1
- package/lib/reanimated1/core/AnimatedCall.js +1 -1
- package/lib/reanimated1/core/AnimatedCallFunc.js +1 -1
- package/lib/reanimated1/core/AnimatedConcat.js +1 -1
- package/lib/reanimated1/core/AnimatedCond.js +1 -1
- package/lib/reanimated1/core/AnimatedDebug.js +1 -1
- package/lib/reanimated1/core/AnimatedEvent.js +1 -1
- package/lib/reanimated1/core/AnimatedFunction.js +1 -1
- package/lib/reanimated1/core/AnimatedOperator.js +1 -1
- package/lib/reanimated1/core/AnimatedParam.js +1 -1
- package/lib/reanimated1/core/AnimatedProps.js +2 -2
- package/lib/reanimated1/core/AnimatedSet.js +1 -1
- package/lib/reanimated1/core/AnimatedStartClock.js +1 -1
- package/lib/reanimated1/core/AnimatedStopClock.js +1 -1
- package/lib/reanimated1/core/AnimatedStyle.js +1 -1
- package/lib/reanimated1/core/AnimatedTransform.js +1 -1
- package/lib/reanimated1/core/Core.test.js +30 -0
- package/lib/reanimated1/core/InternalAnimatedValue.js +1 -1
- package/lib/reanimated1/core/__mocks__/AnimatedProps.js +1 -1
- package/lib/reanimated1/derived/interpolate.js +1 -1
- package/lib/reanimated2/Colors.js +16 -12
- package/lib/reanimated2/NativeMethods.js +3 -14
- package/lib/reanimated2/{NativeReanimated.native.js → NativeReanimated/NativeReanimated.js} +19 -24
- package/lib/reanimated2/NativeReanimated/index.js +15 -0
- package/lib/reanimated2/PlatformChecker.js +16 -0
- package/lib/reanimated2/PropAdapters.js +14 -4
- package/lib/reanimated2/UpdateProps.js +14 -11
- package/lib/reanimated2/ViewDescriptorsSet.js +73 -0
- package/lib/reanimated2/WorkletEventHandler.js +15 -13
- package/lib/reanimated2/animation/commonTypes.js +1 -0
- package/lib/reanimated2/animation/decay.js +71 -0
- package/lib/reanimated2/animation/delay.js +64 -0
- package/lib/reanimated2/animation/index.js +8 -0
- package/lib/reanimated2/animation/repeat.js +69 -0
- package/lib/reanimated2/animation/sequence.js +72 -0
- package/lib/reanimated2/animation/spring.js +101 -0
- package/lib/reanimated2/animation/styleAnimation.js +166 -0
- package/lib/reanimated2/animation/timing.js +64 -0
- package/lib/reanimated2/animation/util.js +157 -0
- package/lib/reanimated2/commonTypes.js +1 -0
- package/lib/reanimated2/core.js +35 -39
- package/lib/reanimated2/globals.d.ts +47 -1
- package/lib/reanimated2/hook/Hooks.js +9 -0
- package/lib/reanimated2/hook/commonTypes.js +1 -0
- package/lib/reanimated2/hook/index.js +8 -0
- package/lib/reanimated2/hook/useAnimatedGestureHandler.js +50 -0
- package/lib/reanimated2/hook/useAnimatedReaction.js +37 -0
- package/lib/reanimated2/hook/useAnimatedRef.js +25 -0
- package/lib/reanimated2/hook/useAnimatedScrollHandler.js +41 -0
- package/lib/reanimated2/hook/useAnimatedStyle.js +376 -0
- package/lib/reanimated2/hook/useDerivedValue.js +36 -0
- package/lib/reanimated2/hook/useSharedValue.js +17 -0
- package/lib/reanimated2/hook/utils.js +175 -0
- package/lib/reanimated2/index.js +3 -2
- package/lib/reanimated2/interpolation.js +95 -86
- package/lib/reanimated2/jestUtils.js +0 -12
- package/lib/reanimated2/js-reanimated/JSReanimated.js +9 -10
- package/lib/reanimated2/js-reanimated/index.js +57 -1
- package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +58 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +69 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +125 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +193 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +1 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/index.js +3 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +325 -207
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +36 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +235 -187
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +327 -269
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +146 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +85 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +119 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +289 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +159 -121
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +83 -65
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +371 -277
- package/lib/reanimated2/layoutReanimation/defaultAnimations/index.js +4 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +78 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +128 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +37 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +41 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +34 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +46 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/index.js +6 -0
- package/lib/reanimated2/layoutReanimation/index.js +3 -2
- package/lib/reanimated2/platform-specific/RNRenderer.web.js +2 -0
- package/lib/reanimated2/utils.js +9 -0
- package/libSo/fbjni/jni/arm64-v8a/libfbjni.so +0 -0
- package/libSo/fbjni/jni/armeabi-v7a/libfbjni.so +0 -0
- package/libSo/fbjni/jni/x86/libfbjni.so +0 -0
- package/libSo/fbjni/jni/x86_64/libfbjni.so +0 -0
- package/package.json +21 -10
- package/plugin.js +244 -85
- package/react-native-reanimated.d.ts +531 -453
- package/src/ConfigHelper.js +1 -0
- package/src/ReanimatedModule.native.js +10 -2
- package/src/createAnimatedComponent.js +64 -30
- package/src/reanimated1/core/AnimatedAlways.js +1 -1
- package/src/reanimated1/core/AnimatedBezier.js +1 -1
- package/src/reanimated1/core/AnimatedBlock.js +1 -1
- package/src/reanimated1/core/AnimatedCall.js +1 -1
- package/src/reanimated1/core/AnimatedCallFunc.js +1 -1
- package/src/reanimated1/core/AnimatedConcat.js +1 -1
- package/src/reanimated1/core/AnimatedCond.js +1 -1
- package/src/reanimated1/core/AnimatedDebug.js +1 -1
- package/src/reanimated1/core/AnimatedEvent.js +1 -1
- package/src/reanimated1/core/AnimatedFunction.js +1 -1
- package/src/reanimated1/core/AnimatedOperator.js +1 -1
- package/src/reanimated1/core/AnimatedParam.js +1 -1
- package/src/reanimated1/core/AnimatedProps.js +2 -2
- package/src/reanimated1/core/AnimatedSet.js +1 -1
- package/src/reanimated1/core/AnimatedStartClock.js +1 -1
- package/src/reanimated1/core/AnimatedStopClock.js +1 -1
- package/src/reanimated1/core/AnimatedStyle.js +1 -1
- package/src/reanimated1/core/AnimatedTransform.js +1 -1
- package/src/reanimated1/core/Core.test.js +30 -0
- package/src/reanimated1/core/InternalAnimatedValue.js +1 -1
- package/src/reanimated1/core/__mocks__/AnimatedProps.js +1 -1
- package/src/reanimated1/derived/interpolate.js +1 -1
- package/src/reanimated2/Colors.ts +30 -27
- package/src/reanimated2/Easing.ts +3 -1
- package/src/reanimated2/NativeMethods.ts +26 -16
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +78 -0
- package/src/reanimated2/NativeReanimated/index.ts +18 -0
- package/src/reanimated2/PlatformChecker.ts +21 -0
- package/src/reanimated2/PropAdapters.ts +52 -34
- package/src/reanimated2/UpdateProps.ts +40 -20
- package/src/reanimated2/ViewDescriptorsSet.ts +108 -0
- package/src/reanimated2/WorkletEventHandler.ts +41 -23
- package/src/reanimated2/animation/commonTypes.ts +48 -0
- package/src/reanimated2/animation/decay.ts +141 -0
- package/src/reanimated2/animation/delay.ts +103 -0
- package/src/reanimated2/animation/index.ts +16 -0
- package/src/reanimated2/animation/repeat.ts +128 -0
- package/src/reanimated2/animation/sequence.ts +110 -0
- package/src/reanimated2/animation/spring.ts +165 -0
- package/src/reanimated2/animation/styleAnimation.ts +253 -0
- package/src/reanimated2/animation/timing.ts +109 -0
- package/src/reanimated2/animation/util.ts +242 -0
- package/src/reanimated2/commonTypes.ts +81 -0
- package/src/reanimated2/core.ts +128 -82
- package/src/reanimated2/globals.d.ts +47 -1
- package/src/reanimated2/hook/Hooks.ts +16 -0
- package/src/reanimated2/hook/commonTypes.ts +12 -0
- package/src/reanimated2/hook/index.ts +25 -0
- package/src/reanimated2/hook/useAnimatedGestureHandler.ts +110 -0
- package/src/reanimated2/hook/useAnimatedReaction.ts +49 -0
- package/src/reanimated2/hook/useAnimatedRef.ts +34 -0
- package/src/reanimated2/hook/useAnimatedScrollHandler.ts +83 -0
- package/src/reanimated2/hook/useAnimatedStyle.ts +538 -0
- package/src/reanimated2/hook/useDerivedValue.ts +48 -0
- package/src/reanimated2/hook/useSharedValue.ts +22 -0
- package/src/reanimated2/hook/utils.ts +259 -0
- package/src/reanimated2/index.ts +3 -2
- package/src/reanimated2/interpolation.ts +170 -101
- package/src/reanimated2/jestUtils.ts +0 -12
- package/src/reanimated2/js-reanimated/JSReanimated.ts +47 -22
- package/src/reanimated2/js-reanimated/Mapper.ts +1 -1
- package/src/reanimated2/js-reanimated/index.ts +71 -0
- package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.tsx +62 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.ts +91 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +169 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +263 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +78 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +16 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +243 -121
- package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +43 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +95 -53
- package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +114 -64
- package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +179 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +93 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +132 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +333 -0
- package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +84 -50
- package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +41 -23
- package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +234 -154
- package/src/reanimated2/layoutReanimation/defaultAnimations/index.ts +4 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +104 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +213 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +60 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +58 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +41 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +78 -0
- package/src/reanimated2/layoutReanimation/defaultTransitions/index.ts +6 -0
- package/src/reanimated2/layoutReanimation/index.ts +3 -2
- package/src/reanimated2/platform-specific/RNRenderer.web.ts +2 -0
- package/src/reanimated2/utils.ts +21 -0
- package/android/react-native-reanimated-62-hermes.aar +0 -0
- package/android/react-native-reanimated-62-jsc.aar +0 -0
- package/ios/LayoutReanimation/REAAnimationRootView.h +0 -12
- package/ios/LayoutReanimation/REAAnimationRootView.m +0 -16
- package/ios/LayoutReanimation/REAAnimationRootViewManager.h +0 -9
- package/ios/LayoutReanimation/REAAnimationRootViewManager.m +0 -49
- package/ios/LayoutReanimation/REAReactBatchObserver.h +0 -20
- package/ios/LayoutReanimation/REAReactBatchObserver.m +0 -125
- package/ios/LayoutReanimation/REASnapshooter.h +0 -19
- package/ios/LayoutReanimation/REASnapshooter.m +0 -64
- package/ios/LayoutReanimation/REAViewTraverser.h +0 -13
- package/ios/LayoutReanimation/REAViewTraverser.m +0 -40
- package/lib/reanimated2/Hooks.js +0 -732
- package/lib/reanimated2/NativeReanimated.js +0 -4
- package/lib/reanimated2/animations.js +0 -713
- package/lib/reanimated2/js-reanimated/index.web.js +0 -20
- package/lib/reanimated2/layoutReanimation/AnimatedRoot.js +0 -55
- package/lib/reanimated2/layoutReanimation/defaultAnimationsBuilder.js +0 -374
- package/src/reanimated2/Hooks.ts +0 -918
- package/src/reanimated2/NativeReanimated.native.ts +0 -61
- package/src/reanimated2/NativeReanimated.ts +0 -5
- package/src/reanimated2/animations.ts +0 -868
- package/src/reanimated2/js-reanimated/index.js +0 -0
- package/src/reanimated2/js-reanimated/index.web.ts +0 -29
- package/src/reanimated2/layoutReanimation/AnimatedRoot.tsx +0 -68
- package/src/reanimated2/layoutReanimation/defaultAnimationsBuilder.ts +0 -440
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
#include
|
|
2
|
-
#include "
|
|
3
|
-
#include "RuntimeManager.h"
|
|
1
|
+
#include <cxxabi.h>
|
|
2
|
+
#include "FrozenObject.h"
|
|
4
3
|
#include "MutableValue.h"
|
|
5
4
|
#include "MutableValueSetterProxy.h"
|
|
6
5
|
#include "RemoteObject.h"
|
|
7
|
-
#include "FrozenObject.h"
|
|
8
6
|
#include "RuntimeDecorator.h"
|
|
7
|
+
#include "RuntimeManager.h"
|
|
8
|
+
#include "SharedParent.h"
|
|
9
9
|
|
|
10
10
|
namespace reanimated {
|
|
11
|
-
|
|
11
|
+
class ShareableValue;
|
|
12
12
|
const char *HIDDEN_HOST_OBJECT_PROP = "__reanimatedHostObjectRef";
|
|
13
|
-
const char *ALREADY_CONVERTED= "__alreadyConverted";
|
|
13
|
+
const char *ALREADY_CONVERTED = "__alreadyConverted";
|
|
14
14
|
const char *CALL_ASYNC = "__callAsync";
|
|
15
15
|
const char *PRIMAL_FUNCTION = "__primalFunction";
|
|
16
16
|
std::string CALLBACK_ERROR_SUFFIX = R"(
|
|
@@ -19,12 +19,14 @@ Possible solutions are:
|
|
|
19
19
|
a) If you want to synchronously execute this method, mark it as a Worklet
|
|
20
20
|
b) If you want to execute this method on the JS thread, wrap it using runOnJS )";
|
|
21
21
|
|
|
22
|
-
void addHiddenProperty(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
void addHiddenProperty(
|
|
23
|
+
jsi::Runtime &rt,
|
|
24
|
+
jsi::Value &&value,
|
|
25
|
+
jsi::Object &obj,
|
|
26
|
+
const char *name) {
|
|
26
27
|
jsi::Object globalObject = rt.global().getPropertyAsObject(rt, "Object");
|
|
27
|
-
jsi::Function defineProperty =
|
|
28
|
+
jsi::Function defineProperty =
|
|
29
|
+
globalObject.getPropertyAsFunction(rt, "defineProperty");
|
|
28
30
|
jsi::String internalPropName = jsi::String::createFromUtf8(rt, name);
|
|
29
31
|
jsi::Object paramForDefineProperty(rt);
|
|
30
32
|
paramForDefineProperty.setProperty(rt, "enumerable", false);
|
|
@@ -39,8 +41,9 @@ void freeze(jsi::Runtime &rt, jsi::Object &obj) {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
void ShareableValue::adaptCache(jsi::Runtime &rt, const jsi::Value &value) {
|
|
42
|
-
// when adapting from host object we can assign cached value immediately such
|
|
43
|
-
// running `toJSValue` in the future when given object is
|
|
44
|
+
// when adapting from host object we can assign cached value immediately such
|
|
45
|
+
// that we avoid running `toJSValue` in the future when given object is
|
|
46
|
+
// accessed
|
|
44
47
|
if (RuntimeDecorator::isWorkletRuntime(rt)) {
|
|
45
48
|
if (remoteValue.expired()) {
|
|
46
49
|
remoteValue = getWeakRef(rt);
|
|
@@ -51,7 +54,10 @@ void ShareableValue::adaptCache(jsi::Runtime &rt, const jsi::Value &value) {
|
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
void ShareableValue::adapt(
|
|
57
|
+
void ShareableValue::adapt(
|
|
58
|
+
jsi::Runtime &rt,
|
|
59
|
+
const jsi::Value &value,
|
|
60
|
+
ValueType objectType) {
|
|
55
61
|
if (value.isObject()) {
|
|
56
62
|
jsi::Object object = value.asObject(rt);
|
|
57
63
|
jsi::Value hiddenValue = object.getProperty(rt, HIDDEN_HOST_OBJECT_PROP);
|
|
@@ -63,8 +69,7 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
|
|
|
63
69
|
type = ValueType::WorkletFunctionType;
|
|
64
70
|
}
|
|
65
71
|
valueContainer = std::make_unique<FrozenObjectWrapper>(
|
|
66
|
-
|
|
67
|
-
);
|
|
72
|
+
hiddenProperty.getHostObject<FrozenObject>(rt));
|
|
68
73
|
if (object.hasProperty(rt, ALREADY_CONVERTED)) {
|
|
69
74
|
adaptCache(rt, value);
|
|
70
75
|
}
|
|
@@ -75,9 +80,9 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
|
|
|
75
80
|
|
|
76
81
|
if (objectType == ValueType::MutableValueType) {
|
|
77
82
|
type = ValueType::MutableValueType;
|
|
78
|
-
valueContainer =
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
valueContainer =
|
|
84
|
+
std::make_unique<MutableValueWrapper>(std::make_shared<MutableValue>(
|
|
85
|
+
rt, value, runtimeManager, runtimeManager->scheduler));
|
|
81
86
|
} else if (value.isUndefined()) {
|
|
82
87
|
type = ValueType::UndefinedType;
|
|
83
88
|
} else if (value.isNull()) {
|
|
@@ -90,7 +95,8 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
|
|
|
90
95
|
valueContainer = std::make_unique<NumberValueWrapper>(value.asNumber());
|
|
91
96
|
} else if (value.isString()) {
|
|
92
97
|
type = ValueType::StringType;
|
|
93
|
-
valueContainer =
|
|
98
|
+
valueContainer =
|
|
99
|
+
std::make_unique<StringValueWrapper>(value.asString(rt).utf8(rt));
|
|
94
100
|
} else if (value.isObject()) {
|
|
95
101
|
auto object = value.asObject(rt);
|
|
96
102
|
if (object.isFunction(rt)) {
|
|
@@ -99,32 +105,39 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
|
|
|
99
105
|
type = ValueType::HostFunctionType;
|
|
100
106
|
containsHostFunction = true;
|
|
101
107
|
|
|
102
|
-
//Check if it's a hostFunction wrapper
|
|
108
|
+
// Check if it's a hostFunction wrapper
|
|
103
109
|
jsi::Value primalFunction = object.getProperty(rt, PRIMAL_FUNCTION);
|
|
104
110
|
if (!primalFunction.isUndefined()) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
jsi::Object handlerAsObject = primalFunction.asObject(rt);
|
|
112
|
+
std::shared_ptr<HostFunctionHandler> handler =
|
|
113
|
+
handlerAsObject.getHostObject<HostFunctionHandler>(rt);
|
|
114
|
+
valueContainer = std::make_unique<HostFunctionWrapper>(handler);
|
|
108
115
|
} else {
|
|
109
|
-
|
|
110
|
-
std::make_shared<HostFunctionHandler>(
|
|
116
|
+
valueContainer = std::make_unique<HostFunctionWrapper>(
|
|
117
|
+
std::make_shared<HostFunctionHandler>(
|
|
118
|
+
std::make_shared<jsi::Function>(object.asFunction(rt)), rt));
|
|
111
119
|
}
|
|
112
120
|
|
|
113
121
|
} else {
|
|
114
122
|
// a worklet
|
|
115
123
|
type = ValueType::WorkletFunctionType;
|
|
116
|
-
valueContainer = std::make_unique<FrozenObjectWrapper>(
|
|
117
|
-
|
|
124
|
+
valueContainer = std::make_unique<FrozenObjectWrapper>(
|
|
125
|
+
std::make_shared<FrozenObject>(rt, object, runtimeManager));
|
|
126
|
+
auto &frozenObject = ValueWrapper::asFrozenObject(valueContainer);
|
|
118
127
|
containsHostFunction |= frozenObject->containsHostFunction;
|
|
119
128
|
if (RuntimeDecorator::isReactRuntime(rt) && !containsHostFunction) {
|
|
120
|
-
addHiddenProperty(
|
|
129
|
+
addHiddenProperty(
|
|
130
|
+
rt,
|
|
131
|
+
createHost(rt, frozenObject),
|
|
132
|
+
object,
|
|
133
|
+
HIDDEN_HOST_OBJECT_PROP);
|
|
121
134
|
}
|
|
122
135
|
}
|
|
123
136
|
} else if (object.isArray(rt)) {
|
|
124
137
|
type = ValueType::FrozenArrayType;
|
|
125
138
|
auto array = object.asArray(rt);
|
|
126
139
|
valueContainer = std::make_unique<FrozenArrayWrapper>();
|
|
127
|
-
auto&
|
|
140
|
+
auto &frozenArray = ValueWrapper::asFrozenArray(valueContainer);
|
|
128
141
|
for (size_t i = 0, size = array.size(rt); i < size; i++) {
|
|
129
142
|
auto sv = adapt(rt, array.getValueAtIndex(rt, i), runtimeManager);
|
|
130
143
|
containsHostFunction |= sv->containsHostFunction;
|
|
@@ -132,51 +145,63 @@ void ShareableValue::adapt(jsi::Runtime &rt, const jsi::Value &value, ValueType
|
|
|
132
145
|
}
|
|
133
146
|
} else if (object.isHostObject<MutableValue>(rt)) {
|
|
134
147
|
type = ValueType::MutableValueType;
|
|
135
|
-
valueContainer = std::make_unique<MutableValueWrapper>(
|
|
148
|
+
valueContainer = std::make_unique<MutableValueWrapper>(
|
|
149
|
+
object.getHostObject<MutableValue>(rt));
|
|
136
150
|
adaptCache(rt, value);
|
|
137
151
|
} else if (object.isHostObject<RemoteObject>(rt)) {
|
|
138
152
|
type = ValueType::RemoteObjectType;
|
|
139
153
|
valueContainer = std::make_unique<RemoteObjectWrapper>(
|
|
140
|
-
|
|
141
|
-
);
|
|
154
|
+
object.getHostObject<RemoteObject>(rt));
|
|
142
155
|
adaptCache(rt, value);
|
|
143
156
|
} else if (objectType == ValueType::RemoteObjectType) {
|
|
144
157
|
type = ValueType::RemoteObjectType;
|
|
145
|
-
valueContainer =
|
|
146
|
-
|
|
147
|
-
|
|
158
|
+
valueContainer =
|
|
159
|
+
std::make_unique<RemoteObjectWrapper>(std::make_shared<RemoteObject>(
|
|
160
|
+
rt, object, runtimeManager, runtimeManager->scheduler));
|
|
148
161
|
} else {
|
|
149
162
|
// create frozen object based on a copy of a given object
|
|
150
163
|
type = ValueType::FrozenObjectType;
|
|
151
164
|
valueContainer = std::make_unique<FrozenObjectWrapper>(
|
|
152
|
-
|
|
153
|
-
);
|
|
154
|
-
auto& frozenObject = ValueWrapper::asFrozenObject(valueContainer);
|
|
165
|
+
std::make_shared<FrozenObject>(rt, object, runtimeManager));
|
|
166
|
+
auto &frozenObject = ValueWrapper::asFrozenObject(valueContainer);
|
|
155
167
|
containsHostFunction |= frozenObject->containsHostFunction;
|
|
156
168
|
if (RuntimeDecorator::isReactRuntime(rt)) {
|
|
157
169
|
if (!containsHostFunction) {
|
|
158
|
-
addHiddenProperty(
|
|
170
|
+
addHiddenProperty(
|
|
171
|
+
rt,
|
|
172
|
+
createHost(rt, frozenObject),
|
|
173
|
+
object,
|
|
174
|
+
HIDDEN_HOST_OBJECT_PROP);
|
|
159
175
|
}
|
|
160
176
|
freeze(rt, object);
|
|
161
177
|
}
|
|
162
178
|
}
|
|
163
179
|
} else if (value.isSymbol()) {
|
|
164
180
|
type = ValueType::StringType;
|
|
165
|
-
valueContainer =
|
|
181
|
+
valueContainer =
|
|
182
|
+
std::make_unique<StringValueWrapper>(value.asSymbol(rt).toString(rt));
|
|
166
183
|
} else {
|
|
167
184
|
throw "Invalid value type";
|
|
168
185
|
}
|
|
169
186
|
}
|
|
170
187
|
|
|
171
|
-
std::shared_ptr<ShareableValue> ShareableValue::adapt(
|
|
172
|
-
|
|
188
|
+
std::shared_ptr<ShareableValue> ShareableValue::adapt(
|
|
189
|
+
jsi::Runtime &rt,
|
|
190
|
+
const jsi::Value &value,
|
|
191
|
+
RuntimeManager *runtimeManager,
|
|
192
|
+
ValueType valueType) {
|
|
193
|
+
auto sv = std::shared_ptr<ShareableValue>(
|
|
194
|
+
new ShareableValue(runtimeManager, runtimeManager->scheduler));
|
|
173
195
|
sv->adapt(rt, value, valueType);
|
|
174
196
|
return sv;
|
|
175
197
|
}
|
|
176
198
|
|
|
177
199
|
jsi::Value ShareableValue::getValue(jsi::Runtime &rt) {
|
|
178
|
-
// TODO: maybe we can cache toJSValue results on a per-runtime basis, need to
|
|
179
|
-
|
|
200
|
+
// TODO: maybe we can cache toJSValue results on a per-runtime basis, need to
|
|
201
|
+
// avoid ref loops
|
|
202
|
+
if (&rt == runtimeManager->runtime.get()) {
|
|
203
|
+
// Getting value on the same runtime where it was created, prepare
|
|
204
|
+
// remoteValue
|
|
180
205
|
if (remoteValue.expired()) {
|
|
181
206
|
remoteValue = getWeakRef(rt);
|
|
182
207
|
}
|
|
@@ -186,6 +211,8 @@ jsi::Value ShareableValue::getValue(jsi::Runtime &rt) {
|
|
|
186
211
|
}
|
|
187
212
|
return jsi::Value(rt, *remoteValue.lock());
|
|
188
213
|
} else {
|
|
214
|
+
// Getting value on a different runtime than where it was created from,
|
|
215
|
+
// prepare hostValue
|
|
189
216
|
if (hostValue.get() == nullptr) {
|
|
190
217
|
hostValue = std::make_unique<jsi::Value>(toJSValue(rt));
|
|
191
218
|
}
|
|
@@ -193,17 +220,23 @@ jsi::Value ShareableValue::getValue(jsi::Runtime &rt) {
|
|
|
193
220
|
}
|
|
194
221
|
}
|
|
195
222
|
|
|
196
|
-
jsi::Object ShareableValue::createHost(
|
|
223
|
+
jsi::Object ShareableValue::createHost(
|
|
224
|
+
jsi::Runtime &rt,
|
|
225
|
+
std::shared_ptr<jsi::HostObject> host) {
|
|
197
226
|
return jsi::Object::createFromHostObject(rt, host);
|
|
198
227
|
}
|
|
199
228
|
|
|
200
|
-
jsi::Value createFrozenWrapper(
|
|
201
|
-
|
|
229
|
+
jsi::Value createFrozenWrapper(
|
|
230
|
+
jsi::Runtime &rt,
|
|
231
|
+
std::shared_ptr<FrozenObject> frozenObject) {
|
|
232
|
+
jsi::Object __reanimatedHiddenHost =
|
|
233
|
+
jsi::Object::createFromHostObject(rt, frozenObject);
|
|
202
234
|
jsi::Object obj = frozenObject->shallowClone(rt);
|
|
203
235
|
jsi::Object globalObject = rt.global().getPropertyAsObject(rt, "Object");
|
|
204
236
|
jsi::Function freeze = globalObject.getPropertyAsFunction(rt, "freeze");
|
|
205
237
|
if (!frozenObject->containsHostFunction) {
|
|
206
|
-
addHiddenProperty(
|
|
238
|
+
addHiddenProperty(
|
|
239
|
+
rt, std::move(__reanimatedHiddenHost), obj, HIDDEN_HOST_OBJECT_PROP);
|
|
207
240
|
addHiddenProperty(rt, true, obj, ALREADY_CONVERTED);
|
|
208
241
|
}
|
|
209
242
|
return freeze.call(rt, obj);
|
|
@@ -220,15 +253,15 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
|
|
|
220
253
|
case ValueType::NumberType:
|
|
221
254
|
return jsi::Value(ValueWrapper::asNumber(valueContainer));
|
|
222
255
|
case ValueType::StringType: {
|
|
223
|
-
auto&
|
|
256
|
+
auto &stringValue = ValueWrapper::asString(valueContainer);
|
|
224
257
|
return jsi::Value(rt, jsi::String::createFromUtf8(rt, stringValue));
|
|
225
258
|
}
|
|
226
259
|
case ValueType::FrozenObjectType: {
|
|
227
|
-
auto&
|
|
260
|
+
auto &frozenObject = ValueWrapper::asFrozenObject(valueContainer);
|
|
228
261
|
return createFrozenWrapper(rt, frozenObject);
|
|
229
262
|
}
|
|
230
263
|
case ValueType::FrozenArrayType: {
|
|
231
|
-
auto&
|
|
264
|
+
auto &frozenArray = ValueWrapper::asFrozenArray(valueContainer);
|
|
232
265
|
jsi::Array array(rt, frozenArray.size());
|
|
233
266
|
for (size_t i = 0; i < frozenArray.size(); i++) {
|
|
234
267
|
array.setValueAtIndex(rt, i, frozenArray[i]->toJSValue(rt));
|
|
@@ -236,45 +269,50 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
|
|
|
236
269
|
return array;
|
|
237
270
|
}
|
|
238
271
|
case ValueType::RemoteObjectType: {
|
|
239
|
-
auto&
|
|
272
|
+
auto &remoteObject = ValueWrapper::asRemoteObject(valueContainer);
|
|
240
273
|
if (RuntimeDecorator::isWorkletRuntime(rt)) {
|
|
241
274
|
remoteObject->maybeInitializeOnWorkletRuntime(rt);
|
|
242
275
|
}
|
|
243
276
|
return createHost(rt, remoteObject);
|
|
244
277
|
}
|
|
245
278
|
case ValueType::MutableValueType: {
|
|
246
|
-
auto&
|
|
279
|
+
auto &mutableObject = ValueWrapper::asMutableValue(valueContainer);
|
|
247
280
|
return createHost(rt, mutableObject);
|
|
248
281
|
}
|
|
249
282
|
case ValueType::HostFunctionType: {
|
|
250
|
-
auto hostFunctionWrapper =
|
|
251
|
-
|
|
283
|
+
auto hostFunctionWrapper =
|
|
284
|
+
ValueWrapper::asHostFunctionWrapper(valueContainer);
|
|
285
|
+
auto &hostRuntime = hostFunctionWrapper->value->hostRuntime;
|
|
252
286
|
if (hostRuntime == &rt) {
|
|
253
|
-
// function is accessed from the same runtime it was crated, we just
|
|
254
|
-
return
|
|
287
|
+
// function is accessed from the same runtime it was crated, we just
|
|
288
|
+
// return same function obj
|
|
289
|
+
return jsi::Value(
|
|
290
|
+
rt, *hostFunctionWrapper->value->getPureFunction().get());
|
|
255
291
|
} else {
|
|
256
|
-
// function is accessed from a different runtime, we wrap function in
|
|
257
|
-
// call on an appropriate thread
|
|
292
|
+
// function is accessed from a different runtime, we wrap function in
|
|
293
|
+
// host func that'd enqueue call on an appropriate thread
|
|
258
294
|
|
|
259
295
|
auto runtimeManager = this->runtimeManager;
|
|
260
296
|
auto hostFunction = hostFunctionWrapper->value;
|
|
261
297
|
|
|
262
298
|
auto warnFunction = [runtimeManager, hostFunction](
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
) -> jsi::Value {
|
|
268
|
-
|
|
299
|
+
jsi::Runtime &rt,
|
|
300
|
+
const jsi::Value &thisValue,
|
|
301
|
+
const jsi::Value *args,
|
|
302
|
+
size_t count) -> jsi::Value {
|
|
269
303
|
jsi::Value jsThis = rt.global().getProperty(rt, "jsThis");
|
|
270
|
-
std::string workletLocation = jsThis.asObject(rt)
|
|
304
|
+
std::string workletLocation = jsThis.asObject(rt)
|
|
305
|
+
.getProperty(rt, "__location")
|
|
306
|
+
.toString(rt)
|
|
307
|
+
.utf8(rt);
|
|
271
308
|
std::string exceptionMessage = "Tried to synchronously call ";
|
|
272
|
-
if(hostFunction->functionName.empty()) {
|
|
309
|
+
if (hostFunction->functionName.empty()) {
|
|
273
310
|
exceptionMessage += "anonymous function";
|
|
274
311
|
} else {
|
|
275
312
|
exceptionMessage += "function {" + hostFunction->functionName + "}";
|
|
276
313
|
}
|
|
277
|
-
exceptionMessage +=
|
|
314
|
+
exceptionMessage +=
|
|
315
|
+
" from a different thread.\n\nOccurred in worklet location: ";
|
|
278
316
|
exceptionMessage += workletLocation;
|
|
279
317
|
exceptionMessage += CALLBACK_ERROR_SUFFIX;
|
|
280
318
|
runtimeManager->errorHandler->setError(exceptionMessage);
|
|
@@ -284,129 +322,151 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
|
|
|
284
322
|
};
|
|
285
323
|
|
|
286
324
|
auto clb = [runtimeManager, hostFunction, hostRuntime](
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
//
|
|
293
|
-
// from RN and not only RN methods from UI
|
|
325
|
+
jsi::Runtime &rt,
|
|
326
|
+
const jsi::Value &thisValue,
|
|
327
|
+
const jsi::Value *args,
|
|
328
|
+
size_t count) -> jsi::Value {
|
|
329
|
+
// TODO: we should find thread based on runtime such that we could
|
|
330
|
+
// also call UI methods from RN and not only RN methods from UI
|
|
294
331
|
|
|
295
332
|
std::vector<std::shared_ptr<ShareableValue>> params;
|
|
296
333
|
for (int i = 0; i < count; ++i) {
|
|
297
|
-
params.push_back(
|
|
334
|
+
params.push_back(
|
|
335
|
+
ShareableValue::adapt(rt, args[i], runtimeManager));
|
|
298
336
|
}
|
|
299
337
|
|
|
300
338
|
std::function<void()> job = [hostFunction, hostRuntime, params] {
|
|
301
|
-
jsi::Value *
|
|
339
|
+
jsi::Value *args = new jsi::Value[params.size()];
|
|
302
340
|
for (int i = 0; i < params.size(); ++i) {
|
|
303
341
|
args[i] = params[i]->getValue(*hostRuntime);
|
|
304
342
|
}
|
|
305
|
-
jsi::Value returnedValue =
|
|
306
|
-
|
|
307
|
-
|
|
343
|
+
jsi::Value returnedValue =
|
|
344
|
+
hostFunction->getPureFunction().get()->call(
|
|
345
|
+
*hostRuntime,
|
|
346
|
+
static_cast<const jsi::Value *>(args),
|
|
347
|
+
(size_t)params.size());
|
|
308
348
|
|
|
309
|
-
delete
|
|
349
|
+
delete[] args;
|
|
310
350
|
// ToDo use returned value to return promise
|
|
311
351
|
};
|
|
312
352
|
|
|
313
353
|
runtimeManager->scheduler->scheduleOnJS(job);
|
|
314
354
|
return jsi::Value::undefined();
|
|
315
355
|
};
|
|
316
|
-
jsi::Function wrapperFunction = jsi::Function::createFromHostFunction(
|
|
317
|
-
|
|
356
|
+
jsi::Function wrapperFunction = jsi::Function::createFromHostFunction(
|
|
357
|
+
rt, jsi::PropNameID::forAscii(rt, "hostFunction"), 0, warnFunction);
|
|
358
|
+
jsi::Function res = jsi::Function::createFromHostFunction(
|
|
359
|
+
rt, jsi::PropNameID::forAscii(rt, "hostFunction"), 0, clb);
|
|
318
360
|
addHiddenProperty(rt, std::move(res), wrapperFunction, CALL_ASYNC);
|
|
319
|
-
jsi::Object functionHandler =
|
|
320
|
-
|
|
361
|
+
jsi::Object functionHandler =
|
|
362
|
+
createHost(rt, hostFunctionWrapper->value);
|
|
363
|
+
addHiddenProperty(
|
|
364
|
+
rt, std::move(functionHandler), wrapperFunction, PRIMAL_FUNCTION);
|
|
321
365
|
return wrapperFunction;
|
|
322
366
|
}
|
|
323
367
|
}
|
|
324
368
|
case ValueType::WorkletFunctionType: {
|
|
325
369
|
auto runtimeManager = this->runtimeManager;
|
|
326
|
-
auto&
|
|
370
|
+
auto &frozenObject = ValueWrapper::asFrozenObject(this->valueContainer);
|
|
327
371
|
if (RuntimeDecorator::isWorkletRuntime(rt)) {
|
|
328
372
|
// when running on worklet thread we prep a function
|
|
329
373
|
|
|
330
|
-
auto jsThis = std::make_shared<jsi::Object>(
|
|
331
|
-
|
|
374
|
+
auto jsThis = std::make_shared<jsi::Object>(
|
|
375
|
+
frozenObject->shallowClone(*runtimeManager->runtime));
|
|
376
|
+
std::shared_ptr<jsi::Function> funPtr(
|
|
377
|
+
runtimeManager->workletsCache->getFunction(rt, frozenObject));
|
|
332
378
|
auto name = funPtr->getProperty(rt, "name").asString(rt).utf8(rt);
|
|
333
379
|
|
|
334
|
-
auto clb = [=](
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
} catch(jsi::JSError &e) {
|
|
353
|
-
throw e;
|
|
354
|
-
} catch(...) {
|
|
355
|
-
// TODO find out a way to get the error's message on hermes
|
|
356
|
-
jsi::Value location = jsThis->getProperty(rt, "__location");
|
|
357
|
-
std::string str = "Javascript worklet error";
|
|
358
|
-
if (location.isString()) {
|
|
359
|
-
str += "\nIn file: " + location.asString(rt).utf8(rt);
|
|
360
|
-
}
|
|
361
|
-
runtimeManager->errorHandler->setError(str);
|
|
362
|
-
runtimeManager->errorHandler->raise();
|
|
380
|
+
auto clb = [=](jsi::Runtime &rt,
|
|
381
|
+
const jsi::Value &thisValue,
|
|
382
|
+
const jsi::Value *args,
|
|
383
|
+
size_t count) mutable -> jsi::Value {
|
|
384
|
+
const jsi::String jsThisName =
|
|
385
|
+
jsi::String::createFromAscii(rt, "jsThis");
|
|
386
|
+
jsi::Object global = rt.global();
|
|
387
|
+
jsi::Value oldJSThis = global.getProperty(rt, jsThisName);
|
|
388
|
+
global.setProperty(rt, jsThisName, *jsThis); // set jsThis
|
|
389
|
+
|
|
390
|
+
jsi::Value res = jsi::Value::undefined();
|
|
391
|
+
try {
|
|
392
|
+
if (thisValue.isObject()) {
|
|
393
|
+
res =
|
|
394
|
+
funPtr->callWithThis(rt, thisValue.asObject(rt), args, count);
|
|
395
|
+
} else {
|
|
396
|
+
res = funPtr->call(rt, args, count);
|
|
363
397
|
}
|
|
364
|
-
|
|
365
|
-
|
|
398
|
+
} catch (jsi::JSError &e) {
|
|
399
|
+
throw e;
|
|
400
|
+
} catch (...) {
|
|
401
|
+
if (demangleExceptionName(
|
|
402
|
+
abi::__cxa_current_exception_type()->name()) ==
|
|
403
|
+
"facebook::jsi::JSError") {
|
|
404
|
+
throw jsi::JSError(rt, "Javascript worklet error");
|
|
405
|
+
}
|
|
406
|
+
// TODO find out a way to get the error's message on hermes
|
|
407
|
+
jsi::Value location = jsThis->getProperty(rt, "__location");
|
|
408
|
+
std::string str = "Javascript worklet error";
|
|
409
|
+
if (location.isString()) {
|
|
410
|
+
str += "\nIn file: " + location.asString(rt).utf8(rt);
|
|
411
|
+
}
|
|
412
|
+
runtimeManager->errorHandler->setError(str);
|
|
413
|
+
runtimeManager->errorHandler->raise();
|
|
414
|
+
}
|
|
415
|
+
global.setProperty(rt, jsThisName, oldJSThis); // clean jsThis
|
|
416
|
+
return res;
|
|
366
417
|
};
|
|
367
|
-
return jsi::Function::createFromHostFunction(
|
|
418
|
+
return jsi::Function::createFromHostFunction(
|
|
419
|
+
rt, jsi::PropNameID::forAscii(rt, name.c_str()), 0, clb);
|
|
368
420
|
} else {
|
|
369
421
|
// when run outside of UI thread we enqueue a call on the UI thread
|
|
370
|
-
auto clb = [=](
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
// TODO: we should find thread based on runtime such that we could also call UI methods
|
|
377
|
-
// from RN and not only RN methods from UI
|
|
422
|
+
auto clb = [=](jsi::Runtime &rt,
|
|
423
|
+
const jsi::Value &thisValue,
|
|
424
|
+
const jsi::Value *args,
|
|
425
|
+
size_t count) -> jsi::Value {
|
|
426
|
+
// TODO: we should find thread based on runtime such that we could
|
|
427
|
+
// also call UI methods from RN and not only RN methods from UI
|
|
378
428
|
|
|
379
429
|
std::vector<std::shared_ptr<ShareableValue>> params;
|
|
380
430
|
for (int i = 0; i < count; ++i) {
|
|
381
|
-
params.push_back(
|
|
431
|
+
params.push_back(
|
|
432
|
+
ShareableValue::adapt(rt, args[i], runtimeManager));
|
|
382
433
|
}
|
|
383
434
|
|
|
384
435
|
runtimeManager->scheduler->scheduleOnUI([=] {
|
|
385
436
|
jsi::Runtime &rt = *runtimeManager->runtime.get();
|
|
386
437
|
auto jsThis = createFrozenWrapper(rt, frozenObject).getObject(rt);
|
|
387
|
-
auto code =
|
|
388
|
-
|
|
438
|
+
auto code =
|
|
439
|
+
jsThis.getProperty(rt, "asString").asString(rt).utf8(rt);
|
|
440
|
+
std::shared_ptr<jsi::Function> funPtr(
|
|
441
|
+
runtimeManager->workletsCache->getFunction(rt, frozenObject));
|
|
389
442
|
|
|
390
|
-
jsi::Value *
|
|
443
|
+
jsi::Value *args = new jsi::Value[params.size()];
|
|
391
444
|
for (int i = 0; i < params.size(); ++i) {
|
|
392
445
|
args[i] = params[i]->getValue(rt);
|
|
393
446
|
}
|
|
394
447
|
|
|
395
448
|
jsi::Value returnedValue;
|
|
396
|
-
const jsi::String jsThisName =
|
|
449
|
+
const jsi::String jsThisName =
|
|
450
|
+
jsi::String::createFromAscii(rt, "jsThis");
|
|
397
451
|
jsi::Object global = rt.global();
|
|
398
452
|
jsi::Value oldJSThis = global.getProperty(rt, jsThisName);
|
|
399
|
-
global.setProperty(rt, jsThisName, jsThis); //set jsThis
|
|
453
|
+
global.setProperty(rt, jsThisName, jsThis); // set jsThis
|
|
400
454
|
try {
|
|
401
|
-
returnedValue = funPtr->call(
|
|
402
|
-
|
|
403
|
-
|
|
455
|
+
returnedValue = funPtr->call(
|
|
456
|
+
rt,
|
|
457
|
+
static_cast<const jsi::Value *>(args),
|
|
458
|
+
(size_t)params.size());
|
|
404
459
|
|
|
405
|
-
} catch(std::exception &e) {
|
|
460
|
+
} catch (std::exception &e) {
|
|
406
461
|
std::string str = e.what();
|
|
407
462
|
runtimeManager->errorHandler->setError(str);
|
|
408
463
|
runtimeManager->errorHandler->raise();
|
|
409
|
-
} catch(...) {
|
|
464
|
+
} catch (...) {
|
|
465
|
+
if (demangleExceptionName(
|
|
466
|
+
abi::__cxa_current_exception_type()->name()) ==
|
|
467
|
+
"facebook::jsi::JSError") {
|
|
468
|
+
throw jsi::JSError(rt, "Javascript worklet error");
|
|
469
|
+
}
|
|
410
470
|
// TODO find out a way to get the error's message on hermes
|
|
411
471
|
jsi::Value location = jsThis.getProperty(rt, "__location");
|
|
412
472
|
std::string str = "Javascript worklet error";
|
|
@@ -416,14 +476,15 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
|
|
|
416
476
|
runtimeManager->errorHandler->setError(str);
|
|
417
477
|
runtimeManager->errorHandler->raise();
|
|
418
478
|
}
|
|
419
|
-
global.setProperty(rt, jsThisName, oldJSThis); //clean jsThis
|
|
479
|
+
global.setProperty(rt, jsThisName, oldJSThis); // clean jsThis
|
|
420
480
|
|
|
421
|
-
delete
|
|
481
|
+
delete[] args;
|
|
422
482
|
// ToDo use returned value to return promise
|
|
423
483
|
});
|
|
424
484
|
return jsi::Value::undefined();
|
|
425
485
|
};
|
|
426
|
-
return jsi::Function::createFromHostFunction(
|
|
486
|
+
return jsi::Function::createFromHostFunction(
|
|
487
|
+
rt, jsi::PropNameID::forAscii(rt, "_workletFunction"), 0, clb);
|
|
427
488
|
}
|
|
428
489
|
}
|
|
429
490
|
default: {
|
|
@@ -433,4 +494,16 @@ jsi::Value ShareableValue::toJSValue(jsi::Runtime &rt) {
|
|
|
433
494
|
throw "convert error";
|
|
434
495
|
}
|
|
435
496
|
|
|
497
|
+
std::string ShareableValue::demangleExceptionName(std::string toDemangle) {
|
|
498
|
+
int status = 0;
|
|
499
|
+
char *buff =
|
|
500
|
+
__cxxabiv1::__cxa_demangle(toDemangle.c_str(), nullptr, nullptr, &status);
|
|
501
|
+
if (!buff) {
|
|
502
|
+
return toDemangle;
|
|
503
|
+
}
|
|
504
|
+
std::string demangled = buff;
|
|
505
|
+
std::free(buff);
|
|
506
|
+
return demangled;
|
|
436
507
|
}
|
|
508
|
+
|
|
509
|
+
} // namespace reanimated
|