react-native-reanimated 2.3.3 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +72 -0
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +30 -1
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +64 -39
- package/Common/cpp/Tools/RuntimeDecorator.cpp +2 -0
- package/Common/cpp/headers/AnimatedSensor/AnimatedSensorModule.h +41 -0
- package/Common/cpp/headers/NativeModules/NativeReanimatedModule.h +14 -0
- package/Common/cpp/headers/NativeModules/NativeReanimatedModuleSpec.h +14 -0
- package/Common/cpp/headers/SharedItems/MutableValue.h +4 -1
- package/Common/cpp/headers/SharedItems/ShareableValue.h +3 -0
- package/Common/cpp/headers/SharedItems/ValueWrapper.h +3 -0
- package/Common/cpp/headers/Tools/PlatformDepMethodsHolder.h +11 -0
- package/Common/cpp/headers/Tools/RuntimeDecorator.h +2 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/android/.gradle/7.2/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/7.2/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/7.2/executionHistory/executionHistory.bin +0 -0
- package/android/.gradle/7.2/executionHistory/executionHistory.lock +0 -0
- package/android/.gradle/7.2/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.2/fileHashes/fileHashes.bin +0 -0
- package/android/.gradle/7.2/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.2/fileHashes/resourceHashesCache.bin +0 -0
- package/android/.gradle/7.2/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/checksums/checksums.lock +0 -0
- package/android/.gradle/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/CMakeLists.txt +198 -0
- package/android/README.md +15 -0
- package/android/build.gradle +686 -73
- package/android/empty.cpp +1 -0
- package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
- package/android/gradle.properties +25 -0
- package/android/gradlew +234 -0
- package/android/gradlew.bat +89 -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/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/rnVersionPatch/62/layoutReanimation/ReanimatedNativeHierarchyManager.java +412 -0
- package/android/rnVersionPatch/62/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- package/android/rnVersionPatch/63/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- package/android/rnVersionPatch/64/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- package/android/rnVersionPatch/65/.gitkeep +0 -0
- package/android/rnVersionPatch/66/.gitkeep +0 -0
- package/android/rnVersionPatch/67/.gitkeep +0 -0
- package/android/rnVersionPatch/68/.gitkeep +0 -0
- package/android/rnVersionPatch/backup/.gitkeep +0 -0
- package/android/settings.gradle +1 -0
- package/android/spotless.gradle +9 -0
- package/android/src/{AndroidManifest.xml → main/AndroidManifest.xml} +0 -0
- package/android/src/main/cpp/AndroidErrorHandler.cpp +42 -0
- package/android/src/main/cpp/AndroidLogger.cpp +27 -0
- package/android/src/main/cpp/AndroidScheduler.cpp +59 -0
- package/android/src/main/cpp/JNIHelper.cpp +59 -0
- package/android/src/main/cpp/LayoutAnimations.cpp +103 -0
- package/android/src/main/cpp/NativeProxy.cpp +327 -0
- package/android/src/main/cpp/OnLoad.cpp +17 -0
- package/android/src/main/cpp/TurboModule.cpp +44 -0
- package/android/src/main/cpp/headers/AndroidErrorHandler.h +30 -0
- package/android/src/main/cpp/headers/AndroidLogger.h +16 -0
- package/android/src/main/cpp/headers/AndroidScheduler.h +41 -0
- package/android/src/main/cpp/headers/JNIHelper.h +30 -0
- package/android/src/main/cpp/headers/LayoutAnimations.h +42 -0
- package/android/src/main/cpp/headers/NativeProxy.h +170 -0
- package/android/src/main/cpp/headers/TurboModule.h +70 -0
- package/android/src/main/java/com/facebook/react/uimanager/UIManagerReanimatedHelper.java +15 -0
- package/android/src/main/java/com/swmansion/common/GestureHandlerStateManager.java +5 -0
- package/android/src/main/java/com/swmansion/reanimated/AndroidErrorHandler.java +8 -0
- package/android/src/main/java/com/swmansion/reanimated/CopiedEvent.java +43 -0
- package/android/src/main/java/com/swmansion/reanimated/MapUtils.java +26 -0
- package/android/src/main/java/com/swmansion/reanimated/NativeMethodsHelper.java +117 -0
- package/android/src/main/java/com/swmansion/reanimated/NativeProxy.java +285 -0
- package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +682 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedJSIModulePackage.java +29 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedModule.java +251 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedPackage.java +96 -0
- package/android/src/main/java/com/swmansion/reanimated/Scheduler.java +51 -0
- package/android/src/main/java/com/swmansion/reanimated/UpdateContext.java +11 -0
- package/android/src/main/java/com/swmansion/reanimated/Utils.java +32 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +517 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +56 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +11 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +410 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIImplementation.java +68 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ReanimatedUIManager.java +292 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/Snapshot.java +121 -0
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ViewHierarchyObserver.java +12 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/AlwaysNode.java +29 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/BezierNode.java +87 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/BlockNode.java +24 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/CallFuncNode.java +49 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ClockNode.java +38 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ClockOpNode.java +73 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ConcatNode.java +36 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/CondNode.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/DebugNode.java +33 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/EventNode.java +83 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/FinalNode.java +5 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/FunctionNode.java +20 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/JSCallNode.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/Node.java +139 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/NoopNode.java +37 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/OperatorNode.java +377 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ParamNode.java +71 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/PropsNode.java +153 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/SetNode.java +32 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/StyleNode.java +40 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/TransformNode.java +84 -0
- package/android/src/main/java/com/swmansion/reanimated/nodes/ValueNode.java +40 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensor.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorContainer.java +40 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorListener.java +31 -0
- package/android/src/main/java/com/swmansion/reanimated/sensor/ReanimatedSensorType.java +35 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/ChangeTransition.java +84 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/SaneSidePropagation.java +25 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/Scale.java +86 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionModule.java +41 -0
- package/android/src/main/java/com/swmansion/reanimated/transitions/TransitionUtils.java +161 -0
- package/ios/LayoutReanimation/REAAnimationsManager.h +1 -1
- package/ios/LayoutReanimation/REAAnimationsManager.m +18 -4
- package/ios/REAModule.m +8 -9
- package/ios/REANodesManager.h +4 -1
- package/ios/REANodesManager.m +75 -3
- package/ios/native/NativeMethods.h +1 -1
- package/ios/native/NativeProxy.mm +85 -5
- package/ios/sensor/ReanimatedSensor.h +21 -0
- package/ios/sensor/ReanimatedSensor.m +169 -0
- package/ios/sensor/ReanimatedSensorContainer.h +13 -0
- package/ios/sensor/ReanimatedSensorContainer.m +41 -0
- package/ios/sensor/ReanimatedSensorType.h +7 -0
- package/lib/ConfigHelper.js +2 -2
- package/lib/createAnimatedComponent.js +3 -4
- package/lib/reanimated1/core/AnimatedFunction.js +1 -1
- package/lib/reanimated1/derived/interpolate.js +2 -4
- package/lib/reanimated2/Colors.js +3 -98
- package/lib/reanimated2/Easing.js +5 -0
- package/lib/reanimated2/NativeMethods.js +15 -5
- package/lib/reanimated2/NativeReanimated/NativeReanimated.js +25 -12
- package/lib/reanimated2/NativeReanimated/index.js +2 -6
- package/lib/reanimated2/ViewDescriptorsSet.js +2 -2
- package/lib/reanimated2/animation/styleAnimation.js +2 -1
- package/lib/reanimated2/core.js +30 -24
- package/lib/reanimated2/globals.d.ts +6 -0
- package/lib/reanimated2/hook/index.js +1 -0
- package/lib/reanimated2/hook/useAnimatedGestureHandler.js +1 -2
- package/lib/reanimated2/hook/useAnimatedSensor.js +66 -0
- package/lib/reanimated2/hook/useAnimatedStyle.js +31 -14
- package/lib/reanimated2/hook/utils.js +14 -11
- package/lib/reanimated2/index.js +2 -0
- package/lib/reanimated2/interpolateColor.js +98 -0
- package/lib/reanimated2/interpolation.js +1 -1
- package/lib/reanimated2/jestUtils.js +9 -4
- package/lib/reanimated2/js-reanimated/JSReanimated.js +24 -3
- package/lib/reanimated2/js-reanimated/commonTypes.js +1 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +8 -0
- package/lib/reanimated2/layoutReanimation/animationBuilder/Keyframe.js +2 -1
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Bounce.js +32 -42
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Fade.js +20 -38
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +32 -44
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.js +8 -16
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.js +6 -10
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Roll.js +8 -12
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +20 -36
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +16 -20
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Stretch.js +8 -12
- package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +32 -48
- package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +22 -18
- package/lib/reanimated2/mock.js +3 -2
- package/mock.js +6 -4
- package/package.json +44 -36
- package/plugin.js +3 -0
- package/react-native-reanimated.d.ts +102 -15
- package/src/ConfigHelper.ts +4 -4
- package/src/createAnimatedComponent.tsx +3 -3
- package/src/reanimated1/core/AnimatedFunction.js +1 -1
- package/src/reanimated1/derived/interpolate.js +2 -4
- package/src/reanimated2/Colors.ts +8 -151
- package/src/reanimated2/Easing.ts +11 -0
- package/src/reanimated2/NativeMethods.ts +19 -6
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +42 -14
- package/src/reanimated2/NativeReanimated/index.ts +2 -8
- package/src/reanimated2/ViewDescriptorsSet.ts +2 -3
- package/src/reanimated2/animation/commonTypes.ts +44 -40
- package/src/reanimated2/animation/decay.ts +1 -1
- package/src/reanimated2/animation/delay.ts +2 -16
- package/src/reanimated2/animation/index.ts +8 -8
- package/src/reanimated2/animation/repeat.ts +2 -12
- package/src/reanimated2/animation/sequence.ts +3 -10
- package/src/reanimated2/animation/spring.ts +1 -1
- package/src/reanimated2/animation/styleAnimation.ts +11 -25
- package/src/reanimated2/animation/timing.ts +4 -2
- package/src/reanimated2/animation/util.ts +22 -20
- package/src/reanimated2/commonTypes.ts +68 -1
- package/src/reanimated2/component/FlatList.tsx +2 -1
- package/src/reanimated2/core.ts +35 -29
- package/src/reanimated2/globals.d.ts +6 -0
- package/src/reanimated2/hook/commonTypes.ts +5 -0
- package/src/reanimated2/hook/index.ts +1 -0
- package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -2
- package/src/reanimated2/hook/useAnimatedRef.ts +1 -5
- package/src/reanimated2/hook/useAnimatedSensor.ts +91 -0
- package/src/reanimated2/hook/useAnimatedStyle.ts +35 -16
- package/src/reanimated2/hook/utils.ts +20 -18
- package/src/reanimated2/index.ts +2 -0
- package/src/reanimated2/interpolateColor.ts +178 -0
- package/src/reanimated2/interpolation.ts +2 -6
- package/src/reanimated2/jestUtils.ts +9 -4
- package/src/reanimated2/js-reanimated/JSReanimated.ts +28 -6
- package/src/reanimated2/js-reanimated/Mapper.ts +1 -1
- package/src/reanimated2/js-reanimated/MapperRegistry.ts +1 -1
- package/src/reanimated2/js-reanimated/commonTypes.ts +51 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/ComplexAnimationBuilder.ts +13 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/Keyframe.ts +2 -3
- package/src/reanimated2/layoutReanimation/defaultAnimations/Bounce.ts +51 -21
- package/src/reanimated2/layoutReanimation/defaultAnimations/Fade.ts +40 -10
- package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +48 -12
- package/src/reanimated2/layoutReanimation/defaultAnimations/Lightspeed.ts +16 -4
- package/src/reanimated2/layoutReanimation/defaultAnimations/Pinwheel.ts +8 -2
- package/src/reanimated2/layoutReanimation/defaultAnimations/Roll.ts +16 -4
- package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +32 -8
- package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +32 -10
- package/src/reanimated2/layoutReanimation/defaultAnimations/Stretch.ts +16 -4
- package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +64 -16
- package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +32 -21
- package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +2 -1
- package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +2 -1
- package/src/reanimated2/mock.ts +3 -2
- package/src/reanimated2/utils.ts +1 -1
- package/android/react-native-reanimated-63-hermes.aar +0 -0
- package/android/react-native-reanimated-63-jsc.aar +0 -0
- package/android/src/main/java/com/swmansion/reanimated/ReanimatedProxyPackage.java +0 -15
- 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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { MutableRefObject, useEffect, useRef } from 'react';
|
|
2
|
-
import { AnimationObject } from '../animation';
|
|
3
2
|
import { processColor } from '../Colors';
|
|
4
3
|
import {
|
|
5
4
|
AnimatedStyle,
|
|
@@ -7,9 +6,10 @@ import {
|
|
|
7
6
|
NestedObjectValues,
|
|
8
7
|
StyleProps,
|
|
9
8
|
WorkletFunction,
|
|
9
|
+
AnimationObject,
|
|
10
10
|
} from '../commonTypes';
|
|
11
11
|
import { makeRemote } from '../core';
|
|
12
|
-
import { isWeb } from '../PlatformChecker';
|
|
12
|
+
import { isWeb, isJest } from '../PlatformChecker';
|
|
13
13
|
import { colorProps } from '../UpdateProps';
|
|
14
14
|
import WorkletEventHandler from '../WorkletEventHandler';
|
|
15
15
|
import {
|
|
@@ -80,7 +80,7 @@ export function useHandler<T, TContext extends Context>(
|
|
|
80
80
|
savedDependencies
|
|
81
81
|
);
|
|
82
82
|
initRef.current.savedDependencies = dependencies;
|
|
83
|
-
const useWeb = isWeb();
|
|
83
|
+
const useWeb = isWeb() || isJest();
|
|
84
84
|
|
|
85
85
|
return { context, doDependenciesDiffer, useWeb };
|
|
86
86
|
}
|
|
@@ -163,7 +163,12 @@ export function parseColors(updates: AnimatedStyle): void {
|
|
|
163
163
|
'worklet';
|
|
164
164
|
for (const key in updates) {
|
|
165
165
|
if (colorProps.indexOf(key) !== -1) {
|
|
166
|
-
|
|
166
|
+
// value could be an animation in which case processColor will recognize it and will return undefined
|
|
167
|
+
// -> in such a case we don't want to override style of that key
|
|
168
|
+
const processedColor = processColor(updates[key]);
|
|
169
|
+
if (processedColor !== undefined) {
|
|
170
|
+
updates[key] = processedColor;
|
|
171
|
+
}
|
|
167
172
|
}
|
|
168
173
|
}
|
|
169
174
|
}
|
|
@@ -182,7 +187,8 @@ export function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {
|
|
|
182
187
|
'worklet';
|
|
183
188
|
const propsToCheck: NestedObjectValues<AnimationObject>[] = [prop];
|
|
184
189
|
while (propsToCheck.length > 0) {
|
|
185
|
-
const currentProp: NestedObjectValues<AnimationObject> =
|
|
190
|
+
const currentProp: NestedObjectValues<AnimationObject> =
|
|
191
|
+
propsToCheck.pop() as NestedObjectValues<AnimationObject>;
|
|
186
192
|
if (Array.isArray(currentProp)) {
|
|
187
193
|
for (const item of currentProp) {
|
|
188
194
|
propsToCheck.push(item);
|
|
@@ -201,33 +207,29 @@ export function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {
|
|
|
201
207
|
return false;
|
|
202
208
|
}
|
|
203
209
|
|
|
204
|
-
export function styleDiff(
|
|
210
|
+
export function styleDiff<T extends AnimatedStyle>(
|
|
205
211
|
oldStyle: AnimatedStyle,
|
|
206
212
|
newStyle: AnimatedStyle
|
|
207
|
-
):
|
|
213
|
+
): Partial<T> {
|
|
208
214
|
'worklet';
|
|
209
|
-
const diff:
|
|
210
|
-
|
|
215
|
+
const diff: any = {};
|
|
216
|
+
for (const key in oldStyle) {
|
|
211
217
|
if (newStyle[key] === undefined) {
|
|
212
218
|
diff[key] = null;
|
|
213
219
|
}
|
|
214
|
-
}
|
|
215
|
-
|
|
220
|
+
}
|
|
221
|
+
for (const key in newStyle) {
|
|
216
222
|
const value = newStyle[key];
|
|
217
223
|
const oldValue = oldStyle[key];
|
|
218
224
|
|
|
219
225
|
if (isAnimated(value)) {
|
|
220
226
|
// do nothing
|
|
221
|
-
|
|
227
|
+
continue;
|
|
222
228
|
}
|
|
223
|
-
if (
|
|
224
|
-
oldValue !== value &&
|
|
225
|
-
JSON.stringify(oldValue) !== JSON.stringify(value)
|
|
226
|
-
) {
|
|
227
|
-
// I'd use deep equal here but that'd take additional work and this was easier
|
|
229
|
+
if (oldValue !== value) {
|
|
228
230
|
diff[key] = value;
|
|
229
231
|
}
|
|
230
|
-
}
|
|
232
|
+
}
|
|
231
233
|
return diff;
|
|
232
234
|
}
|
|
233
235
|
|
package/src/reanimated2/index.ts
CHANGED
|
@@ -2,9 +2,11 @@ export * from './core';
|
|
|
2
2
|
export * from './hook';
|
|
3
3
|
export * from './animation';
|
|
4
4
|
export * from './interpolation';
|
|
5
|
+
export * from './interpolateColor';
|
|
5
6
|
export * from './Easing';
|
|
6
7
|
export * from './NativeMethods';
|
|
7
8
|
export * from './Colors';
|
|
8
9
|
export * from './PropAdapters';
|
|
9
10
|
export * from './layoutReanimation';
|
|
10
11
|
export * from './utils';
|
|
12
|
+
export * from './commonTypes';
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hsvToColor,
|
|
3
|
+
RGBtoHSV,
|
|
4
|
+
rgbaColor,
|
|
5
|
+
processColor,
|
|
6
|
+
red,
|
|
7
|
+
green,
|
|
8
|
+
blue,
|
|
9
|
+
opacity,
|
|
10
|
+
} from './Colors';
|
|
11
|
+
import { makeMutable } from './core';
|
|
12
|
+
import { interpolate } from './interpolation';
|
|
13
|
+
// @ts-ignore JS file
|
|
14
|
+
import { Extrapolate } from '../reanimated1/derived';
|
|
15
|
+
import { SharedValue } from './commonTypes';
|
|
16
|
+
import { useSharedValue } from './hook/useSharedValue';
|
|
17
|
+
|
|
18
|
+
const interpolateColorsHSV = (
|
|
19
|
+
value: number,
|
|
20
|
+
inputRange: readonly number[],
|
|
21
|
+
colors: InterpolateHSV
|
|
22
|
+
) => {
|
|
23
|
+
'worklet';
|
|
24
|
+
const h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);
|
|
25
|
+
const s = interpolate(value, inputRange, colors.s, Extrapolate.CLAMP);
|
|
26
|
+
const v = interpolate(value, inputRange, colors.v, Extrapolate.CLAMP);
|
|
27
|
+
return hsvToColor(h, s, v);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const interpolateColorsRGB = (
|
|
31
|
+
value: number,
|
|
32
|
+
inputRange: readonly number[],
|
|
33
|
+
colors: InterpolateRGB
|
|
34
|
+
) => {
|
|
35
|
+
'worklet';
|
|
36
|
+
const r = interpolate(value, inputRange, colors.r, Extrapolate.CLAMP);
|
|
37
|
+
const g = interpolate(value, inputRange, colors.g, Extrapolate.CLAMP);
|
|
38
|
+
const b = interpolate(value, inputRange, colors.b, Extrapolate.CLAMP);
|
|
39
|
+
const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
|
|
40
|
+
return rgbaColor(r, g, b, a);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
interface InterpolateRGB {
|
|
44
|
+
r: number[];
|
|
45
|
+
g: number[];
|
|
46
|
+
b: number[];
|
|
47
|
+
a: number[];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const getInterpolateRGB = (
|
|
51
|
+
colors: readonly (string | number)[]
|
|
52
|
+
): InterpolateRGB => {
|
|
53
|
+
'worklet';
|
|
54
|
+
|
|
55
|
+
const r = [];
|
|
56
|
+
const g = [];
|
|
57
|
+
const b = [];
|
|
58
|
+
const a = [];
|
|
59
|
+
for (let i = 0; i < colors.length; ++i) {
|
|
60
|
+
const color = colors[i];
|
|
61
|
+
const proocessedColor = processColor(color);
|
|
62
|
+
// explicit check in case if processedColor is 0
|
|
63
|
+
if (proocessedColor !== null && proocessedColor !== undefined) {
|
|
64
|
+
r.push(red(proocessedColor));
|
|
65
|
+
g.push(green(proocessedColor));
|
|
66
|
+
b.push(blue(proocessedColor));
|
|
67
|
+
a.push(opacity(proocessedColor));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return { r, g, b, a };
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
interface InterpolateHSV {
|
|
74
|
+
h: number[];
|
|
75
|
+
s: number[];
|
|
76
|
+
v: number[];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const getInterpolateHSV = (
|
|
80
|
+
colors: readonly (string | number)[]
|
|
81
|
+
): InterpolateHSV => {
|
|
82
|
+
'worklet';
|
|
83
|
+
const h = [];
|
|
84
|
+
const s = [];
|
|
85
|
+
const v = [];
|
|
86
|
+
for (let i = 0; i < colors.length; ++i) {
|
|
87
|
+
const color = colors[i];
|
|
88
|
+
const proocessedColor = RGBtoHSV(processColor(color) as any);
|
|
89
|
+
if (proocessedColor) {
|
|
90
|
+
h.push(proocessedColor.h);
|
|
91
|
+
s.push(proocessedColor.s);
|
|
92
|
+
v.push(proocessedColor.v);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { h, s, v };
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const interpolateColor = (
|
|
99
|
+
value: number,
|
|
100
|
+
inputRange: readonly number[],
|
|
101
|
+
outputRange: readonly (string | number)[],
|
|
102
|
+
colorSpace: 'RGB' | 'HSV' = 'RGB'
|
|
103
|
+
): string | number => {
|
|
104
|
+
'worklet';
|
|
105
|
+
if (colorSpace === 'HSV') {
|
|
106
|
+
return interpolateColorsHSV(
|
|
107
|
+
value,
|
|
108
|
+
inputRange,
|
|
109
|
+
getInterpolateHSV(outputRange)
|
|
110
|
+
);
|
|
111
|
+
} else if (colorSpace === 'RGB') {
|
|
112
|
+
return interpolateColorsRGB(
|
|
113
|
+
value,
|
|
114
|
+
inputRange,
|
|
115
|
+
getInterpolateRGB(outputRange)
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
throw new Error(
|
|
119
|
+
`Invalid color space provided: ${colorSpace}. Supported values are: ['RGB', 'HSV']`
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export enum ColorSpace {
|
|
124
|
+
RGB = 0,
|
|
125
|
+
HSV = 1,
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export interface InterpolateConfig {
|
|
129
|
+
inputRange: readonly number[];
|
|
130
|
+
outputRange: readonly (string | number)[];
|
|
131
|
+
colorSpace: ColorSpace;
|
|
132
|
+
cache: SharedValue<InterpolateRGB | InterpolateHSV | null>;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function useInterpolateConfig(
|
|
136
|
+
inputRange: readonly number[],
|
|
137
|
+
outputRange: readonly (string | number)[],
|
|
138
|
+
colorSpace = ColorSpace.RGB
|
|
139
|
+
): SharedValue<InterpolateConfig> {
|
|
140
|
+
return useSharedValue({
|
|
141
|
+
inputRange,
|
|
142
|
+
outputRange,
|
|
143
|
+
colorSpace,
|
|
144
|
+
cache: makeMutable(null),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export const interpolateSharableColor = (
|
|
149
|
+
value: number,
|
|
150
|
+
interpolateConfig: SharedValue<InterpolateConfig>
|
|
151
|
+
): string | number => {
|
|
152
|
+
'worklet';
|
|
153
|
+
let colors = interpolateConfig.value.cache.value;
|
|
154
|
+
if (interpolateConfig.value.colorSpace === ColorSpace.RGB) {
|
|
155
|
+
if (!colors) {
|
|
156
|
+
colors = getInterpolateRGB(interpolateConfig.value.outputRange);
|
|
157
|
+
interpolateConfig.value.cache.value = colors;
|
|
158
|
+
}
|
|
159
|
+
return interpolateColorsRGB(
|
|
160
|
+
value,
|
|
161
|
+
interpolateConfig.value.inputRange,
|
|
162
|
+
colors as InterpolateRGB
|
|
163
|
+
);
|
|
164
|
+
} else if (interpolateConfig.value.colorSpace === ColorSpace.HSV) {
|
|
165
|
+
if (!colors) {
|
|
166
|
+
colors = getInterpolateHSV(interpolateConfig.value.outputRange);
|
|
167
|
+
interpolateConfig.value.cache.value = colors;
|
|
168
|
+
}
|
|
169
|
+
return interpolateColorsHSV(
|
|
170
|
+
value,
|
|
171
|
+
interpolateConfig.value.inputRange,
|
|
172
|
+
colors as InterpolateHSV
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
throw new Error(
|
|
176
|
+
`Invalid color space provided: ${interpolateConfig.value.colorSpace}. Supported values are: ['RGB', 'HSV']`
|
|
177
|
+
);
|
|
178
|
+
};
|
|
@@ -123,12 +123,8 @@ function internalInterpolate(
|
|
|
123
123
|
extrapolationConfig: RequiredExtrapolationConfig
|
|
124
124
|
) {
|
|
125
125
|
'worklet';
|
|
126
|
-
const {
|
|
127
|
-
|
|
128
|
-
rightEdgeInput,
|
|
129
|
-
leftEdgeOutput,
|
|
130
|
-
rightEdgeOutput,
|
|
131
|
-
} = narrowedInput;
|
|
126
|
+
const { leftEdgeInput, rightEdgeInput, leftEdgeOutput, rightEdgeOutput } =
|
|
127
|
+
narrowedInput;
|
|
132
128
|
if (rightEdgeInput - leftEdgeInput === 0) return leftEdgeOutput;
|
|
133
129
|
const progress = (x - leftEdgeInput) / (rightEdgeInput - leftEdgeInput);
|
|
134
130
|
const val = leftEdgeOutput + progress * (rightEdgeOutput - leftEdgeOutput);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
2
|
// @ts-nocheck
|
|
3
|
-
|
|
3
|
+
import { jestResetJsReanimatedModule } from './core';
|
|
4
4
|
|
|
5
5
|
let config = {
|
|
6
6
|
fps: 60,
|
|
@@ -129,26 +129,30 @@ const compareStyle = (received, expectedStyle, config) => {
|
|
|
129
129
|
|
|
130
130
|
let frameTime = 1000 / config.fps;
|
|
131
131
|
let requestAnimationFrameCopy;
|
|
132
|
+
let currentTimestamp = 0;
|
|
132
133
|
|
|
133
134
|
const requestAnimationFrame = (callback) => {
|
|
134
135
|
setTimeout(callback, frameTime);
|
|
135
136
|
};
|
|
136
137
|
|
|
137
138
|
const beforeTest = () => {
|
|
139
|
+
jestResetJsReanimatedModule();
|
|
138
140
|
requestAnimationFrameCopy = global.requestAnimationFrame;
|
|
139
141
|
global.requestAnimationFrame = requestAnimationFrame;
|
|
140
|
-
|
|
142
|
+
global.ReanimatedDataMock = {
|
|
143
|
+
now: () => currentTimestamp,
|
|
144
|
+
};
|
|
145
|
+
currentTimestamp = 0;
|
|
141
146
|
jest.useFakeTimers();
|
|
142
147
|
};
|
|
143
148
|
|
|
144
149
|
const afterTest = () => {
|
|
145
|
-
MockDate.reset();
|
|
146
150
|
jest.useRealTimers();
|
|
147
151
|
global.requestAnimationFrame = requestAnimationFrameCopy;
|
|
148
152
|
};
|
|
149
153
|
|
|
150
154
|
const tickTravel = () => {
|
|
151
|
-
|
|
155
|
+
currentTimestamp += frameTime;
|
|
152
156
|
jest.advanceTimersByTime(frameTime);
|
|
153
157
|
};
|
|
154
158
|
|
|
@@ -174,6 +178,7 @@ export const advanceAnimationByFrame = (count) => {
|
|
|
174
178
|
|
|
175
179
|
export const setUpTests = (userConfig = {}) => {
|
|
176
180
|
const expect = require('expect');
|
|
181
|
+
require('setimmediate');
|
|
177
182
|
frameTime = Math.round(1000 / config.fps);
|
|
178
183
|
|
|
179
184
|
config = {
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import MapperRegistry from './MapperRegistry';
|
|
2
|
-
import MutableValue from './MutableValue';
|
|
3
2
|
import Mapper from './Mapper';
|
|
3
|
+
import MutableValue from './MutableValue';
|
|
4
4
|
import { NativeReanimated } from '../NativeReanimated/NativeReanimated';
|
|
5
|
-
import { Timestamp } from '../
|
|
6
|
-
import {
|
|
5
|
+
import { Timestamp, NestedObjectValues } from '../commonTypes';
|
|
6
|
+
import { isJest } from '../PlatformChecker';
|
|
7
7
|
|
|
8
8
|
export default class JSReanimated extends NativeReanimated {
|
|
9
9
|
_valueSetter?: <T>(value: T) => void = undefined;
|
|
10
10
|
|
|
11
11
|
_renderRequested = false;
|
|
12
|
-
_mapperRegistry = new MapperRegistry(this);
|
|
12
|
+
_mapperRegistry: MapperRegistry<any> = new MapperRegistry(this);
|
|
13
13
|
_frames: ((timestamp: Timestamp) => void)[] = [];
|
|
14
14
|
timeProvider: { now: () => number };
|
|
15
15
|
|
|
16
16
|
constructor() {
|
|
17
17
|
super(false);
|
|
18
|
-
if (
|
|
19
|
-
this.timeProvider = { now: () =>
|
|
18
|
+
if (isJest()) {
|
|
19
|
+
this.timeProvider = { now: () => global.ReanimatedDataMock.now() };
|
|
20
20
|
} else {
|
|
21
21
|
this.timeProvider = { now: () => window.performance.now() };
|
|
22
22
|
}
|
|
@@ -104,4 +104,26 @@ export default class JSReanimated extends NativeReanimated {
|
|
|
104
104
|
'[Reanimated] enableLayoutAnimations is not available for WEB yet'
|
|
105
105
|
);
|
|
106
106
|
}
|
|
107
|
+
|
|
108
|
+
registerSensor(): number {
|
|
109
|
+
console.warn('[Reanimated] useAnimatedSensor is not available on web yet.');
|
|
110
|
+
return -1;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
unregisterSensor(): void {
|
|
114
|
+
// noop
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
jestResetModule() {
|
|
118
|
+
if (isJest()) {
|
|
119
|
+
/**
|
|
120
|
+
* If someone used timers to stop animation before the end,
|
|
121
|
+
* then _renderRequested was set as true
|
|
122
|
+
* and any new update from another test wasn't applied.
|
|
123
|
+
*/
|
|
124
|
+
this._renderRequested = false;
|
|
125
|
+
} else {
|
|
126
|
+
throw Error('This method can be only use in Jest testing.');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
107
129
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Timestamp, NestedObjectValues } from '../commonTypes';
|
|
2
|
+
import MutableValue from './MutableValue';
|
|
3
|
+
|
|
4
|
+
export interface Mapper<T> {
|
|
5
|
+
MAPPER_ID?: number;
|
|
6
|
+
id: number;
|
|
7
|
+
inputs: MutableValue<T>[];
|
|
8
|
+
outputs: MutableValue<T>[];
|
|
9
|
+
mapper: () => void;
|
|
10
|
+
dirty: boolean;
|
|
11
|
+
execute(): void;
|
|
12
|
+
extractMutablesFromArray<T>(
|
|
13
|
+
array: NestedObjectValues<MutableValue<T>>
|
|
14
|
+
): MutableValue<T>[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface MapperRegistry<T> {
|
|
18
|
+
sortedMappers: Mapper<T>[];
|
|
19
|
+
mappers: Map<number, Mapper<T>>;
|
|
20
|
+
_module: JSReanimated;
|
|
21
|
+
updatedSinceLastExecute: boolean;
|
|
22
|
+
startMapper(mapper: Mapper<T>): number;
|
|
23
|
+
stopMapper(id: number): void;
|
|
24
|
+
execute(): void;
|
|
25
|
+
updateOrder(): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface JSReanimated {
|
|
29
|
+
_valueSetter?: <T>(value: T) => void;
|
|
30
|
+
_renderRequested: boolean;
|
|
31
|
+
_mapperRegistry: MapperRegistry<any>;
|
|
32
|
+
_frames: ((timestamp: Timestamp) => void)[];
|
|
33
|
+
timeProvider: { now: () => number };
|
|
34
|
+
pushFrame(frame: (timestamp: Timestamp) => void): void;
|
|
35
|
+
getTimestamp(): number;
|
|
36
|
+
maybeRequestRender(): void;
|
|
37
|
+
_onRender(timestampMs: number): void;
|
|
38
|
+
installCoreFunctions(valueSetter: <T>(value: T) => void): void;
|
|
39
|
+
makeShareable<T>(value: T): T;
|
|
40
|
+
makeMutable<T>(value: T): MutableValue<T>;
|
|
41
|
+
makeRemote<T>(object: Record<string, any>): T;
|
|
42
|
+
startMapper(
|
|
43
|
+
mapper: () => void,
|
|
44
|
+
inputs: NestedObjectValues<MutableValue<unknown>>[],
|
|
45
|
+
outputs: NestedObjectValues<MutableValue<unknown>>[]
|
|
46
|
+
): number;
|
|
47
|
+
stopMapper(mapperId: number): void;
|
|
48
|
+
registerEventHandler<T>(_: string, __: (event: T) => void): string;
|
|
49
|
+
unregisterEventHandler(_: string): void;
|
|
50
|
+
enableLayoutAnimations(): void;
|
|
51
|
+
}
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
} from './commonTypes';
|
|
7
7
|
import { EasingFn } from '../../Easing';
|
|
8
8
|
import { BaseAnimationBuilder } from './BaseAnimationBuilder';
|
|
9
|
+
import { StyleProps } from '../../commonTypes';
|
|
10
|
+
|
|
9
11
|
export class ComplexAnimationBuilder extends BaseAnimationBuilder {
|
|
10
12
|
easingV?: EasingFn;
|
|
11
13
|
rotateV?: string;
|
|
@@ -16,6 +18,7 @@ export class ComplexAnimationBuilder extends BaseAnimationBuilder {
|
|
|
16
18
|
overshootClampingV?: number;
|
|
17
19
|
restDisplacementThresholdV?: number;
|
|
18
20
|
restSpeedThresholdV?: number;
|
|
21
|
+
initialValues?: StyleProps;
|
|
19
22
|
|
|
20
23
|
static createInstance: () => ComplexAnimationBuilder;
|
|
21
24
|
|
|
@@ -115,6 +118,16 @@ export class ComplexAnimationBuilder extends BaseAnimationBuilder {
|
|
|
115
118
|
return this;
|
|
116
119
|
}
|
|
117
120
|
|
|
121
|
+
static withInitialValues(values: StyleProps): BaseAnimationBuilder {
|
|
122
|
+
const instance = this.createInstance();
|
|
123
|
+
return instance.withInitialValues(values);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
withInitialValues(values: StyleProps): BaseAnimationBuilder {
|
|
127
|
+
this.initialValues = values;
|
|
128
|
+
return this;
|
|
129
|
+
}
|
|
130
|
+
|
|
118
131
|
getAnimationAndConfig(): LayoutAnimationAndConfig {
|
|
119
132
|
const duration = this.durationV;
|
|
120
133
|
const easing = this.easingV;
|
|
@@ -74,9 +74,8 @@ export class Keyframe implements IEntryExitAnimationBuilder {
|
|
|
74
74
|
if (styleProp === 'transform') {
|
|
75
75
|
initialValues[styleProp]?.forEach((transformStyle, index) => {
|
|
76
76
|
Object.keys(transformStyle).forEach((transformProp: string) => {
|
|
77
|
-
parsedKeyframes[
|
|
78
|
-
|
|
79
|
-
] = [];
|
|
77
|
+
parsedKeyframes[index.toString() + '_transform:' + transformProp] =
|
|
78
|
+
[];
|
|
80
79
|
});
|
|
81
80
|
});
|
|
82
81
|
} else {
|