react-native-reanimated 2.16.0 → 2.17.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/android/.gradle/7.5.1/checksums/checksums.lock +0 -0
- package/android/.gradle/7.5.1/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/7.5.1/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/7.5.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.5.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.5.1/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/7.5.1/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.5.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.5.1/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.5.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.5.1/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/7.5.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/buildOutputCleanup/outputFiles.bin +0 -0
- package/android/.gradle/file-system.probe +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/react-native-reanimated-67-hermes.aar +0 -0
- package/android/react-native-reanimated-67-jsc.aar +0 -0
- package/android/react-native-reanimated-68-hermes.aar +0 -0
- package/android/react-native-reanimated-68-jsc.aar +0 -0
- package/android/react-native-reanimated-69-hermes.aar +0 -0
- package/android/react-native-reanimated-69-jsc.aar +0 -0
- package/android/react-native-reanimated-70-hermes.aar +0 -0
- package/android/react-native-reanimated-70-jsc.aar +0 -0
- package/android/react-native-reanimated-71-hermes.aar +0 -0
- package/android/react-native-reanimated-71-jsc.aar +0 -0
- package/lib/Animated.js +9 -0
- package/lib/ConfigHelper.js +145 -0
- package/lib/ReanimatedEventEmitter.js +3 -0
- package/lib/ReanimatedModule.js +2 -0
- package/lib/ReanimatedModule.macos.js +2 -0
- package/lib/ReanimatedModule.native.js +12 -0
- package/lib/ReanimatedModule.windows.js +2 -0
- package/lib/ReanimatedModuleCompat.js +66 -0
- package/lib/__mocks__/ReanimatedEventEmitter.js +8 -0
- package/lib/__mocks__/ReanimatedModule.native.js +11 -0
- package/lib/createAnimatedComponent.js +518 -0
- package/lib/index.js +14 -0
- package/lib/index.web.js +6 -0
- package/lib/reanimated1/Easing.js +231 -0
- package/lib/reanimated1/SpringConfig.js +79 -0
- package/lib/reanimated1/Transitioning.js +158 -0
- package/lib/reanimated1/animations/Animation.js +32 -0
- package/lib/reanimated1/animations/SpringUtils.js +199 -0
- package/lib/reanimated1/animations/backwardCompatibleAnimWrapper.js +117 -0
- package/lib/reanimated1/animations/decay.js +54 -0
- package/lib/reanimated1/animations/spring.js +198 -0
- package/lib/reanimated1/animations/timing.js +74 -0
- package/lib/reanimated1/base.js +13 -0
- package/lib/reanimated1/core/AnimatedAlways.js +33 -0
- package/lib/reanimated1/core/AnimatedBezier.js +150 -0
- package/lib/reanimated1/core/AnimatedBlock.js +52 -0
- package/lib/reanimated1/core/AnimatedCall.js +55 -0
- package/lib/reanimated1/core/AnimatedCallFunc.js +72 -0
- package/lib/reanimated1/core/AnimatedClock.js +90 -0
- package/lib/reanimated1/core/AnimatedClockTest.js +22 -0
- package/lib/reanimated1/core/AnimatedCode.js +32 -0
- package/lib/reanimated1/core/AnimatedConcat.js +32 -0
- package/lib/reanimated1/core/AnimatedCond.js +57 -0
- package/lib/reanimated1/core/AnimatedDebug.js +62 -0
- package/lib/reanimated1/core/AnimatedEvent.js +126 -0
- package/lib/reanimated1/core/AnimatedFunction.js +55 -0
- package/lib/reanimated1/core/AnimatedNode.js +223 -0
- package/lib/reanimated1/core/AnimatedOperator.js +103 -0
- package/lib/reanimated1/core/AnimatedParam.js +88 -0
- package/lib/reanimated1/core/AnimatedProps.js +108 -0
- package/lib/reanimated1/core/AnimatedSet.js +38 -0
- package/lib/reanimated1/core/AnimatedStartClock.js +30 -0
- package/lib/reanimated1/core/AnimatedStopClock.js +30 -0
- package/lib/reanimated1/core/AnimatedStyle.js +78 -0
- package/lib/reanimated1/core/AnimatedTransform.js +78 -0
- package/lib/reanimated1/core/AnimatedValue.js +38 -0
- package/lib/reanimated1/core/InternalAnimatedValue.js +87 -0
- package/lib/reanimated1/core/__mocks__/AnimatedProps.js +86 -0
- package/lib/reanimated1/core/createEventObjectProxyPolyfill.js +44 -0
- package/lib/reanimated1/derived/__mocks__/evaluateOnce.js +14 -0
- package/lib/reanimated1/derived/acc.js +11 -0
- package/lib/reanimated1/derived/color.js +47 -0
- package/lib/reanimated1/derived/diff.js +16 -0
- package/lib/reanimated1/derived/diffClamp.js +11 -0
- package/lib/reanimated1/derived/evaluateOnce.js +35 -0
- package/lib/reanimated1/derived/index.js +8 -0
- package/lib/reanimated1/derived/interpolate.js +152 -0
- package/lib/reanimated1/derived/interpolateColors.js +62 -0
- package/lib/reanimated1/derived/onChange.js +14 -0
- package/lib/reanimated1/derived/useCode.js +41 -0
- package/lib/reanimated1/index.js +53 -0
- package/lib/reanimated1/operators.js +35 -0
- package/lib/reanimated1/useValue.js +10 -0
- package/lib/reanimated1/val.js +3 -0
- package/lib/reanimated2/Bezier.js +126 -0
- package/lib/reanimated2/Colors.js +538 -0
- package/lib/reanimated2/Easing.js +248 -0
- package/lib/reanimated2/NativeMethods.js +94 -0
- package/lib/reanimated2/NativeReanimated/NativeReanimated.js +60 -0
- package/lib/reanimated2/NativeReanimated/index.js +11 -0
- package/lib/reanimated2/PlatformChecker.js +16 -0
- package/lib/reanimated2/PropAdapters.js +55 -0
- package/lib/reanimated2/UpdateProps.js +55 -0
- package/lib/reanimated2/ViewDescriptorsSet.js +75 -0
- package/lib/reanimated2/WorkletEventHandler.js +37 -0
- package/lib/reanimated2/__mocks__/MutableValue.js +13 -0
- package/lib/reanimated2/__mocks__/NativeReanimated.js +20 -0
- 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 +69 -0
- package/lib/reanimated2/animation/spring.js +103 -0
- package/lib/reanimated2/animation/styleAnimation.js +174 -0
- package/lib/reanimated2/animation/timing.js +64 -0
- package/lib/reanimated2/animation/util.js +183 -0
- package/lib/reanimated2/commonTypes.js +8 -0
- package/lib/reanimated2/component/FlatList.js +30 -0
- package/lib/reanimated2/component/Image.js +4 -0
- package/lib/reanimated2/component/ScrollView.js +4 -0
- package/lib/reanimated2/component/Text.js +4 -0
- package/lib/reanimated2/component/View.js +4 -0
- package/lib/reanimated2/core.js +269 -0
- package/lib/reanimated2/frameCallback/FrameCallbackRegistryJS.js +32 -0
- package/lib/reanimated2/frameCallback/FrameCallbackRegistryUI.js +76 -0
- package/lib/reanimated2/globals.d.ts +91 -0
- package/lib/reanimated2/hook/Hooks.js +9 -0
- package/lib/reanimated2/hook/commonTypes.js +1 -0
- package/lib/reanimated2/hook/index.js +12 -0
- package/lib/reanimated2/hook/useAnimatedGestureHandler.js +49 -0
- package/lib/reanimated2/hook/useAnimatedKeyboard.js +31 -0
- package/lib/reanimated2/hook/useAnimatedReaction.js +44 -0
- package/lib/reanimated2/hook/useAnimatedRef.js +25 -0
- package/lib/reanimated2/hook/useAnimatedScrollHandler.js +41 -0
- package/lib/reanimated2/hook/useAnimatedSensor.js +66 -0
- package/lib/reanimated2/hook/useAnimatedStyle.js +402 -0
- package/lib/reanimated2/hook/useDerivedValue.js +43 -0
- package/lib/reanimated2/hook/useFrameCallback.js +23 -0
- package/lib/reanimated2/hook/useScrollViewOffset.js +27 -0
- package/lib/reanimated2/hook/useSharedValue.js +17 -0
- package/lib/reanimated2/hook/utils.js +165 -0
- package/lib/reanimated2/index.js +12 -0
- package/lib/reanimated2/interpolateColor.js +157 -0
- package/lib/reanimated2/interpolation.js +127 -0
- package/lib/reanimated2/jestUtils.js +175 -0
- package/lib/reanimated2/js-reanimated/JSReanimated.js +106 -0
- package/lib/reanimated2/js-reanimated/Mapper.js +43 -0
- package/lib/reanimated2/js-reanimated/MapperRegistry.js +101 -0
- package/lib/reanimated2/js-reanimated/MutableValue.js +29 -0
- package/lib/reanimated2/js-reanimated/commonTypes.js +1 -0
- package/lib/reanimated2/js-reanimated/global.js +36 -0
- package/lib/reanimated2/js-reanimated/index.js +35 -0
- package/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.js +67 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +69 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +133 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +194 -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 +374 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +36 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +275 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +385 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +136 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +81 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +120 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +273 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +201 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +101 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +457 -0
- package/lib/reanimated2/layoutReanimation/defaultAnimations/index.js +10 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +90 -0
- package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +132 -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 +4 -0
- package/lib/reanimated2/mock.js +75 -0
- package/lib/reanimated2/platform-specific/RNRenderer.js +3 -0
- package/lib/reanimated2/platform-specific/RNRenderer.web.js +3 -0
- package/lib/reanimated2/platform-specific/checkVersion.js +28 -0
- package/lib/reanimated2/platform-specific/checkVersion.web.js +6 -0
- package/lib/reanimated2/utils.js +16 -0
- package/lib/setAndForwardRef.js +19 -0
- package/lib/types/lib/Animated.d.ts +8 -0
- package/lib/types/lib/ConfigHelper.d.ts +12 -0
- package/lib/types/lib/ReanimatedEventEmitter.d.ts +3 -0
- package/lib/types/lib/ReanimatedModule.d.ts +2 -0
- package/lib/types/lib/ReanimatedModule.macos.d.ts +2 -0
- package/lib/types/lib/ReanimatedModule.native.d.ts +2 -0
- package/lib/types/lib/ReanimatedModule.windows.d.ts +2 -0
- package/lib/types/lib/ReanimatedModuleCompat.d.ts +14 -0
- package/lib/types/lib/createAnimatedComponent.d.ts +33 -0
- package/lib/types/lib/index.d.ts +4 -0
- package/lib/types/lib/index.web.d.ts +4 -0
- package/lib/types/lib/reanimated2/Bezier.d.ts +6 -0
- package/lib/types/lib/reanimated2/Colors.d.ts +33 -0
- package/lib/types/lib/reanimated2/Easing.d.ts +172 -0
- package/lib/types/lib/reanimated2/NativeMethods.d.ts +7 -0
- package/lib/types/lib/reanimated2/NativeReanimated/NativeReanimated.d.ts +22 -0
- package/lib/types/lib/reanimated2/NativeReanimated/index.d.ts +3 -0
- package/lib/types/lib/reanimated2/PlatformChecker.d.ts +5 -0
- package/lib/types/lib/reanimated2/PropAdapters.d.ts +4 -0
- package/lib/types/lib/reanimated2/UpdateProps.d.ts +9 -0
- package/lib/types/lib/reanimated2/ViewDescriptorsSet.d.ts +20 -0
- package/lib/types/lib/reanimated2/WorkletEventHandler.d.ts +13 -0
- package/lib/types/lib/reanimated2/__mocks__/MutableValue.d.ts +5 -0
- package/lib/types/lib/reanimated2/__mocks__/NativeReanimated.d.ts +13 -0
- package/lib/types/lib/reanimated2/animation/commonTypes.d.ts +27 -0
- package/lib/types/lib/reanimated2/animation/decay.d.ts +19 -0
- package/lib/types/lib/reanimated2/animation/delay.d.ts +7 -0
- package/lib/types/lib/reanimated2/animation/index.d.ts +9 -0
- package/lib/types/lib/reanimated2/animation/repeat.d.ts +12 -0
- package/lib/types/lib/reanimated2/animation/sequence.d.ts +7 -0
- package/lib/types/lib/reanimated2/animation/spring.d.ts +22 -0
- package/lib/types/lib/reanimated2/animation/styleAnimation.d.ts +7 -0
- package/lib/types/lib/reanimated2/animation/timing.d.ts +21 -0
- package/lib/types/lib/reanimated2/animation/util.d.ts +9 -0
- package/lib/types/lib/reanimated2/commonTypes.d.ts +99 -0
- package/lib/types/lib/reanimated2/component/FlatList.d.ts +9 -0
- package/lib/types/lib/reanimated2/component/Image.d.ts +3 -0
- package/lib/types/lib/reanimated2/component/ScrollView.d.ts +3 -0
- package/lib/types/lib/reanimated2/component/Text.d.ts +3 -0
- package/lib/types/lib/reanimated2/component/View.d.ts +3 -0
- package/lib/types/lib/reanimated2/core.d.ts +24 -0
- package/lib/types/lib/reanimated2/frameCallback/FrameCallbackRegistryJS.d.ts +8 -0
- package/lib/types/lib/reanimated2/frameCallback/FrameCallbackRegistryUI.d.ts +20 -0
- package/lib/types/lib/reanimated2/hook/Hooks.d.ts +5 -0
- package/lib/types/lib/reanimated2/hook/commonTypes.d.ts +14 -0
- package/lib/types/lib/reanimated2/hook/index.d.ts +14 -0
- package/lib/types/lib/reanimated2/hook/useAnimatedGestureHandler.d.ts +35 -0
- package/lib/types/lib/reanimated2/hook/useAnimatedKeyboard.d.ts +2 -0
- package/lib/types/lib/reanimated2/hook/useAnimatedReaction.d.ts +12 -0
- package/lib/types/lib/reanimated2/hook/useAnimatedRef.d.ts +3 -0
- package/lib/types/lib/reanimated2/hook/useAnimatedScrollHandler.d.ts +20 -0
- package/lib/types/lib/reanimated2/hook/useAnimatedSensor.d.ts +18 -0
- package/lib/types/lib/reanimated2/hook/useAnimatedStyle.d.ts +11 -0
- package/lib/types/lib/reanimated2/hook/useDerivedValue.d.ts +4 -0
- package/lib/types/lib/reanimated2/hook/useFrameCallback.d.ts +7 -0
- package/lib/types/lib/reanimated2/hook/useScrollViewOffset.d.ts +4 -0
- package/lib/types/lib/reanimated2/hook/useSharedValue.d.ts +2 -0
- package/lib/types/lib/reanimated2/hook/utils.d.ts +28 -0
- package/lib/types/lib/reanimated2/index.d.ts +12 -0
- package/lib/types/lib/reanimated2/interpolateColor.d.ts +32 -0
- package/lib/types/lib/reanimated2/interpolation.d.ts +14 -0
- package/lib/types/lib/reanimated2/jestUtils.d.ts +12 -0
- package/lib/types/lib/reanimated2/js-reanimated/JSReanimated.d.ts +32 -0
- package/lib/types/lib/reanimated2/js-reanimated/Mapper.d.ts +14 -0
- package/lib/types/lib/reanimated2/js-reanimated/MapperRegistry.d.ts +14 -0
- package/lib/types/lib/reanimated2/js-reanimated/MutableValue.d.ts +14 -0
- package/lib/types/lib/reanimated2/js-reanimated/commonTypes.d.ts +44 -0
- package/lib/types/lib/reanimated2/js-reanimated/global.d.ts +2 -0
- package/lib/types/lib/reanimated2/js-reanimated/index.d.ts +15 -0
- package/lib/types/lib/reanimated2/layoutReanimation/LayoutAnimationRepository.d.ts +1 -0
- package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/BaseAnimationBuilder.d.ts +22 -0
- package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.d.ts +38 -0
- package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.d.ts +25 -0
- package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/commonTypes.d.ts +81 -0
- package/lib/types/lib/reanimated2/layoutReanimation/animationBuilder/index.d.ts +4 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.d.ts +62 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Default.d.ts +4 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.d.ts +42 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.d.ts +50 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.d.ts +18 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.d.ts +10 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.d.ts +18 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.d.ts +34 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.d.ts +34 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.d.ts +18 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.d.ts +66 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultAnimations/index.d.ts +10 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.d.ts +19 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.d.ts +13 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.d.ts +6 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.d.ts +6 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.d.ts +7 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.d.ts +9 -0
- package/lib/types/lib/reanimated2/layoutReanimation/defaultTransitions/index.d.ts +6 -0
- package/lib/types/lib/reanimated2/layoutReanimation/index.d.ts +4 -0
- package/lib/types/lib/reanimated2/mock.d.ts +61 -0
- package/lib/types/lib/reanimated2/platform-specific/RNRenderer.d.ts +1 -0
- package/lib/types/lib/reanimated2/platform-specific/RNRenderer.web.d.ts +0 -0
- package/lib/types/lib/reanimated2/platform-specific/checkVersion.d.ts +4 -0
- package/lib/types/lib/reanimated2/platform-specific/checkVersion.web.d.ts +5 -0
- package/lib/types/lib/reanimated2/utils.d.ts +11 -0
- package/lib/types/lib/setAndForwardRef.d.ts +40 -0
- package/package.json +1 -1
- package/src/reanimated1/core/Core.test.js +0 -30
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
/* global _frameTimestamp */
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { startMapper, stopMapper, makeRemote, requestFrame, getTimestamp, makeMutable, } from '../core';
|
|
4
|
+
import updateProps, { updatePropsJestWrapper } from '../UpdateProps';
|
|
5
|
+
import { initialUpdaterRun } from '../animation';
|
|
6
|
+
import NativeReanimatedModule from '../NativeReanimated';
|
|
7
|
+
import { useSharedValue } from './useSharedValue';
|
|
8
|
+
import { buildWorkletsHash, canApplyOptimalisation, getStyleWithoutAnimations, hasColorProps, isAnimated, parseColors, styleDiff, validateAnimatedStyles, } from './utils';
|
|
9
|
+
import { makeViewDescriptorsSet, makeViewsRefSet, } from '../ViewDescriptorsSet';
|
|
10
|
+
import { isJest, shouldBeUseWeb } from '../PlatformChecker';
|
|
11
|
+
function prepareAnimation(animatedProp, lastAnimation, lastValue) {
|
|
12
|
+
'worklet';
|
|
13
|
+
if (Array.isArray(animatedProp)) {
|
|
14
|
+
animatedProp.forEach((prop, index) => prepareAnimation(prop, lastAnimation && lastAnimation[index], lastValue && lastValue[index]));
|
|
15
|
+
// return animatedProp;
|
|
16
|
+
}
|
|
17
|
+
if (typeof animatedProp === 'object' && animatedProp.onFrame) {
|
|
18
|
+
const animation = animatedProp;
|
|
19
|
+
let value = animation.current;
|
|
20
|
+
if (lastValue !== undefined) {
|
|
21
|
+
if (typeof lastValue === 'object') {
|
|
22
|
+
if (lastValue.value !== undefined) {
|
|
23
|
+
// previously it was a shared value
|
|
24
|
+
value = lastValue.value;
|
|
25
|
+
}
|
|
26
|
+
else if (lastValue.onFrame !== undefined) {
|
|
27
|
+
if ((lastAnimation === null || lastAnimation === void 0 ? void 0 : lastAnimation.current) !== undefined) {
|
|
28
|
+
// it was an animation before, copy its state
|
|
29
|
+
value = lastAnimation.current;
|
|
30
|
+
}
|
|
31
|
+
else if ((lastValue === null || lastValue === void 0 ? void 0 : lastValue.current) !== undefined) {
|
|
32
|
+
// it was initialized
|
|
33
|
+
value = lastValue.current;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// previously it was a plain value, just set it as starting point
|
|
39
|
+
value = lastValue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
animation.callStart = (timestamp) => {
|
|
43
|
+
animation.onStart(animation, value, timestamp, lastAnimation);
|
|
44
|
+
};
|
|
45
|
+
animation.callStart(getTimestamp());
|
|
46
|
+
animation.callStart = null;
|
|
47
|
+
}
|
|
48
|
+
else if (typeof animatedProp === 'object') {
|
|
49
|
+
// it is an object
|
|
50
|
+
Object.keys(animatedProp).forEach((key) => prepareAnimation(animatedProp[key], lastAnimation && lastAnimation[key], lastValue && lastValue[key]));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function runAnimations(animation, timestamp, key, result, animationsActive) {
|
|
54
|
+
'worklet';
|
|
55
|
+
if (!animationsActive.value) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
if (Array.isArray(animation)) {
|
|
59
|
+
result[key] = [];
|
|
60
|
+
let allFinished = true;
|
|
61
|
+
animation.forEach((entry, index) => {
|
|
62
|
+
if (!runAnimations(entry, timestamp, index, result[key], animationsActive)) {
|
|
63
|
+
allFinished = false;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return allFinished;
|
|
67
|
+
}
|
|
68
|
+
else if (typeof animation === 'object' && animation.onFrame) {
|
|
69
|
+
let finished = true;
|
|
70
|
+
if (!animation.finished) {
|
|
71
|
+
if (animation.callStart) {
|
|
72
|
+
animation.callStart(timestamp);
|
|
73
|
+
animation.callStart = null;
|
|
74
|
+
}
|
|
75
|
+
finished = animation.onFrame(animation, timestamp);
|
|
76
|
+
animation.timestamp = timestamp;
|
|
77
|
+
if (finished) {
|
|
78
|
+
animation.finished = true;
|
|
79
|
+
animation.callback && animation.callback(true /* finished */);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
result[key] = animation.current;
|
|
83
|
+
return finished;
|
|
84
|
+
}
|
|
85
|
+
else if (typeof animation === 'object') {
|
|
86
|
+
result[key] = {};
|
|
87
|
+
let allFinished = true;
|
|
88
|
+
Object.keys(animation).forEach((k) => {
|
|
89
|
+
if (!runAnimations(animation[k], timestamp, k, result[key], animationsActive)) {
|
|
90
|
+
allFinished = false;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
return allFinished;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
result[key] = animation;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function styleUpdater(viewDescriptors, updater, state, maybeViewRef, animationsActive) {
|
|
101
|
+
'worklet';
|
|
102
|
+
var _a, _b;
|
|
103
|
+
const animations = (_a = state.animations) !== null && _a !== void 0 ? _a : {};
|
|
104
|
+
const newValues = (_b = updater()) !== null && _b !== void 0 ? _b : {};
|
|
105
|
+
const oldValues = state.last;
|
|
106
|
+
let hasAnimations = false;
|
|
107
|
+
for (const key in newValues) {
|
|
108
|
+
const value = newValues[key];
|
|
109
|
+
if (isAnimated(value)) {
|
|
110
|
+
prepareAnimation(value, animations[key], oldValues[key]);
|
|
111
|
+
animations[key] = value;
|
|
112
|
+
hasAnimations = true;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
delete animations[key];
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (hasAnimations) {
|
|
119
|
+
const frame = (timestamp) => {
|
|
120
|
+
const { animations, last, isAnimationCancelled } = state;
|
|
121
|
+
if (isAnimationCancelled) {
|
|
122
|
+
state.isAnimationRunning = false;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const updates = {};
|
|
126
|
+
let allFinished = true;
|
|
127
|
+
for (const propName in animations) {
|
|
128
|
+
const finished = runAnimations(animations[propName], timestamp, propName, updates, animationsActive);
|
|
129
|
+
if (finished) {
|
|
130
|
+
last[propName] = updates[propName];
|
|
131
|
+
delete animations[propName];
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
allFinished = false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (updates) {
|
|
138
|
+
updateProps(viewDescriptors, updates, maybeViewRef);
|
|
139
|
+
}
|
|
140
|
+
if (!allFinished) {
|
|
141
|
+
requestFrame(frame);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
state.isAnimationRunning = false;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
state.animations = animations;
|
|
148
|
+
if (!state.isAnimationRunning) {
|
|
149
|
+
state.isAnimationCancelled = false;
|
|
150
|
+
state.isAnimationRunning = true;
|
|
151
|
+
if (_frameTimestamp) {
|
|
152
|
+
frame(_frameTimestamp);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
requestFrame(frame);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
state.last = Object.assign({}, oldValues, newValues);
|
|
159
|
+
const style = getStyleWithoutAnimations(state.last);
|
|
160
|
+
if (style) {
|
|
161
|
+
updateProps(viewDescriptors, style, maybeViewRef);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
state.isAnimationCancelled = true;
|
|
166
|
+
state.animations = [];
|
|
167
|
+
const diff = styleDiff(oldValues, newValues);
|
|
168
|
+
state.last = Object.assign({}, oldValues, newValues);
|
|
169
|
+
if (diff) {
|
|
170
|
+
updateProps(viewDescriptors, newValues, maybeViewRef);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function jestStyleUpdater(viewDescriptors, updater, state, maybeViewRef, animationsActive, animatedStyle, adapters = []) {
|
|
175
|
+
'worklet';
|
|
176
|
+
var _a, _b;
|
|
177
|
+
const animations = (_a = state.animations) !== null && _a !== void 0 ? _a : {};
|
|
178
|
+
const newValues = (_b = updater()) !== null && _b !== void 0 ? _b : {};
|
|
179
|
+
const oldValues = state.last;
|
|
180
|
+
// extract animated props
|
|
181
|
+
let hasAnimations = false;
|
|
182
|
+
Object.keys(animations).forEach((key) => {
|
|
183
|
+
const value = newValues[key];
|
|
184
|
+
if (!isAnimated(value)) {
|
|
185
|
+
delete animations[key];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
Object.keys(newValues).forEach((key) => {
|
|
189
|
+
const value = newValues[key];
|
|
190
|
+
if (isAnimated(value)) {
|
|
191
|
+
prepareAnimation(value, animations[key], oldValues[key]);
|
|
192
|
+
animations[key] = value;
|
|
193
|
+
hasAnimations = true;
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
function frame(timestamp) {
|
|
197
|
+
const { animations, last, isAnimationCancelled } = state;
|
|
198
|
+
if (isAnimationCancelled) {
|
|
199
|
+
state.isAnimationRunning = false;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const updates = {};
|
|
203
|
+
let allFinished = true;
|
|
204
|
+
Object.keys(animations).forEach((propName) => {
|
|
205
|
+
const finished = runAnimations(animations[propName], timestamp, propName, updates, animationsActive);
|
|
206
|
+
if (finished) {
|
|
207
|
+
last[propName] = updates[propName];
|
|
208
|
+
delete animations[propName];
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
allFinished = false;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
if (Object.keys(updates).length) {
|
|
215
|
+
updatePropsJestWrapper(viewDescriptors, updates, maybeViewRef, animatedStyle, adapters);
|
|
216
|
+
}
|
|
217
|
+
if (!allFinished) {
|
|
218
|
+
requestFrame(frame);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
state.isAnimationRunning = false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
if (hasAnimations) {
|
|
225
|
+
state.animations = animations;
|
|
226
|
+
if (!state.isAnimationRunning) {
|
|
227
|
+
state.isAnimationCancelled = false;
|
|
228
|
+
state.isAnimationRunning = true;
|
|
229
|
+
if (_frameTimestamp) {
|
|
230
|
+
frame(_frameTimestamp);
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
requestFrame(frame);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
state.isAnimationCancelled = true;
|
|
239
|
+
state.animations = [];
|
|
240
|
+
}
|
|
241
|
+
// calculate diff
|
|
242
|
+
const diff = styleDiff(oldValues, newValues);
|
|
243
|
+
state.last = Object.assign({}, oldValues, newValues);
|
|
244
|
+
if (Object.keys(diff).length !== 0) {
|
|
245
|
+
updatePropsJestWrapper(viewDescriptors, diff, maybeViewRef, animatedStyle, adapters);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
// check for invalid usage of shared values in returned object
|
|
249
|
+
function checkSharedValueUsage(prop, currentKey) {
|
|
250
|
+
if (Array.isArray(prop)) {
|
|
251
|
+
// if it's an array (i.ex. transform) validate all its elements
|
|
252
|
+
for (const element of prop) {
|
|
253
|
+
checkSharedValueUsage(element, currentKey);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else if (typeof prop === 'object' && prop.value === undefined) {
|
|
257
|
+
// if it's a nested object, run validation for all its props
|
|
258
|
+
for (const key of Object.keys(prop)) {
|
|
259
|
+
checkSharedValueUsage(prop[key], key);
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
else if (currentKey !== undefined &&
|
|
263
|
+
typeof prop === 'object' &&
|
|
264
|
+
prop.value !== undefined) {
|
|
265
|
+
// if shared value is passed insted of its value, throw an error
|
|
266
|
+
throw new Error(`invalid value passed to \`${currentKey}\`, maybe you forgot to use \`.value\`?`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
export function useAnimatedStyle(updater, dependencies, adapters) {
|
|
270
|
+
var _a, _b;
|
|
271
|
+
const viewsRef = makeViewsRefSet();
|
|
272
|
+
const viewDescriptors = makeViewDescriptorsSet();
|
|
273
|
+
const initRef = useRef();
|
|
274
|
+
let inputs = Object.values((_a = updater._closure) !== null && _a !== void 0 ? _a : {});
|
|
275
|
+
if (shouldBeUseWeb()) {
|
|
276
|
+
if (!inputs.length && (dependencies === null || dependencies === void 0 ? void 0 : dependencies.length)) {
|
|
277
|
+
// let web work without a Babel/SWC plugin
|
|
278
|
+
inputs = dependencies;
|
|
279
|
+
}
|
|
280
|
+
if (__DEV__ && !inputs.length && !dependencies && !updater.__workletHash) {
|
|
281
|
+
console.error(`useAnimatedStyle was used without a dependency array or Babel plugin. Please explicitly pass a dependency array, or enable the Babel/SWC plugin. For more, see the docs: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/web-support#web-without-a-babel-plugin`);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const adaptersArray = adapters
|
|
285
|
+
? Array.isArray(adapters)
|
|
286
|
+
? adapters
|
|
287
|
+
: [adapters]
|
|
288
|
+
: [];
|
|
289
|
+
const adaptersHash = adapters ? buildWorkletsHash(adaptersArray) : null;
|
|
290
|
+
const animationsActive = useSharedValue(true);
|
|
291
|
+
const animatedStyle = useRef({});
|
|
292
|
+
// build dependencies
|
|
293
|
+
if (!dependencies) {
|
|
294
|
+
dependencies = [...inputs, updater.__workletHash];
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
dependencies.push(updater.__workletHash);
|
|
298
|
+
}
|
|
299
|
+
adaptersHash && dependencies.push(adaptersHash);
|
|
300
|
+
if (!initRef.current) {
|
|
301
|
+
const initialStyle = initialUpdaterRun(updater);
|
|
302
|
+
validateAnimatedStyles(initialStyle);
|
|
303
|
+
initRef.current = {
|
|
304
|
+
initial: {
|
|
305
|
+
value: initialStyle,
|
|
306
|
+
updater: updater,
|
|
307
|
+
},
|
|
308
|
+
remoteState: makeRemote({ last: initialStyle }),
|
|
309
|
+
sharableViewDescriptors: makeMutable([]),
|
|
310
|
+
};
|
|
311
|
+
viewDescriptors.rebuildsharableViewDescriptors(
|
|
312
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
313
|
+
initRef.current.sharableViewDescriptors);
|
|
314
|
+
}
|
|
315
|
+
dependencies.push((_b = initRef.current) === null || _b === void 0 ? void 0 : _b.sharableViewDescriptors.value);
|
|
316
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
317
|
+
const { initial, remoteState, sharableViewDescriptors } = initRef.current;
|
|
318
|
+
const maybeViewRef = NativeReanimatedModule.native ? undefined : viewsRef;
|
|
319
|
+
useEffect(() => {
|
|
320
|
+
let fun;
|
|
321
|
+
let updaterFn = updater;
|
|
322
|
+
let optimalization = updater.__optimalization;
|
|
323
|
+
if (adapters) {
|
|
324
|
+
updaterFn = () => {
|
|
325
|
+
'worklet';
|
|
326
|
+
const newValues = updater();
|
|
327
|
+
adaptersArray.forEach((adapter) => {
|
|
328
|
+
adapter(newValues);
|
|
329
|
+
});
|
|
330
|
+
return newValues;
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
if (canApplyOptimalisation(updaterFn) && !shouldBeUseWeb()) {
|
|
334
|
+
if (hasColorProps(updaterFn())) {
|
|
335
|
+
updaterFn = () => {
|
|
336
|
+
'worklet';
|
|
337
|
+
const newValues = updaterFn();
|
|
338
|
+
const oldValues = remoteState.last;
|
|
339
|
+
const diff = styleDiff(oldValues, newValues);
|
|
340
|
+
remoteState.last = Object.assign({}, oldValues, newValues);
|
|
341
|
+
parseColors(diff);
|
|
342
|
+
return diff;
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
else {
|
|
346
|
+
updaterFn = () => {
|
|
347
|
+
'worklet';
|
|
348
|
+
const newValues = updaterFn();
|
|
349
|
+
const oldValues = remoteState.last;
|
|
350
|
+
const diff = styleDiff(oldValues, newValues);
|
|
351
|
+
remoteState.last = Object.assign({}, oldValues, newValues);
|
|
352
|
+
return diff;
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
else if (!shouldBeUseWeb()) {
|
|
357
|
+
optimalization = 0;
|
|
358
|
+
updaterFn = () => {
|
|
359
|
+
'worklet';
|
|
360
|
+
const style = updaterFn();
|
|
361
|
+
parseColors(style);
|
|
362
|
+
return style;
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
if (typeof updater.__optimalization !== undefined) {
|
|
366
|
+
updaterFn.__optimalization = optimalization;
|
|
367
|
+
}
|
|
368
|
+
if (isJest()) {
|
|
369
|
+
fun = () => {
|
|
370
|
+
'worklet';
|
|
371
|
+
jestStyleUpdater(sharableViewDescriptors, updater, remoteState, maybeViewRef, animationsActive, animatedStyle, adaptersArray);
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
fun = () => {
|
|
376
|
+
'worklet';
|
|
377
|
+
styleUpdater(sharableViewDescriptors, updaterFn, remoteState, maybeViewRef, animationsActive);
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
const mapperId = startMapper(fun, inputs, [], updaterFn,
|
|
381
|
+
// TODO fix this
|
|
382
|
+
sharableViewDescriptors);
|
|
383
|
+
return () => {
|
|
384
|
+
stopMapper(mapperId);
|
|
385
|
+
};
|
|
386
|
+
}, dependencies);
|
|
387
|
+
useEffect(() => {
|
|
388
|
+
animationsActive.value = true;
|
|
389
|
+
return () => {
|
|
390
|
+
// initRef.current = null;
|
|
391
|
+
// viewsRef = null;
|
|
392
|
+
animationsActive.value = false;
|
|
393
|
+
};
|
|
394
|
+
}, []);
|
|
395
|
+
checkSharedValueUsage(initial.value);
|
|
396
|
+
if (process.env.JEST_WORKER_ID) {
|
|
397
|
+
return { viewDescriptors, initial: initial, viewsRef, animatedStyle };
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
return { viewDescriptors, initial: initial, viewsRef };
|
|
401
|
+
}
|
|
402
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { initialUpdaterRun } from '../animation';
|
|
3
|
+
import { makeMutable, startMapper, stopMapper } from '../core';
|
|
4
|
+
import { shouldBeUseWeb } from '../PlatformChecker';
|
|
5
|
+
export function useDerivedValue(processor, dependencies) {
|
|
6
|
+
var _a;
|
|
7
|
+
const initRef = useRef(null);
|
|
8
|
+
let inputs = Object.values((_a = processor._closure) !== null && _a !== void 0 ? _a : {});
|
|
9
|
+
if (shouldBeUseWeb()) {
|
|
10
|
+
if (!inputs.length && (dependencies === null || dependencies === void 0 ? void 0 : dependencies.length)) {
|
|
11
|
+
// let web work without a Babel/SWC plugin
|
|
12
|
+
inputs = dependencies;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// build dependencies
|
|
16
|
+
if (dependencies === undefined) {
|
|
17
|
+
dependencies = [...inputs, processor.__workletHash];
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
dependencies.push(processor.__workletHash);
|
|
21
|
+
}
|
|
22
|
+
if (initRef.current === null) {
|
|
23
|
+
initRef.current = makeMutable(initialUpdaterRun(processor));
|
|
24
|
+
}
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
26
|
+
const sharedValue = initRef.current;
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const fun = () => {
|
|
29
|
+
'worklet';
|
|
30
|
+
sharedValue.value = processor();
|
|
31
|
+
};
|
|
32
|
+
const mapperId = startMapper(fun, inputs, [sharedValue]);
|
|
33
|
+
return () => {
|
|
34
|
+
stopMapper(mapperId);
|
|
35
|
+
};
|
|
36
|
+
}, dependencies);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
return () => {
|
|
39
|
+
initRef.current = null;
|
|
40
|
+
};
|
|
41
|
+
}, []);
|
|
42
|
+
return sharedValue;
|
|
43
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import FrameCallbackRegistryJS from '../frameCallback/FrameCallbackRegistryJS';
|
|
3
|
+
const frameCallbackRegistry = new FrameCallbackRegistryJS();
|
|
4
|
+
export function useFrameCallback(callback, autostart = true) {
|
|
5
|
+
const ref = useRef({
|
|
6
|
+
setActive: (isActive) => {
|
|
7
|
+
frameCallbackRegistry.manageStateFrameCallback(ref.current.callbackId, isActive);
|
|
8
|
+
ref.current.isActive = isActive;
|
|
9
|
+
},
|
|
10
|
+
isActive: autostart,
|
|
11
|
+
callbackId: -1,
|
|
12
|
+
});
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
ref.current.callbackId =
|
|
15
|
+
frameCallbackRegistry.registerFrameCallback(callback);
|
|
16
|
+
ref.current.setActive(ref.current.isActive);
|
|
17
|
+
return () => {
|
|
18
|
+
frameCallbackRegistry.unregisterFrameCallback(ref.current.callbackId);
|
|
19
|
+
ref.current.callbackId = -1;
|
|
20
|
+
};
|
|
21
|
+
}, [callback, autostart]);
|
|
22
|
+
return ref.current;
|
|
23
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { findNodeHandle } from 'react-native';
|
|
3
|
+
import { useEvent } from './utils';
|
|
4
|
+
import { useSharedValue } from './useSharedValue';
|
|
5
|
+
const subscribeForEvents = [
|
|
6
|
+
'onScroll',
|
|
7
|
+
'onScrollBeginDrag',
|
|
8
|
+
'onScrollEndDrag',
|
|
9
|
+
'onMomentumScrollBegin',
|
|
10
|
+
'onMomentumScrollEnd',
|
|
11
|
+
];
|
|
12
|
+
export function useScrollViewOffset(aref) {
|
|
13
|
+
const offsetRef = useRef(useSharedValue(0));
|
|
14
|
+
const event = useEvent((event) => {
|
|
15
|
+
'worklet';
|
|
16
|
+
offsetRef.current.value =
|
|
17
|
+
event.contentOffset.x === 0
|
|
18
|
+
? event.contentOffset.y
|
|
19
|
+
: event.contentOffset.x;
|
|
20
|
+
}, subscribeForEvents);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
var _a;
|
|
23
|
+
const viewTag = findNodeHandle(aref.current);
|
|
24
|
+
(_a = event.current) === null || _a === void 0 ? void 0 : _a.registerForEvents(viewTag);
|
|
25
|
+
}, [aref.current]);
|
|
26
|
+
return offsetRef.current;
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { cancelAnimation } from '../animation';
|
|
3
|
+
import { makeMutable } from '../core';
|
|
4
|
+
export function useSharedValue(init) {
|
|
5
|
+
const ref = useRef(makeMutable(init));
|
|
6
|
+
if (ref.current === null) {
|
|
7
|
+
ref.current = makeMutable(init);
|
|
8
|
+
}
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
return () => {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
12
|
+
cancelAnimation(ref.current);
|
|
13
|
+
};
|
|
14
|
+
}, []);
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
16
|
+
return ref.current;
|
|
17
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { processColor } from '../Colors';
|
|
3
|
+
import { makeRemote } from '../core';
|
|
4
|
+
import { isWeb, isJest } from '../PlatformChecker';
|
|
5
|
+
import { colorProps } from '../UpdateProps';
|
|
6
|
+
import WorkletEventHandler from '../WorkletEventHandler';
|
|
7
|
+
export function useEvent(handler, eventNames = [], rebuild = false) {
|
|
8
|
+
const initRef = useRef(null);
|
|
9
|
+
if (initRef.current === null) {
|
|
10
|
+
initRef.current = new WorkletEventHandler(handler, eventNames);
|
|
11
|
+
}
|
|
12
|
+
else if (rebuild) {
|
|
13
|
+
initRef.current.updateWorklet(handler);
|
|
14
|
+
}
|
|
15
|
+
return initRef;
|
|
16
|
+
}
|
|
17
|
+
export function useHandler(handlers, dependencies) {
|
|
18
|
+
const initRef = useRef(null);
|
|
19
|
+
if (initRef.current === null) {
|
|
20
|
+
initRef.current = {
|
|
21
|
+
context: makeRemote({}),
|
|
22
|
+
savedDependencies: [],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
return () => {
|
|
27
|
+
initRef.current = null;
|
|
28
|
+
};
|
|
29
|
+
}, []);
|
|
30
|
+
const { context, savedDependencies } = initRef.current;
|
|
31
|
+
dependencies = buildDependencies(dependencies, handlers);
|
|
32
|
+
const doDependenciesDiffer = !areDependenciesEqual(dependencies, savedDependencies);
|
|
33
|
+
initRef.current.savedDependencies = dependencies;
|
|
34
|
+
const useWeb = isWeb() || isJest();
|
|
35
|
+
return { context, doDependenciesDiffer, useWeb };
|
|
36
|
+
}
|
|
37
|
+
// builds one big hash from multiple worklets' hashes
|
|
38
|
+
export function buildWorkletsHash(handlers) {
|
|
39
|
+
return Object.values(handlers).reduce((acc, worklet) =>
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
41
|
+
acc + worklet.__workletHash.toString(), '');
|
|
42
|
+
}
|
|
43
|
+
// builds dependencies array for gesture handlers
|
|
44
|
+
export function buildDependencies(dependencies, handlers) {
|
|
45
|
+
const handlersList = Object.values(handlers).filter((handler) => handler !== undefined);
|
|
46
|
+
if (!dependencies) {
|
|
47
|
+
dependencies = handlersList.map((handler) => {
|
|
48
|
+
return {
|
|
49
|
+
workletHash: handler.__workletHash,
|
|
50
|
+
closure: handler._closure,
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
dependencies.push(buildWorkletsHash(handlersList));
|
|
56
|
+
}
|
|
57
|
+
return dependencies;
|
|
58
|
+
}
|
|
59
|
+
// this is supposed to work as useEffect comparison
|
|
60
|
+
export function areDependenciesEqual(nextDeps, prevDeps) {
|
|
61
|
+
function is(x, y) {
|
|
62
|
+
/* eslint-disable no-self-compare */
|
|
63
|
+
return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y);
|
|
64
|
+
/* eslint-enable no-self-compare */
|
|
65
|
+
}
|
|
66
|
+
const objectIs = typeof Object.is === 'function' ? Object.is : is;
|
|
67
|
+
function areHookInputsEqual(nextDeps, prevDeps) {
|
|
68
|
+
if (!nextDeps || !prevDeps || prevDeps.length !== nextDeps.length) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
for (let i = 0; i < prevDeps.length; ++i) {
|
|
72
|
+
if (!objectIs(nextDeps[i], prevDeps[i])) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return areHookInputsEqual(nextDeps, prevDeps);
|
|
79
|
+
}
|
|
80
|
+
export function hasColorProps(updates) {
|
|
81
|
+
const colorPropsSet = new Set(colorProps);
|
|
82
|
+
for (const key in updates) {
|
|
83
|
+
if (colorPropsSet.has(key)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
export function parseColors(updates) {
|
|
90
|
+
'worklet';
|
|
91
|
+
for (const key in updates) {
|
|
92
|
+
if (colorProps.indexOf(key) !== -1) {
|
|
93
|
+
// value could be an animation in which case processColor will recognize it and will return undefined
|
|
94
|
+
// -> in such a case we don't want to override style of that key
|
|
95
|
+
const processedColor = processColor(updates[key]);
|
|
96
|
+
if (processedColor !== undefined) {
|
|
97
|
+
updates[key] = processedColor;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
export function canApplyOptimalisation(upadterFn) {
|
|
103
|
+
const FUNCTIONLESS_FLAG = 0b00000001;
|
|
104
|
+
const STATEMENTLESS_FLAG = 0b00000010;
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
106
|
+
const optimalization = upadterFn.__optimalization;
|
|
107
|
+
return (optimalization & FUNCTIONLESS_FLAG && optimalization & STATEMENTLESS_FLAG);
|
|
108
|
+
}
|
|
109
|
+
export function isAnimated(prop) {
|
|
110
|
+
'worklet';
|
|
111
|
+
if (Array.isArray(prop)) {
|
|
112
|
+
return prop.some(isAnimated);
|
|
113
|
+
}
|
|
114
|
+
else if (typeof prop === 'object') {
|
|
115
|
+
if (prop.onFrame !== undefined) {
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
return Object.values(prop).some(isAnimated);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
export function styleDiff(oldStyle, newStyle) {
|
|
125
|
+
'worklet';
|
|
126
|
+
const diff = {};
|
|
127
|
+
for (const key in oldStyle) {
|
|
128
|
+
if (newStyle[key] === undefined) {
|
|
129
|
+
diff[key] = null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
for (const key in newStyle) {
|
|
133
|
+
const value = newStyle[key];
|
|
134
|
+
const oldValue = oldStyle[key];
|
|
135
|
+
if (isAnimated(value)) {
|
|
136
|
+
// do nothing
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if (oldValue !== value) {
|
|
140
|
+
diff[key] = value;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return diff;
|
|
144
|
+
}
|
|
145
|
+
export function getStyleWithoutAnimations(newStyle) {
|
|
146
|
+
'worklet';
|
|
147
|
+
const diff = {};
|
|
148
|
+
for (const key in newStyle) {
|
|
149
|
+
const value = newStyle[key];
|
|
150
|
+
if (isAnimated(value)) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
diff[key] = value;
|
|
154
|
+
}
|
|
155
|
+
return diff;
|
|
156
|
+
}
|
|
157
|
+
export const validateAnimatedStyles = (styles) => {
|
|
158
|
+
'worklet';
|
|
159
|
+
if (typeof styles !== 'object') {
|
|
160
|
+
throw new Error(`useAnimatedStyle has to return an object, found ${typeof styles} instead`);
|
|
161
|
+
}
|
|
162
|
+
else if (Array.isArray(styles)) {
|
|
163
|
+
throw new Error('useAnimatedStyle has to return an object and cannot return static styles combined with dynamic ones. Please do merging where a component receives props.');
|
|
164
|
+
}
|
|
165
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './core';
|
|
2
|
+
export * from './hook';
|
|
3
|
+
export * from './animation';
|
|
4
|
+
export * from './interpolation';
|
|
5
|
+
export * from './interpolateColor';
|
|
6
|
+
export * from './Easing';
|
|
7
|
+
export * from './NativeMethods';
|
|
8
|
+
export * from './Colors';
|
|
9
|
+
export * from './PropAdapters';
|
|
10
|
+
export * from './layoutReanimation';
|
|
11
|
+
export * from './utils';
|
|
12
|
+
export * from './commonTypes';
|