react-native-reanimated 2.3.1 → 2.4.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/build.gradle +3 -3
- package/android/react-native-reanimated-63-hermes.aar +0 -0
- package/android/react-native-reanimated-63-jsc.aar +0 -0
- package/android/react-native-reanimated-64-hermes.aar +0 -0
- package/android/react-native-reanimated-64-jsc.aar +0 -0
- package/android/react-native-reanimated-65-hermes.aar +0 -0
- package/android/react-native-reanimated-65-jsc.aar +0 -0
- package/android/react-native-reanimated-66-hermes.aar +0 -0
- package/android/react-native-reanimated-66-jsc.aar +0 -0
- package/android/react-native-reanimated-67-hermes.aar +0 -0
- package/android/react-native-reanimated-67-jsc.aar +0 -0
- package/ios/LayoutReanimation/REAAnimationsManager.h +1 -1
- package/ios/LayoutReanimation/REAAnimationsManager.m +4 -0
- package/ios/native/NativeMethods.h +1 -1
- package/ios/native/NativeProxy.mm +10 -2
- package/lib/{Animated.js → src/Animated.js} +0 -0
- package/lib/{ConfigHelper.js → src/ConfigHelper.js} +0 -0
- package/lib/{ReanimatedEventEmitter.js → src/ReanimatedEventEmitter.js} +0 -0
- package/lib/{ReanimatedModule.js → src/ReanimatedModule.js} +0 -0
- package/lib/{ReanimatedModule.macos.js → src/ReanimatedModule.macos.js} +0 -0
- package/lib/{ReanimatedModule.native.js → src/ReanimatedModule.native.js} +0 -0
- package/lib/{ReanimatedModule.windows.js → src/ReanimatedModule.windows.js} +0 -0
- package/lib/{ReanimatedModuleCompat.js → src/ReanimatedModuleCompat.js} +0 -0
- package/lib/{__mocks__ → src/__mocks__}/ReanimatedEventEmitter.js +0 -0
- package/lib/{__mocks__ → src/__mocks__}/ReanimatedModule.native.js +0 -0
- package/lib/{createAnimatedComponent.js → src/createAnimatedComponent.js} +0 -0
- package/lib/{index.js → src/index.js} +0 -0
- package/lib/{reanimated1 → src/reanimated1}/Easing.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/SpringConfig.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/Transitioning.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/animations/Animation.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/animations/SpringUtils.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/animations/backwardCompatibleAnimWrapper.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/animations/decay.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/animations/spring.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/animations/timing.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/base.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedAlways.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedBezier.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedBlock.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedCall.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedCallFunc.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedClock.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedClockTest.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedCode.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedConcat.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedCond.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedDebug.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedEvent.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedFunction.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedNode.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedOperator.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedParam.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedProps.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedSet.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedStartClock.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedStopClock.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedStyle.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedTransform.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/AnimatedValue.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/Core.test.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/InternalAnimatedValue.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/__mocks__/AnimatedProps.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/core/createEventObjectProxyPolyfill.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/derived/__mocks__/evaluateOnce.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/derived/acc.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/derived/color.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/derived/diff.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/derived/diffClamp.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/derived/evaluateOnce.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/derived/index.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/derived/interpolate.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/derived/interpolateColors.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/derived/onChange.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/derived/useCode.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/index.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/operators.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/useValue.js +0 -0
- package/lib/{reanimated1 → src/reanimated1}/val.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/Bezier.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/Colors.js +1 -97
- package/lib/{reanimated2 → src/reanimated2}/Easing.js +5 -0
- package/lib/{reanimated2 → src/reanimated2}/NativeMethods.js +15 -5
- package/lib/{reanimated2 → src/reanimated2}/NativeReanimated/NativeReanimated.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/NativeReanimated/index.js +2 -2
- package/lib/{reanimated2 → src/reanimated2}/PlatformChecker.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/PropAdapters.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/UpdateProps.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/ViewDescriptorsSet.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/WorkletEventHandler.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/__mocks__/MutableValue.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/__mocks__/NativeReanimated.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/__mocks__/NativeReanimated.native.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/animation/commonTypes.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/animation/decay.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/animation/delay.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/animation/index.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/animation/repeat.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/animation/sequence.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/animation/spring.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/animation/styleAnimation.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/animation/timing.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/animation/util.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/commonTypes.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/component/FlatList.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/component/WrappedComponents.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/component/index.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/core.js +5 -3
- package/lib/{reanimated2 → src/reanimated2}/globals.d.ts +0 -0
- package/lib/{reanimated2 → src/reanimated2}/hook/Hooks.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/hook/commonTypes.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/hook/index.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/hook/useAnimatedGestureHandler.js +1 -2
- package/lib/{reanimated2 → src/reanimated2}/hook/useAnimatedReaction.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/hook/useAnimatedRef.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/hook/useAnimatedScrollHandler.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/hook/useAnimatedStyle.js +31 -14
- package/lib/{reanimated2 → src/reanimated2}/hook/useDerivedValue.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/hook/useSharedValue.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/hook/utils.js +14 -11
- package/lib/{reanimated2 → src/reanimated2}/index.js +2 -0
- package/lib/src/reanimated2/interpolateColor.js +98 -0
- package/lib/{reanimated2 → src/reanimated2}/interpolation.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/jestUtils.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/js-reanimated/JSReanimated.js +1 -1
- package/lib/{reanimated2 → src/reanimated2}/js-reanimated/Mapper.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/js-reanimated/MapperRegistry.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/js-reanimated/MutableValue.js +0 -0
- package/lib/{reanimated2/layoutReanimation/animationBuilder → src/reanimated2/js-reanimated}/commonTypes.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/js-reanimated/index.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/LayoutAnimationRepository.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/animationBuilder/BaseAnimationBuilder.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/animationBuilder/ComplexAnimationBuilder.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/animationBuilder/Keyframe.js +0 -0
- package/lib/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.js +1 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/animationBuilder/index.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/Bounce.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/Default.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/Fade.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/Flip.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/Lightspeed.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/Pinwheel.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/Roll.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/Rotate.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/Slide.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/Stretch.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/Zoom.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultAnimations/index.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultTransitions/CurvedTransition.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultTransitions/EntryExitTransition.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultTransitions/FadingTransition.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultTransitions/JumpingTransition.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultTransitions/LinearTransition.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultTransitions/SequencedTransition.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/defaultTransitions/index.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/layoutReanimation/index.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/mock.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/platform-specific/RNRenderer.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/platform-specific/RNRenderer.web.js +0 -0
- package/lib/{reanimated2 → src/reanimated2}/utils.js +0 -0
- package/lib/{setAndForwardRef.js → src/setAndForwardRef.js} +0 -0
- package/mock.js +1 -0
- package/package.json +5 -3
- package/plugin.js +1 -0
- package/react-native-reanimated.d.ts +55 -1
- package/src/reanimated2/Colors.ts +6 -150
- package/src/reanimated2/Easing.ts +11 -0
- package/src/reanimated2/NativeMethods.ts +19 -6
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +1 -0
- package/src/reanimated2/NativeReanimated/index.ts +2 -2
- 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 +7 -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 +1 -18
- package/src/reanimated2/animation/timing.ts +1 -1
- package/src/reanimated2/animation/util.ts +12 -9
- package/src/reanimated2/commonTypes.ts +48 -1
- package/src/reanimated2/core.ts +6 -6
- package/src/reanimated2/hook/commonTypes.ts +5 -0
- package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -2
- package/src/reanimated2/hook/useAnimatedRef.ts +1 -5
- package/src/reanimated2/hook/useAnimatedStyle.ts +35 -16
- package/src/reanimated2/hook/utils.ts +18 -17
- package/src/reanimated2/index.ts +2 -0
- package/src/reanimated2/interpolateColor.ts +178 -0
- package/src/reanimated2/js-reanimated/JSReanimated.ts +3 -4
- 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/defaultTransitions/EntryExitTransition.ts +6 -2
- package/src/reanimated2/utils.ts +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { MutableRefObject } from 'react';
|
|
2
2
|
import { WorkletFunction } from '../commonTypes';
|
|
3
|
-
import { isWeb } from '../PlatformChecker';
|
|
4
3
|
import WorkletEventHandler from '../WorkletEventHandler';
|
|
5
4
|
import { Context, DependencyList } from './commonTypes';
|
|
6
5
|
import { useEvent, useHandler } from './Hooks';
|
|
@@ -98,7 +97,7 @@ export function useAnimatedGestureHandler<
|
|
|
98
97
|
}
|
|
99
98
|
};
|
|
100
99
|
|
|
101
|
-
if (
|
|
100
|
+
if (useWeb) {
|
|
102
101
|
return handler;
|
|
103
102
|
}
|
|
104
103
|
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { Component, useRef } from 'react';
|
|
2
2
|
import { getTag } from '../NativeMethods';
|
|
3
3
|
import { useSharedValue } from './useSharedValue';
|
|
4
|
-
|
|
5
|
-
export interface RefObjectFunction<T> {
|
|
6
|
-
current: T | null;
|
|
7
|
-
(component?: T): number;
|
|
8
|
-
}
|
|
4
|
+
import { RefObjectFunction } from './commonTypes';
|
|
9
5
|
|
|
10
6
|
export function useAnimatedRef<T extends Component>(): RefObjectFunction<T> {
|
|
11
7
|
const tag = useSharedValue<number | null>(-1);
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
makeMutable,
|
|
11
11
|
} from '../core';
|
|
12
12
|
import updateProps, { updatePropsJestWrapper } from '../UpdateProps';
|
|
13
|
-
import { initialUpdaterRun
|
|
13
|
+
import { initialUpdaterRun } from '../animation';
|
|
14
14
|
import NativeReanimatedModule from '../NativeReanimated';
|
|
15
15
|
import { useSharedValue } from './useSharedValue';
|
|
16
16
|
import {
|
|
@@ -31,11 +31,13 @@ import {
|
|
|
31
31
|
ViewRefSet,
|
|
32
32
|
} from '../ViewDescriptorsSet';
|
|
33
33
|
import { isJest, shouldBeUseWeb } from '../PlatformChecker';
|
|
34
|
-
import { AnimationObject } from '../animation/commonTypes';
|
|
35
34
|
import {
|
|
35
|
+
AnimationObject,
|
|
36
|
+
Timestamp,
|
|
36
37
|
AdapterWorkletFunction,
|
|
37
38
|
AnimatedStyle,
|
|
38
39
|
BasicWorkletFunction,
|
|
40
|
+
BasicWorkletFunctionOptional,
|
|
39
41
|
NestedObjectValues,
|
|
40
42
|
SharedValue,
|
|
41
43
|
} from '../commonTypes';
|
|
@@ -259,7 +261,12 @@ function styleUpdater(
|
|
|
259
261
|
} else {
|
|
260
262
|
state.isAnimationCancelled = true;
|
|
261
263
|
state.animations = [];
|
|
262
|
-
|
|
264
|
+
|
|
265
|
+
const diff = styleDiff(oldValues, newValues);
|
|
266
|
+
state.last = Object.assign({}, oldValues, newValues);
|
|
267
|
+
if (diff) {
|
|
268
|
+
updateProps(viewDescriptors, newValues, maybeViewRef);
|
|
269
|
+
}
|
|
263
270
|
}
|
|
264
271
|
}
|
|
265
272
|
|
|
@@ -446,10 +453,10 @@ export function useAnimatedStyle<T extends AnimatedStyle>(
|
|
|
446
453
|
|
|
447
454
|
useEffect(() => {
|
|
448
455
|
let fun;
|
|
449
|
-
let
|
|
456
|
+
let updaterFn = updater as BasicWorkletFunctionOptional<T>;
|
|
450
457
|
let optimalization = updater.__optimalization;
|
|
451
458
|
if (adapters) {
|
|
452
|
-
|
|
459
|
+
updaterFn = () => {
|
|
453
460
|
'worklet';
|
|
454
461
|
const newValues = updater();
|
|
455
462
|
adaptersArray.forEach((adapter) => {
|
|
@@ -459,26 +466,38 @@ export function useAnimatedStyle<T extends AnimatedStyle>(
|
|
|
459
466
|
};
|
|
460
467
|
}
|
|
461
468
|
|
|
462
|
-
if (canApplyOptimalisation(
|
|
463
|
-
if (hasColorProps(
|
|
464
|
-
|
|
469
|
+
if (canApplyOptimalisation(updaterFn) && !shouldBeUseWeb()) {
|
|
470
|
+
if (hasColorProps(updaterFn())) {
|
|
471
|
+
updaterFn = () => {
|
|
472
|
+
'worklet';
|
|
473
|
+
const newValues = updaterFn();
|
|
474
|
+
const oldValues = remoteState.last;
|
|
475
|
+
const diff = styleDiff<T>(oldValues, newValues);
|
|
476
|
+
remoteState.last = Object.assign({}, oldValues, newValues);
|
|
477
|
+
parseColors(diff);
|
|
478
|
+
return diff;
|
|
479
|
+
};
|
|
480
|
+
} else {
|
|
481
|
+
updaterFn = () => {
|
|
465
482
|
'worklet';
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
|
|
483
|
+
const newValues = updaterFn();
|
|
484
|
+
const oldValues = remoteState.last;
|
|
485
|
+
const diff = styleDiff<T>(oldValues, newValues);
|
|
486
|
+
remoteState.last = Object.assign({}, oldValues, newValues);
|
|
487
|
+
return diff;
|
|
469
488
|
};
|
|
470
489
|
}
|
|
471
490
|
} else if (!shouldBeUseWeb()) {
|
|
472
491
|
optimalization = 0;
|
|
473
|
-
|
|
492
|
+
updaterFn = () => {
|
|
474
493
|
'worklet';
|
|
475
|
-
const style =
|
|
494
|
+
const style = updaterFn();
|
|
476
495
|
parseColors(style);
|
|
477
496
|
return style;
|
|
478
497
|
};
|
|
479
498
|
}
|
|
480
499
|
if (typeof updater.__optimalization !== undefined) {
|
|
481
|
-
|
|
500
|
+
updaterFn.__optimalization = optimalization;
|
|
482
501
|
}
|
|
483
502
|
|
|
484
503
|
if (isJest()) {
|
|
@@ -499,7 +518,7 @@ export function useAnimatedStyle<T extends AnimatedStyle>(
|
|
|
499
518
|
'worklet';
|
|
500
519
|
styleUpdater(
|
|
501
520
|
sharableViewDescriptors,
|
|
502
|
-
|
|
521
|
+
updaterFn,
|
|
503
522
|
remoteState,
|
|
504
523
|
maybeViewRef,
|
|
505
524
|
animationsActive
|
|
@@ -510,7 +529,7 @@ export function useAnimatedStyle<T extends AnimatedStyle>(
|
|
|
510
529
|
fun,
|
|
511
530
|
inputs,
|
|
512
531
|
[],
|
|
513
|
-
|
|
532
|
+
updaterFn,
|
|
514
533
|
// TODO fix this
|
|
515
534
|
sharableViewDescriptors
|
|
516
535
|
);
|
|
@@ -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
|
}
|
|
@@ -201,33 +206,29 @@ export function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {
|
|
|
201
206
|
return false;
|
|
202
207
|
}
|
|
203
208
|
|
|
204
|
-
export function styleDiff(
|
|
209
|
+
export function styleDiff<T extends AnimatedStyle>(
|
|
205
210
|
oldStyle: AnimatedStyle,
|
|
206
211
|
newStyle: AnimatedStyle
|
|
207
|
-
):
|
|
212
|
+
): Partial<T> {
|
|
208
213
|
'worklet';
|
|
209
|
-
const diff:
|
|
210
|
-
|
|
214
|
+
const diff: any = {};
|
|
215
|
+
for (const key in oldStyle) {
|
|
211
216
|
if (newStyle[key] === undefined) {
|
|
212
217
|
diff[key] = null;
|
|
213
218
|
}
|
|
214
|
-
}
|
|
215
|
-
|
|
219
|
+
}
|
|
220
|
+
for (const key in newStyle) {
|
|
216
221
|
const value = newStyle[key];
|
|
217
222
|
const oldValue = oldStyle[key];
|
|
218
223
|
|
|
219
224
|
if (isAnimated(value)) {
|
|
220
225
|
// do nothing
|
|
221
|
-
|
|
226
|
+
continue;
|
|
222
227
|
}
|
|
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
|
|
228
|
+
if (oldValue !== value) {
|
|
228
229
|
diff[key] = value;
|
|
229
230
|
}
|
|
230
|
-
}
|
|
231
|
+
}
|
|
231
232
|
return diff;
|
|
232
233
|
}
|
|
233
234
|
|
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
|
+
};
|
|
@@ -1,15 +1,14 @@
|
|
|
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 { NestedObjectValues } from '../commonTypes';
|
|
5
|
+
import { Timestamp, NestedObjectValues } from '../commonTypes';
|
|
7
6
|
|
|
8
7
|
export default class JSReanimated extends NativeReanimated {
|
|
9
8
|
_valueSetter?: <T>(value: T) => void = undefined;
|
|
10
9
|
|
|
11
10
|
_renderRequested = false;
|
|
12
|
-
_mapperRegistry = new MapperRegistry(this);
|
|
11
|
+
_mapperRegistry: MapperRegistry<any> = new MapperRegistry(this);
|
|
13
12
|
_frames: ((timestamp: Timestamp) => void)[] = [];
|
|
14
13
|
timeProvider: { now: () => number };
|
|
15
14
|
|
|
@@ -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
|
+
}
|
|
@@ -4,9 +4,13 @@ import {
|
|
|
4
4
|
LayoutAnimationFunction,
|
|
5
5
|
} from '../animationBuilder/commonTypes';
|
|
6
6
|
import { BaseAnimationBuilder } from '../animationBuilder';
|
|
7
|
-
import {
|
|
7
|
+
import { withSequence, withTiming } from '../../animation';
|
|
8
8
|
import { FadeIn, FadeOut } from '../defaultAnimations/Fade';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
StyleProps,
|
|
11
|
+
TransformProperty,
|
|
12
|
+
AnimationObject,
|
|
13
|
+
} from '../../commonTypes';
|
|
10
14
|
|
|
11
15
|
export class EntryExitTransition
|
|
12
16
|
extends BaseAnimationBuilder
|
package/src/reanimated2/utils.ts
CHANGED