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,157 @@
|
|
|
1
|
+
import { hsvToColor, RGBtoHSV, rgbaColor, processColor, red, green, blue, opacity, } from './Colors';
|
|
2
|
+
import { makeMutable } from './core';
|
|
3
|
+
import { interpolate } from './interpolation';
|
|
4
|
+
// @ts-ignore JS file
|
|
5
|
+
import { Extrapolate } from '../reanimated1/derived';
|
|
6
|
+
import { useSharedValue } from './hook/useSharedValue';
|
|
7
|
+
const interpolateColorsHSV = (value, inputRange, colors, options) => {
|
|
8
|
+
'worklet';
|
|
9
|
+
let h = 0;
|
|
10
|
+
const { useCorrectedHSVInterpolation = true } = options;
|
|
11
|
+
if (useCorrectedHSVInterpolation) {
|
|
12
|
+
// if the difference between hues in a range is > 180 deg
|
|
13
|
+
// then move the hue at the right end of the range +/- 360 deg
|
|
14
|
+
// and add the next point in the original place + 0.00001 with original hue
|
|
15
|
+
// to not break the next range
|
|
16
|
+
const correctedInputRange = [inputRange[0]];
|
|
17
|
+
const originalH = colors.h;
|
|
18
|
+
const correctedH = [originalH[0]];
|
|
19
|
+
for (let i = 1; i < originalH.length; ++i) {
|
|
20
|
+
const d = originalH[i] - originalH[i - 1];
|
|
21
|
+
if (originalH[i] > originalH[i - 1] && d > 0.5) {
|
|
22
|
+
correctedInputRange.push(inputRange[i]);
|
|
23
|
+
correctedInputRange.push(inputRange[i] + 0.00001);
|
|
24
|
+
correctedH.push(originalH[i] - 1);
|
|
25
|
+
correctedH.push(originalH[i]);
|
|
26
|
+
}
|
|
27
|
+
else if (originalH[i] < originalH[i - 1] && d < -0.5) {
|
|
28
|
+
correctedInputRange.push(inputRange[i]);
|
|
29
|
+
correctedInputRange.push(inputRange[i] + 0.00001);
|
|
30
|
+
correctedH.push(originalH[i] + 1);
|
|
31
|
+
correctedH.push(originalH[i]);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
correctedInputRange.push(inputRange[i]);
|
|
35
|
+
correctedH.push(originalH[i]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
h =
|
|
39
|
+
(interpolate(value, correctedInputRange, correctedH, Extrapolate.CLAMP) +
|
|
40
|
+
1) %
|
|
41
|
+
1;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);
|
|
45
|
+
}
|
|
46
|
+
const s = interpolate(value, inputRange, colors.s, Extrapolate.CLAMP);
|
|
47
|
+
const v = interpolate(value, inputRange, colors.v, Extrapolate.CLAMP);
|
|
48
|
+
const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
|
|
49
|
+
return hsvToColor(h, s, v, a);
|
|
50
|
+
};
|
|
51
|
+
const toLinearSpace = (x, gamma) => {
|
|
52
|
+
'worklet';
|
|
53
|
+
return x.map((v) => Math.pow(v / 255, gamma));
|
|
54
|
+
};
|
|
55
|
+
const toGammaSpace = (x, gamma) => {
|
|
56
|
+
'worklet';
|
|
57
|
+
return Math.round(Math.pow(x, 1 / gamma) * 255);
|
|
58
|
+
};
|
|
59
|
+
const interpolateColorsRGB = (value, inputRange, colors, options) => {
|
|
60
|
+
'worklet';
|
|
61
|
+
const { gamma = 2.2 } = options;
|
|
62
|
+
let { r: outputR, g: outputG, b: outputB } = colors;
|
|
63
|
+
if (gamma !== 1) {
|
|
64
|
+
outputR = toLinearSpace(outputR, gamma);
|
|
65
|
+
outputG = toLinearSpace(outputG, gamma);
|
|
66
|
+
outputB = toLinearSpace(outputB, gamma);
|
|
67
|
+
}
|
|
68
|
+
const r = interpolate(value, inputRange, outputR, Extrapolate.CLAMP);
|
|
69
|
+
const g = interpolate(value, inputRange, outputG, Extrapolate.CLAMP);
|
|
70
|
+
const b = interpolate(value, inputRange, outputB, Extrapolate.CLAMP);
|
|
71
|
+
const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
|
|
72
|
+
if (gamma === 1) {
|
|
73
|
+
return rgbaColor(r, g, b, a);
|
|
74
|
+
}
|
|
75
|
+
return rgbaColor(toGammaSpace(r, gamma), toGammaSpace(g, gamma), toGammaSpace(b, gamma), a);
|
|
76
|
+
};
|
|
77
|
+
const getInterpolateRGB = (colors) => {
|
|
78
|
+
'worklet';
|
|
79
|
+
const r = [];
|
|
80
|
+
const g = [];
|
|
81
|
+
const b = [];
|
|
82
|
+
const a = [];
|
|
83
|
+
for (let i = 0; i < colors.length; ++i) {
|
|
84
|
+
const color = colors[i];
|
|
85
|
+
const processedColor = processColor(color);
|
|
86
|
+
// explicit check in case if processedColor is 0
|
|
87
|
+
if (processedColor !== null && processedColor !== undefined) {
|
|
88
|
+
r.push(red(processedColor));
|
|
89
|
+
g.push(green(processedColor));
|
|
90
|
+
b.push(blue(processedColor));
|
|
91
|
+
a.push(opacity(processedColor));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { r, g, b, a };
|
|
95
|
+
};
|
|
96
|
+
const getInterpolateHSV = (colors) => {
|
|
97
|
+
'worklet';
|
|
98
|
+
const h = [];
|
|
99
|
+
const s = [];
|
|
100
|
+
const v = [];
|
|
101
|
+
const a = [];
|
|
102
|
+
for (let i = 0; i < colors.length; ++i) {
|
|
103
|
+
const color = colors[i];
|
|
104
|
+
const processedColor = processColor(color);
|
|
105
|
+
if (typeof processedColor === 'number') {
|
|
106
|
+
const processedHSVColor = RGBtoHSV(red(processedColor), green(processedColor), blue(processedColor));
|
|
107
|
+
h.push(processedHSVColor.h);
|
|
108
|
+
s.push(processedHSVColor.s);
|
|
109
|
+
v.push(processedHSVColor.v);
|
|
110
|
+
a.push(opacity(processedColor));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return { h, s, v, a };
|
|
114
|
+
};
|
|
115
|
+
export const interpolateColor = (value, inputRange, outputRange, colorSpace = 'RGB', options = {}) => {
|
|
116
|
+
'worklet';
|
|
117
|
+
if (colorSpace === 'HSV') {
|
|
118
|
+
return interpolateColorsHSV(value, inputRange, getInterpolateHSV(outputRange), options);
|
|
119
|
+
}
|
|
120
|
+
else if (colorSpace === 'RGB') {
|
|
121
|
+
return interpolateColorsRGB(value, inputRange, getInterpolateRGB(outputRange), options);
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`Invalid color space provided: ${colorSpace}. Supported values are: ['RGB', 'HSV']`);
|
|
124
|
+
};
|
|
125
|
+
export var ColorSpace;
|
|
126
|
+
(function (ColorSpace) {
|
|
127
|
+
ColorSpace[ColorSpace["RGB"] = 0] = "RGB";
|
|
128
|
+
ColorSpace[ColorSpace["HSV"] = 1] = "HSV";
|
|
129
|
+
})(ColorSpace || (ColorSpace = {}));
|
|
130
|
+
export function useInterpolateConfig(inputRange, outputRange, colorSpace = ColorSpace.RGB, options = {}) {
|
|
131
|
+
return useSharedValue({
|
|
132
|
+
inputRange,
|
|
133
|
+
outputRange,
|
|
134
|
+
colorSpace,
|
|
135
|
+
cache: makeMutable(null),
|
|
136
|
+
options,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
export const interpolateSharableColor = (value, interpolateConfig) => {
|
|
140
|
+
'worklet';
|
|
141
|
+
let colors = interpolateConfig.value.cache.value;
|
|
142
|
+
if (interpolateConfig.value.colorSpace === ColorSpace.RGB) {
|
|
143
|
+
if (!colors) {
|
|
144
|
+
colors = getInterpolateRGB(interpolateConfig.value.outputRange);
|
|
145
|
+
interpolateConfig.value.cache.value = colors;
|
|
146
|
+
}
|
|
147
|
+
return interpolateColorsRGB(value, interpolateConfig.value.inputRange, colors, interpolateConfig.value.options);
|
|
148
|
+
}
|
|
149
|
+
else if (interpolateConfig.value.colorSpace === ColorSpace.HSV) {
|
|
150
|
+
if (!colors) {
|
|
151
|
+
colors = getInterpolateHSV(interpolateConfig.value.outputRange);
|
|
152
|
+
interpolateConfig.value.cache.value = colors;
|
|
153
|
+
}
|
|
154
|
+
return interpolateColorsHSV(value, interpolateConfig.value.inputRange, colors, interpolateConfig.value.options);
|
|
155
|
+
}
|
|
156
|
+
throw new Error(`Invalid color space provided: ${interpolateConfig.value.colorSpace}. Supported values are: ['RGB', 'HSV']`);
|
|
157
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// @ts-ignore JS file
|
|
2
|
+
import interpolateNode from '../reanimated1/derived/interpolate';
|
|
3
|
+
export var Extrapolation;
|
|
4
|
+
(function (Extrapolation) {
|
|
5
|
+
Extrapolation["IDENTITY"] = "identity";
|
|
6
|
+
Extrapolation["CLAMP"] = "clamp";
|
|
7
|
+
Extrapolation["EXTEND"] = "extend";
|
|
8
|
+
})(Extrapolation || (Extrapolation = {}));
|
|
9
|
+
function isNode(x) {
|
|
10
|
+
'worklet';
|
|
11
|
+
return x.__nodeId !== undefined;
|
|
12
|
+
}
|
|
13
|
+
function getVal(type, coef, val, leftEdgeOutput, rightEdgeOutput, x) {
|
|
14
|
+
'worklet';
|
|
15
|
+
switch (type) {
|
|
16
|
+
case Extrapolation.IDENTITY:
|
|
17
|
+
return x;
|
|
18
|
+
case Extrapolation.CLAMP:
|
|
19
|
+
if (coef * val < coef * leftEdgeOutput) {
|
|
20
|
+
return leftEdgeOutput;
|
|
21
|
+
}
|
|
22
|
+
return rightEdgeOutput;
|
|
23
|
+
case Extrapolation.EXTEND:
|
|
24
|
+
default:
|
|
25
|
+
return val;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function isExtrapolate(value) {
|
|
29
|
+
'worklet';
|
|
30
|
+
return (value === Extrapolation.EXTEND ||
|
|
31
|
+
value === Extrapolation.CLAMP ||
|
|
32
|
+
value === Extrapolation.IDENTITY);
|
|
33
|
+
}
|
|
34
|
+
// validates extrapolations type
|
|
35
|
+
// if type is correct, converts it to ExtrapolationConfig
|
|
36
|
+
function validateType(type) {
|
|
37
|
+
'worklet';
|
|
38
|
+
// initialize extrapolationConfig with default extrapolation
|
|
39
|
+
const extrapolationConfig = {
|
|
40
|
+
extrapolateLeft: Extrapolation.EXTEND,
|
|
41
|
+
extrapolateRight: Extrapolation.EXTEND,
|
|
42
|
+
};
|
|
43
|
+
if (!type) {
|
|
44
|
+
return extrapolationConfig;
|
|
45
|
+
}
|
|
46
|
+
if (typeof type === 'string') {
|
|
47
|
+
if (!isExtrapolate(type)) {
|
|
48
|
+
throw new Error(`Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
|
|
49
|
+
interpolate(value, [inputRange], [outputRange], "clamp")`);
|
|
50
|
+
}
|
|
51
|
+
extrapolationConfig.extrapolateLeft = type;
|
|
52
|
+
extrapolationConfig.extrapolateRight = type;
|
|
53
|
+
return extrapolationConfig;
|
|
54
|
+
}
|
|
55
|
+
// otherwise type is extrapolation config object
|
|
56
|
+
if ((type.extrapolateLeft && !isExtrapolate(type.extrapolateLeft)) ||
|
|
57
|
+
(type.extrapolateRight && !isExtrapolate(type.extrapolateRight))) {
|
|
58
|
+
throw new Error(`Reanimated: not supported value for "interpolate" \nSupported values: ["extend", "clamp", "identity", Extrapolatation.CLAMP, Extrapolatation.EXTEND, Extrapolatation.IDENTITY]\n Valid example:
|
|
59
|
+
interpolate(value, [inputRange], [outputRange], {
|
|
60
|
+
extrapolateLeft: Extrapolation.CLAMP,
|
|
61
|
+
extrapolateRight: Extrapolation.IDENTITY
|
|
62
|
+
}})`);
|
|
63
|
+
}
|
|
64
|
+
Object.assign(extrapolationConfig, type);
|
|
65
|
+
return extrapolationConfig;
|
|
66
|
+
}
|
|
67
|
+
function internalInterpolate(x, narrowedInput, extrapolationConfig) {
|
|
68
|
+
'worklet';
|
|
69
|
+
const { leftEdgeInput, rightEdgeInput, leftEdgeOutput, rightEdgeOutput } = narrowedInput;
|
|
70
|
+
if (rightEdgeInput - leftEdgeInput === 0)
|
|
71
|
+
return leftEdgeOutput;
|
|
72
|
+
const progress = (x - leftEdgeInput) / (rightEdgeInput - leftEdgeInput);
|
|
73
|
+
const val = leftEdgeOutput + progress * (rightEdgeOutput - leftEdgeOutput);
|
|
74
|
+
const coef = rightEdgeOutput >= leftEdgeOutput ? 1 : -1;
|
|
75
|
+
if (coef * val < coef * leftEdgeOutput) {
|
|
76
|
+
return getVal(extrapolationConfig.extrapolateLeft, coef, val, leftEdgeOutput, rightEdgeOutput, x);
|
|
77
|
+
}
|
|
78
|
+
else if (coef * val > coef * rightEdgeOutput) {
|
|
79
|
+
return getVal(extrapolationConfig.extrapolateRight, coef, val, leftEdgeOutput, rightEdgeOutput, x);
|
|
80
|
+
}
|
|
81
|
+
return val;
|
|
82
|
+
}
|
|
83
|
+
// TODO: support default values in worklets:
|
|
84
|
+
// e.g. function interpolate(x, input, output, type = Extrapolatation.CLAMP)
|
|
85
|
+
export function interpolate(x, input, output, type) {
|
|
86
|
+
'worklet';
|
|
87
|
+
if (input.length < 2 || output.length < 2) {
|
|
88
|
+
throw Error('Interpolation input and output should contain at least two values.');
|
|
89
|
+
}
|
|
90
|
+
const extrapolationConfig = validateType(type);
|
|
91
|
+
if (isNode(x)) {
|
|
92
|
+
console.warn(`interpolate() was renamed to interpolateNode() in Reanimated 2. Please use interpolateNode() instead`);
|
|
93
|
+
return interpolateNode(x, {
|
|
94
|
+
inputRange: input,
|
|
95
|
+
outputRange: output,
|
|
96
|
+
extrapolateLeft: extrapolationConfig.extrapolateLeft,
|
|
97
|
+
extrapolateRight: extrapolationConfig.extrapolateRight,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
const length = input.length;
|
|
101
|
+
const narrowedInput = {
|
|
102
|
+
leftEdgeInput: input[0],
|
|
103
|
+
rightEdgeInput: input[1],
|
|
104
|
+
leftEdgeOutput: output[0],
|
|
105
|
+
rightEdgeOutput: output[1],
|
|
106
|
+
};
|
|
107
|
+
if (length > 2) {
|
|
108
|
+
if (x > input[length - 1]) {
|
|
109
|
+
narrowedInput.leftEdgeInput = input[length - 2];
|
|
110
|
+
narrowedInput.rightEdgeInput = input[length - 1];
|
|
111
|
+
narrowedInput.leftEdgeOutput = output[length - 2];
|
|
112
|
+
narrowedInput.rightEdgeOutput = output[length - 1];
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
for (let i = 1; i < length; ++i) {
|
|
116
|
+
if (x <= input[i]) {
|
|
117
|
+
narrowedInput.leftEdgeInput = input[i - 1];
|
|
118
|
+
narrowedInput.rightEdgeInput = input[i];
|
|
119
|
+
narrowedInput.leftEdgeOutput = output[i - 1];
|
|
120
|
+
narrowedInput.rightEdgeOutput = output[i];
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return internalInterpolate(x, narrowedInput, extrapolationConfig);
|
|
127
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
import { jestResetJsReanimatedModule } from './core';
|
|
4
|
+
let config = {
|
|
5
|
+
fps: 60,
|
|
6
|
+
};
|
|
7
|
+
const isAnimatedStyle = (style) => {
|
|
8
|
+
return !!style.animatedStyle;
|
|
9
|
+
};
|
|
10
|
+
const getAnimatedStyleFromObject = (style) => {
|
|
11
|
+
return style.animatedStyle.current.value;
|
|
12
|
+
};
|
|
13
|
+
const getCurrentStyle = (received) => {
|
|
14
|
+
const styleObject = received.props.style;
|
|
15
|
+
let currentStyle = {};
|
|
16
|
+
if (Array.isArray(styleObject)) {
|
|
17
|
+
received.props.style.forEach((style) => {
|
|
18
|
+
if (isAnimatedStyle(style)) {
|
|
19
|
+
currentStyle = Object.assign(Object.assign({}, currentStyle), getAnimatedStyleFromObject(style));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
currentStyle = Object.assign(Object.assign({}, currentStyle), style);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
if (isAnimatedStyle(styleObject)) {
|
|
28
|
+
currentStyle = getAnimatedStyleFromObject(styleObject);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
currentStyle = Object.assign(Object.assign({}, styleObject), received.props.animatedStyle.value);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return currentStyle;
|
|
35
|
+
};
|
|
36
|
+
const checkEqual = (currentStyle, expectStyle) => {
|
|
37
|
+
if (Array.isArray(expectStyle)) {
|
|
38
|
+
if (expectStyle.length !== currentStyle.length)
|
|
39
|
+
return false;
|
|
40
|
+
for (let i = 0; i < currentStyle.length; i++) {
|
|
41
|
+
if (!checkEqual(currentStyle[i], expectStyle[i])) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (typeof currentStyle === 'object' && currentStyle) {
|
|
47
|
+
for (const property in expectStyle) {
|
|
48
|
+
if (!checkEqual(currentStyle[property], expectStyle[property])) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return currentStyle === expectStyle;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
};
|
|
58
|
+
const findStyleDiff = (current, expect, requireAllMatch) => {
|
|
59
|
+
const diffs = [];
|
|
60
|
+
let isEqual = true;
|
|
61
|
+
for (const property in expect) {
|
|
62
|
+
if (!checkEqual(current[property], expect[property])) {
|
|
63
|
+
isEqual = false;
|
|
64
|
+
diffs.push({
|
|
65
|
+
property: property,
|
|
66
|
+
current: current[property],
|
|
67
|
+
expect: expect[property],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (requireAllMatch &&
|
|
72
|
+
Object.keys(current).length !== Object.keys(expect).length) {
|
|
73
|
+
isEqual = false;
|
|
74
|
+
for (const property in current) {
|
|
75
|
+
if (expect[property] === undefined) {
|
|
76
|
+
diffs.push({
|
|
77
|
+
property: property,
|
|
78
|
+
current: current[property],
|
|
79
|
+
expect: expect[property],
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return { isEqual, diffs };
|
|
85
|
+
};
|
|
86
|
+
const compareStyle = (received, expectedStyle, config) => {
|
|
87
|
+
if (!received.props.style) {
|
|
88
|
+
return { message: () => message, pass: false };
|
|
89
|
+
}
|
|
90
|
+
const { exact } = config;
|
|
91
|
+
const currentStyle = getCurrentStyle(received);
|
|
92
|
+
const { isEqual, diffs } = findStyleDiff(currentStyle, expectedStyle, exact);
|
|
93
|
+
if (isEqual) {
|
|
94
|
+
return { message: () => 'ok', pass: true };
|
|
95
|
+
}
|
|
96
|
+
const currentStyleStr = JSON.stringify(currentStyle);
|
|
97
|
+
const expectedStyleStr = JSON.stringify(expectedStyle);
|
|
98
|
+
const differences = diffs
|
|
99
|
+
.map((diff) => `- '${diff.property}' should be ${JSON.stringify(diff.expect)}, but is ${JSON.stringify(diff.current)}`)
|
|
100
|
+
.join('\n');
|
|
101
|
+
return {
|
|
102
|
+
message: () => `Expected: ${expectedStyleStr}\nReceived: ${currentStyleStr}\n\nDifferences:\n${differences}`,
|
|
103
|
+
pass: false,
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
let frameTime = 1000 / config.fps;
|
|
107
|
+
let requestAnimationFrameCopy;
|
|
108
|
+
let currentTimestamp = 0;
|
|
109
|
+
const requestAnimationFrame = (callback) => {
|
|
110
|
+
setTimeout(callback, frameTime);
|
|
111
|
+
};
|
|
112
|
+
const beforeTest = () => {
|
|
113
|
+
jestResetJsReanimatedModule();
|
|
114
|
+
requestAnimationFrameCopy = global.requestAnimationFrame;
|
|
115
|
+
global.requestAnimationFrame = requestAnimationFrame;
|
|
116
|
+
global.ReanimatedDataMock = {
|
|
117
|
+
now: () => currentTimestamp,
|
|
118
|
+
};
|
|
119
|
+
currentTimestamp = 0;
|
|
120
|
+
jest.useFakeTimers();
|
|
121
|
+
};
|
|
122
|
+
const afterTest = () => {
|
|
123
|
+
jest.useRealTimers();
|
|
124
|
+
global.requestAnimationFrame = requestAnimationFrameCopy;
|
|
125
|
+
};
|
|
126
|
+
const tickTravel = () => {
|
|
127
|
+
currentTimestamp += frameTime;
|
|
128
|
+
jest.advanceTimersByTime(frameTime);
|
|
129
|
+
};
|
|
130
|
+
export const withReanimatedTimer = (animationTest) => {
|
|
131
|
+
beforeTest();
|
|
132
|
+
animationTest();
|
|
133
|
+
afterTest();
|
|
134
|
+
};
|
|
135
|
+
export const advanceAnimationByTime = (time = frameTime) => {
|
|
136
|
+
for (let i = 0; i <= Math.ceil(time / frameTime); i++) {
|
|
137
|
+
tickTravel();
|
|
138
|
+
}
|
|
139
|
+
jest.advanceTimersByTime(frameTime);
|
|
140
|
+
};
|
|
141
|
+
export const advanceAnimationByFrame = (count) => {
|
|
142
|
+
for (let i = 0; i <= count; i++) {
|
|
143
|
+
tickTravel();
|
|
144
|
+
}
|
|
145
|
+
jest.advanceTimersByTime(frameTime);
|
|
146
|
+
};
|
|
147
|
+
export const setUpTests = (userConfig = {}) => {
|
|
148
|
+
let expect = global.expect;
|
|
149
|
+
if (expect === undefined) {
|
|
150
|
+
const expectModule = require('expect');
|
|
151
|
+
expect = expectModule;
|
|
152
|
+
// Starting from Jest 28, "expect" package uses named exports instead of default export.
|
|
153
|
+
// So, requiring "expect" package doesn't give direct access to "expect" function anymore.
|
|
154
|
+
// It gives access to the module object instead.
|
|
155
|
+
// We use this info to detect if the project uses Jest 28 or higher.
|
|
156
|
+
if (typeof expect === 'object') {
|
|
157
|
+
const jestGlobals = require('@jest/globals');
|
|
158
|
+
expect = jestGlobals.expect;
|
|
159
|
+
}
|
|
160
|
+
if (expect === undefined || expect.extend === undefined) {
|
|
161
|
+
expect = expectModule.default;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
require('setimmediate');
|
|
165
|
+
frameTime = Math.round(1000 / config.fps);
|
|
166
|
+
config = Object.assign(Object.assign({}, config), userConfig);
|
|
167
|
+
expect.extend({
|
|
168
|
+
toHaveAnimatedStyle(received, expectedStyle, config = {}) {
|
|
169
|
+
return compareStyle(received, expectedStyle, config);
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
export const getAnimatedStyle = (received) => {
|
|
174
|
+
return getCurrentStyle(received);
|
|
175
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import MapperRegistry from './MapperRegistry';
|
|
2
|
+
import Mapper from './Mapper';
|
|
3
|
+
import MutableValue from './MutableValue';
|
|
4
|
+
import { NativeReanimated } from '../NativeReanimated/NativeReanimated';
|
|
5
|
+
import { isJest } from '../PlatformChecker';
|
|
6
|
+
export default class JSReanimated extends NativeReanimated {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(false);
|
|
9
|
+
this._valueSetter = undefined;
|
|
10
|
+
this._renderRequested = false;
|
|
11
|
+
this._mapperRegistry = new MapperRegistry(this);
|
|
12
|
+
this._frames = [];
|
|
13
|
+
if (isJest()) {
|
|
14
|
+
this.timeProvider = { now: () => global.ReanimatedDataMock.now() };
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.timeProvider = { now: () => window.performance.now() };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
pushFrame(frame) {
|
|
21
|
+
this._frames.push(frame);
|
|
22
|
+
this.maybeRequestRender();
|
|
23
|
+
}
|
|
24
|
+
getTimestamp() {
|
|
25
|
+
return this.timeProvider.now();
|
|
26
|
+
}
|
|
27
|
+
maybeRequestRender() {
|
|
28
|
+
if (!this._renderRequested) {
|
|
29
|
+
this._renderRequested = true;
|
|
30
|
+
requestAnimationFrame((_timestampMs) => {
|
|
31
|
+
this._renderRequested = false;
|
|
32
|
+
this._onRender(this.getTimestamp());
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
_onRender(timestampMs) {
|
|
37
|
+
this._mapperRegistry.execute();
|
|
38
|
+
const frames = [...this._frames];
|
|
39
|
+
this._frames = [];
|
|
40
|
+
for (let i = 0, len = frames.length; i < len; ++i) {
|
|
41
|
+
frames[i](timestampMs);
|
|
42
|
+
}
|
|
43
|
+
if (this._mapperRegistry.needRunOnRender) {
|
|
44
|
+
this._mapperRegistry.execute();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
installCoreFunctions(valueSetter) {
|
|
48
|
+
this._valueSetter = valueSetter;
|
|
49
|
+
}
|
|
50
|
+
makeShareable(value) {
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
makeMutable(value) {
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
55
|
+
return new MutableValue(value, this._valueSetter);
|
|
56
|
+
}
|
|
57
|
+
makeRemote(object = {}) {
|
|
58
|
+
return object;
|
|
59
|
+
}
|
|
60
|
+
startMapper(mapper, inputs = [], outputs = []) {
|
|
61
|
+
const instance = new Mapper(this, mapper, inputs, outputs);
|
|
62
|
+
const mapperId = this._mapperRegistry.startMapper(instance);
|
|
63
|
+
this.maybeRequestRender();
|
|
64
|
+
return mapperId;
|
|
65
|
+
}
|
|
66
|
+
stopMapper(mapperId) {
|
|
67
|
+
this._mapperRegistry.stopMapper(mapperId);
|
|
68
|
+
}
|
|
69
|
+
registerEventHandler(_, __) {
|
|
70
|
+
// noop
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
unregisterEventHandler(_) {
|
|
74
|
+
// noop
|
|
75
|
+
}
|
|
76
|
+
enableLayoutAnimations() {
|
|
77
|
+
console.warn('[Reanimated] enableLayoutAnimations is not available for WEB yet');
|
|
78
|
+
}
|
|
79
|
+
registerSensor() {
|
|
80
|
+
console.warn('[Reanimated] useAnimatedSensor is not available on web yet.');
|
|
81
|
+
return -1;
|
|
82
|
+
}
|
|
83
|
+
unregisterSensor() {
|
|
84
|
+
// noop
|
|
85
|
+
}
|
|
86
|
+
jestResetModule() {
|
|
87
|
+
if (isJest()) {
|
|
88
|
+
/**
|
|
89
|
+
* If someone used timers to stop animation before the end,
|
|
90
|
+
* then _renderRequested was set as true
|
|
91
|
+
* and any new update from another test wasn't applied.
|
|
92
|
+
*/
|
|
93
|
+
this._renderRequested = false;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
throw Error('This method can be only use in Jest testing.');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
subscribeForKeyboardEvents(_) {
|
|
100
|
+
console.warn('[Reanimated] useAnimatedKeyboard is not available on web yet.');
|
|
101
|
+
return -1;
|
|
102
|
+
}
|
|
103
|
+
unsubscribeFromKeyboardEvents(_) {
|
|
104
|
+
// noop
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import MutableValue from './MutableValue';
|
|
2
|
+
export default class Mapper {
|
|
3
|
+
constructor(module, mapper, inputs = [], outputs = []) {
|
|
4
|
+
this.dirty = true;
|
|
5
|
+
this.id = Mapper.MAPPER_ID++;
|
|
6
|
+
this.inputs = this.extractMutablesFromArray(inputs);
|
|
7
|
+
this.outputs = this.extractMutablesFromArray(outputs);
|
|
8
|
+
this.mapper = mapper;
|
|
9
|
+
const markDirty = () => {
|
|
10
|
+
this.dirty = true;
|
|
11
|
+
module.maybeRequestRender();
|
|
12
|
+
};
|
|
13
|
+
this.inputs.forEach((input) => {
|
|
14
|
+
input.addListener(markDirty);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
execute() {
|
|
18
|
+
this.dirty = false;
|
|
19
|
+
this.mapper();
|
|
20
|
+
}
|
|
21
|
+
extractMutablesFromArray(array) {
|
|
22
|
+
const res = [];
|
|
23
|
+
function extractMutables(value) {
|
|
24
|
+
if (value == null) {
|
|
25
|
+
// return;
|
|
26
|
+
}
|
|
27
|
+
else if (value instanceof MutableValue) {
|
|
28
|
+
res.push(value);
|
|
29
|
+
}
|
|
30
|
+
else if (Array.isArray(value)) {
|
|
31
|
+
value.forEach((v) => extractMutables(v));
|
|
32
|
+
}
|
|
33
|
+
else if (typeof value === 'object') {
|
|
34
|
+
Object.keys(value).forEach((key) => {
|
|
35
|
+
extractMutables(value[key]);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
extractMutables(array);
|
|
40
|
+
return res;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
Mapper.MAPPER_ID = 1;
|