react-native-reanimated 2.3.0-beta.4 → 2.4.1

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.
Files changed (109) hide show
  1. package/Common/cpp/Tools/RuntimeDecorator.cpp +17 -0
  2. package/LICENSE +1 -1
  3. package/README.md +1 -1
  4. package/android/build.gradle +5 -3
  5. package/android/expo/linking.gradle +46 -0
  6. package/android/expo/src/main/java/com/swmansion/reanimated/EXReanimatedAdapter.java +12 -0
  7. package/android/expo/src/main/java/expo/modules/adapters/reanimated/EXReanimatedPackage.java +26 -0
  8. package/android/react-native-reanimated-63-hermes.aar +0 -0
  9. package/android/react-native-reanimated-63-jsc.aar +0 -0
  10. package/android/react-native-reanimated-64-hermes.aar +0 -0
  11. package/android/react-native-reanimated-64-jsc.aar +0 -0
  12. package/android/react-native-reanimated-65-hermes.aar +0 -0
  13. package/android/react-native-reanimated-65-jsc.aar +0 -0
  14. package/android/react-native-reanimated-66-hermes.aar +0 -0
  15. package/android/react-native-reanimated-66-jsc.aar +0 -0
  16. package/android/react-native-reanimated-67-hermes.aar +0 -0
  17. package/android/react-native-reanimated-67-jsc.aar +0 -0
  18. package/expo-module.config.json +3 -0
  19. package/ios/LayoutReanimation/REAAnimationsManager.h +1 -1
  20. package/ios/LayoutReanimation/REAAnimationsManager.m +68 -19
  21. package/ios/LayoutReanimation/REAUIManager.mm +8 -7
  22. package/ios/Nodes/REAPropsNode.m +1 -1
  23. package/ios/native/NativeMethods.h +1 -1
  24. package/ios/native/NativeProxy.mm +10 -2
  25. package/ios/native/REAInitializer.mm +3 -4
  26. package/lib/Animated.js +3 -5
  27. package/lib/createAnimatedComponent.js +4 -2
  28. package/lib/index.js +3 -5
  29. package/lib/reanimated1/core/Core.test.js +1 -1
  30. package/lib/reanimated2/Colors.js +1 -97
  31. package/lib/reanimated2/Easing.js +5 -0
  32. package/lib/reanimated2/NativeMethods.js +15 -5
  33. package/lib/reanimated2/NativeReanimated/index.js +2 -2
  34. package/lib/reanimated2/component/FlatList.js +30 -0
  35. package/lib/reanimated2/component/WrappedComponents.js +9 -0
  36. package/lib/reanimated2/component/index.js +4 -0
  37. package/lib/reanimated2/core.js +9 -3
  38. package/lib/reanimated2/globals.d.ts +3 -0
  39. package/lib/reanimated2/hook/useAnimatedGestureHandler.js +1 -2
  40. package/lib/reanimated2/hook/useAnimatedStyle.js +31 -14
  41. package/lib/reanimated2/hook/utils.js +14 -11
  42. package/lib/reanimated2/index.js +2 -0
  43. package/lib/reanimated2/interpolateColor.js +98 -0
  44. package/lib/reanimated2/js-reanimated/JSReanimated.js +1 -1
  45. package/lib/reanimated2/js-reanimated/commonTypes.js +1 -0
  46. package/lib/reanimated2/layoutReanimation/defaultAnimations/Default.js +14 -14
  47. package/lib/reanimated2/layoutReanimation/defaultAnimations/Flip.js +8 -8
  48. package/lib/reanimated2/layoutReanimation/defaultAnimations/Rotate.js +16 -16
  49. package/lib/reanimated2/layoutReanimation/defaultAnimations/Slide.js +15 -15
  50. package/lib/reanimated2/layoutReanimation/defaultAnimations/Zoom.js +4 -4
  51. package/lib/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.js +20 -8
  52. package/lib/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.js +2 -2
  53. package/lib/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.js +8 -8
  54. package/lib/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.js +10 -10
  55. package/lib/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.js +8 -8
  56. package/lib/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.js +8 -8
  57. package/mock.js +2 -0
  58. package/package.json +8 -5
  59. package/plugin.js +3 -1
  60. package/react-native-reanimated.d.ts +101 -27
  61. package/src/Animated.js +3 -5
  62. package/src/createAnimatedComponent.tsx +13 -5
  63. package/src/reanimated1/core/Core.test.js +1 -1
  64. package/src/reanimated2/Colors.ts +6 -150
  65. package/src/reanimated2/Easing.ts +11 -0
  66. package/src/reanimated2/NativeMethods.ts +19 -6
  67. package/src/reanimated2/NativeReanimated/NativeReanimated.ts +1 -0
  68. package/src/reanimated2/NativeReanimated/index.ts +2 -2
  69. package/src/reanimated2/animation/commonTypes.ts +44 -40
  70. package/src/reanimated2/animation/decay.ts +1 -1
  71. package/src/reanimated2/animation/delay.ts +2 -16
  72. package/src/reanimated2/animation/index.ts +7 -8
  73. package/src/reanimated2/animation/repeat.ts +2 -12
  74. package/src/reanimated2/animation/sequence.ts +3 -10
  75. package/src/reanimated2/animation/spring.ts +1 -1
  76. package/src/reanimated2/animation/styleAnimation.ts +1 -18
  77. package/src/reanimated2/animation/timing.ts +1 -1
  78. package/src/reanimated2/animation/util.ts +12 -9
  79. package/src/reanimated2/commonTypes.ts +48 -1
  80. package/src/reanimated2/component/FlatList.tsx +44 -0
  81. package/src/reanimated2/component/WrappedComponents.ts +11 -0
  82. package/src/reanimated2/component/index.ts +9 -0
  83. package/src/reanimated2/core.ts +10 -6
  84. package/src/reanimated2/globals.d.ts +3 -0
  85. package/src/reanimated2/hook/commonTypes.ts +5 -0
  86. package/src/reanimated2/hook/useAnimatedGestureHandler.ts +1 -2
  87. package/src/reanimated2/hook/useAnimatedRef.ts +1 -5
  88. package/src/reanimated2/hook/useAnimatedStyle.ts +35 -16
  89. package/src/reanimated2/hook/utils.ts +18 -17
  90. package/src/reanimated2/index.ts +2 -0
  91. package/src/reanimated2/interpolateColor.ts +178 -0
  92. package/src/reanimated2/js-reanimated/JSReanimated.ts +3 -4
  93. package/src/reanimated2/js-reanimated/Mapper.ts +1 -1
  94. package/src/reanimated2/js-reanimated/MapperRegistry.ts +1 -1
  95. package/src/reanimated2/js-reanimated/commonTypes.ts +51 -0
  96. package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +39 -20
  97. package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +5 -1
  98. package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +21 -15
  99. package/src/reanimated2/layoutReanimation/defaultAnimations/Flip.ts +29 -24
  100. package/src/reanimated2/layoutReanimation/defaultAnimations/Rotate.ts +61 -34
  101. package/src/reanimated2/layoutReanimation/defaultAnimations/Slide.ts +48 -33
  102. package/src/reanimated2/layoutReanimation/defaultAnimations/Zoom.ts +17 -12
  103. package/src/reanimated2/layoutReanimation/defaultTransitions/CurvedTransition.ts +20 -8
  104. package/src/reanimated2/layoutReanimation/defaultTransitions/EntryExitTransition.ts +14 -10
  105. package/src/reanimated2/layoutReanimation/defaultTransitions/FadingTransition.ts +8 -8
  106. package/src/reanimated2/layoutReanimation/defaultTransitions/JumpingTransition.ts +20 -14
  107. package/src/reanimated2/layoutReanimation/defaultTransitions/LinearTransition.ts +14 -8
  108. package/src/reanimated2/layoutReanimation/defaultTransitions/SequencedTransition.ts +24 -12
  109. package/src/reanimated2/utils.ts +1 -1
@@ -149,6 +149,10 @@ function bezier(x1, y1, x2, y2) {
149
149
  },
150
150
  };
151
151
  }
152
+ function bezierFn(x1, y1, x2, y2) {
153
+ 'worklet';
154
+ return Bezier(x1, y1, x2, y2);
155
+ }
152
156
  /**
153
157
  * Runs an easing function forwards.
154
158
  */
@@ -194,6 +198,7 @@ const EasingObject = {
194
198
  back,
195
199
  bounce,
196
200
  bezier,
201
+ bezierFn,
197
202
  in: in_,
198
203
  out,
199
204
  inOut,
@@ -1,12 +1,21 @@
1
1
  import { findNodeHandle } from 'react-native';
2
- import { isChromeDebugger } from './PlatformChecker';
2
+ import { shouldBeUseWeb } from './PlatformChecker';
3
3
  export function getTag(view) {
4
4
  return findNodeHandle(view);
5
5
  }
6
+ const isNativeIndefined = shouldBeUseWeb();
6
7
  export function measure(animatedRef) {
7
8
  'worklet';
8
- if (!_WORKLET && !isChromeDebugger()) {
9
- throw new Error('(measure) method cannot be used on RN side!');
9
+ if (!_WORKLET || isNativeIndefined) {
10
+ console.warn('[reanimated.measure] method cannot be used for web or Chrome Debugger');
11
+ return {
12
+ x: NaN,
13
+ y: NaN,
14
+ width: NaN,
15
+ height: NaN,
16
+ pageX: NaN,
17
+ pageY: NaN,
18
+ };
10
19
  }
11
20
  const viewTag = animatedRef();
12
21
  const result = _measure(viewTag);
@@ -17,7 +26,7 @@ export function measure(animatedRef) {
17
26
  }
18
27
  export function scrollTo(animatedRef, x, y, animated) {
19
28
  'worklet';
20
- if (!_WORKLET && !isChromeDebugger()) {
29
+ if (!_WORKLET || isNativeIndefined) {
21
30
  return;
22
31
  }
23
32
  const viewTag = animatedRef();
@@ -25,8 +34,9 @@ export function scrollTo(animatedRef, x, y, animated) {
25
34
  }
26
35
  export function setGestureState(handlerTag, newState) {
27
36
  'worklet';
28
- if (!_WORKLET && !isChromeDebugger()) {
37
+ if (!_WORKLET || isNativeIndefined) {
29
38
  console.warn('[Reanimated] You can not use setGestureState in non-worklet function.');
39
+ return;
30
40
  }
31
41
  _setGestureState(handlerTag, newState);
32
42
  }
@@ -1,9 +1,9 @@
1
1
  import reanimatedJS from '../js-reanimated';
2
- import { nativeShouldBeMock } from '../PlatformChecker';
2
+ import { shouldBeUseWeb } from '../PlatformChecker';
3
3
  import { Platform } from 'react-native';
4
4
  import { NativeReanimated } from './NativeReanimated';
5
5
  let exportedModule;
6
- if (nativeShouldBeMock()) {
6
+ if (shouldBeUseWeb()) {
7
7
  exportedModule = reanimatedJS;
8
8
  }
9
9
  else {
@@ -0,0 +1,30 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React from 'react';
13
+ import { FlatList } from 'react-native';
14
+ import WrappedComponents from './WrappedComponents';
15
+ import createAnimatedComponent from '../../createAnimatedComponent';
16
+ const AnimatedFlatList = createAnimatedComponent(FlatList);
17
+ const createCellRenderer = (itemLayoutAnimation) => {
18
+ const cellRenderer = (props) => {
19
+ return (<WrappedComponents.View layout={itemLayoutAnimation} onLayout={props.onLayout}>
20
+ {props.children}
21
+ </WrappedComponents.View>);
22
+ };
23
+ return cellRenderer;
24
+ };
25
+ const ReanimatedFlatlist = (_a) => {
26
+ var { itemLayoutAnimation } = _a, restProps = __rest(_a, ["itemLayoutAnimation"]);
27
+ const cellRenderer = React.useMemo(() => createCellRenderer(itemLayoutAnimation), []);
28
+ return (<AnimatedFlatList {...restProps} CellRendererComponent={cellRenderer}/>);
29
+ };
30
+ export default ReanimatedFlatlist;
@@ -0,0 +1,9 @@
1
+ import { Image, ScrollView, Text, View } from 'react-native';
2
+ import createAnimatedComponent from '../../createAnimatedComponent';
3
+ const WrappedComponents = {
4
+ View: createAnimatedComponent(View),
5
+ Text: createAnimatedComponent(Text),
6
+ Image: createAnimatedComponent(Image),
7
+ ScrollView: createAnimatedComponent(ScrollView),
8
+ };
9
+ export default WrappedComponents;
@@ -0,0 +1,4 @@
1
+ import ReanimatedFlatlist from './FlatList';
2
+ import WrappedComponents from './WrappedComponents';
3
+ const ReanimatedComponents = Object.assign(Object.assign({}, WrappedComponents), { FlatList: ReanimatedFlatlist });
4
+ export default ReanimatedComponents;
@@ -1,7 +1,7 @@
1
1
  /* global _WORKLET _getCurrentTime _frameTimestamp _eventTimestamp, _setGlobalConsole */
2
2
  import NativeReanimatedModule from './NativeReanimated';
3
3
  import { Platform } from 'react-native';
4
- import { nativeShouldBeMock, shouldBeUseWeb } from './PlatformChecker';
4
+ import { nativeShouldBeMock, shouldBeUseWeb, isWeb } from './PlatformChecker';
5
5
  global.__reanimatedWorkletInit = function (worklet) {
6
6
  worklet.__worklet = true;
7
7
  };
@@ -263,8 +263,8 @@ if (!NativeReanimatedModule.useOnlyV1) {
263
263
  NativeReanimatedModule.installCoreFunctions(NativeReanimatedModule.native
264
264
  ? workletValueSetter
265
265
  : workletValueSetterJS);
266
- const capturableConsole = console;
267
- isConfigured() &&
266
+ if (!isWeb() && isConfigured()) {
267
+ const capturableConsole = console;
268
268
  runOnUI(() => {
269
269
  'worklet';
270
270
  const console = {
@@ -275,7 +275,13 @@ if (!NativeReanimatedModule.useOnlyV1) {
275
275
  info: runOnJS(capturableConsole.info),
276
276
  };
277
277
  _setGlobalConsole(console);
278
+ if (global.performance == null) {
279
+ global.performance = {
280
+ now: global._chronoNow,
281
+ };
282
+ }
278
283
  })();
284
+ }
279
285
  }
280
286
  let featuresConfig = {
281
287
  enableLayoutAnimations: false,
@@ -26,6 +26,7 @@ declare global {
26
26
  y: number,
27
27
  animated: boolean
28
28
  ) => void;
29
+ const _chronoNow: () => number;
29
30
  namespace NodeJS {
30
31
  interface Global {
31
32
  __reanimatedWorkletInit: (worklet: WorkletFunction) => void;
@@ -37,6 +38,8 @@ declare global {
37
38
  _frameTimestamp: number | null;
38
39
  _measure: () => MeasuredDimensions;
39
40
  _scrollTo: () => void;
41
+ _chronoNow: () => number;
42
+ performance: { now: () => number };
40
43
  LayoutAnimationRepository: {
41
44
  configs: Record<string, unknown>;
42
45
  registerConfig(tag: number, config: Record<string, unknown>): void;
@@ -1,4 +1,3 @@
1
- import { isWeb } from '../PlatformChecker';
2
1
  import { useEvent, useHandler } from './Hooks';
3
2
  export var EventType;
4
3
  (function (EventType) {
@@ -43,7 +42,7 @@ export function useAnimatedGestureHandler(handlers, dependencies) {
43
42
  handlers.onFinish(event, context, event.state === EventType.CANCELLED || event.state === EventType.FAILED);
44
43
  }
45
44
  };
46
- if (isWeb()) {
45
+ if (useWeb) {
47
46
  return handler;
48
47
  }
49
48
  return useEvent(handler, ['onGestureHandlerStateChange', 'onGestureHandlerEvent'], doDependenciesDiffer);
@@ -164,7 +164,11 @@ function styleUpdater(viewDescriptors, updater, state, maybeViewRef, animationsA
164
164
  else {
165
165
  state.isAnimationCancelled = true;
166
166
  state.animations = [];
167
- updateProps(viewDescriptors, newValues, maybeViewRef);
167
+ const diff = styleDiff(oldValues, newValues);
168
+ state.last = Object.assign({}, oldValues, newValues);
169
+ if (diff) {
170
+ updateProps(viewDescriptors, newValues, maybeViewRef);
171
+ }
168
172
  }
169
173
  }
170
174
  function jestStyleUpdater(viewDescriptors, updater, state, maybeViewRef, animationsActive, animatedStyle, adapters = []) {
@@ -305,10 +309,10 @@ export function useAnimatedStyle(updater, dependencies, adapters) {
305
309
  const maybeViewRef = NativeReanimatedModule.native ? undefined : viewsRef;
306
310
  useEffect(() => {
307
311
  let fun;
308
- let upadterFn = updater;
312
+ let updaterFn = updater;
309
313
  let optimalization = updater.__optimalization;
310
314
  if (adapters) {
311
- upadterFn = () => {
315
+ updaterFn = () => {
312
316
  'worklet';
313
317
  const newValues = updater();
314
318
  adaptersArray.forEach((adapter) => {
@@ -317,27 +321,40 @@ export function useAnimatedStyle(updater, dependencies, adapters) {
317
321
  return newValues;
318
322
  };
319
323
  }
320
- if (canApplyOptimalisation(upadterFn) && !shouldBeUseWeb()) {
321
- if (hasColorProps(upadterFn())) {
322
- upadterFn = () => {
324
+ if (canApplyOptimalisation(updaterFn) && !shouldBeUseWeb()) {
325
+ if (hasColorProps(updaterFn())) {
326
+ updaterFn = () => {
327
+ 'worklet';
328
+ const newValues = updaterFn();
329
+ const oldValues = remoteState.last;
330
+ const diff = styleDiff(oldValues, newValues);
331
+ remoteState.last = Object.assign({}, oldValues, newValues);
332
+ parseColors(diff);
333
+ return diff;
334
+ };
335
+ }
336
+ else {
337
+ updaterFn = () => {
323
338
  'worklet';
324
- const style = upadterFn();
325
- parseColors(style);
326
- return style;
339
+ const newValues = updaterFn();
340
+ const oldValues = remoteState.last;
341
+ const diff = styleDiff(oldValues, newValues);
342
+ remoteState.last = Object.assign({}, oldValues, newValues);
343
+ return diff;
327
344
  };
328
345
  }
329
346
  }
330
347
  else if (!shouldBeUseWeb()) {
331
348
  optimalization = 0;
332
- upadterFn = () => {
349
+ updaterFn = () => {
333
350
  'worklet';
334
- const style = upadterFn();
351
+ const style = updaterFn();
335
352
  parseColors(style);
336
353
  return style;
337
354
  };
338
355
  }
339
356
  if (typeof updater.__optimalization !== undefined) {
340
- upadterFn.__optimalization = optimalization;
357
+ updaterFn.__optimalization = optimalization;
341
358
  }
342
359
  if (isJest()) {
343
360
  fun = () => {
@@ -348,10 +365,10 @@ export function useAnimatedStyle(updater, dependencies, adapters) {
348
365
  else {
349
366
  fun = () => {
350
367
  'worklet';
351
- styleUpdater(sharableViewDescriptors, upadterFn, remoteState, maybeViewRef, animationsActive);
368
+ styleUpdater(sharableViewDescriptors, updaterFn, remoteState, maybeViewRef, animationsActive);
352
369
  };
353
370
  }
354
- const mapperId = startMapper(fun, inputs, [], upadterFn,
371
+ const mapperId = startMapper(fun, inputs, [], updaterFn,
355
372
  // TODO fix this
356
373
  sharableViewDescriptors);
357
374
  return () => {
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useRef } from 'react';
2
2
  import { processColor } from '../Colors';
3
3
  import { makeRemote } from '../core';
4
- import { isWeb } from '../PlatformChecker';
4
+ import { isWeb, isJest } from '../PlatformChecker';
5
5
  import { colorProps } from '../UpdateProps';
6
6
  import WorkletEventHandler from '../WorkletEventHandler';
7
7
  export function useEvent(handler, eventNames = [], rebuild = false) {
@@ -36,7 +36,7 @@ export function useHandler(handlers, dependencies) {
36
36
  dependencies = buildDependencies(dependencies, handlers);
37
37
  const doDependenciesDiffer = !areDependenciesEqual(dependencies, savedDependencies);
38
38
  initRef.current.savedDependencies = dependencies;
39
- const useWeb = isWeb();
39
+ const useWeb = isWeb() || isJest();
40
40
  return { context, doDependenciesDiffer, useWeb };
41
41
  }
42
42
  // builds one big hash from multiple worklets' hashes
@@ -95,7 +95,12 @@ export function parseColors(updates) {
95
95
  'worklet';
96
96
  for (const key in updates) {
97
97
  if (colorProps.indexOf(key) !== -1) {
98
- updates[key] = processColor(updates[key]);
98
+ // value could be an animation in which case processColor will recognize it and will return undefined
99
+ // -> in such a case we don't want to override style of that key
100
+ const processedColor = processColor(updates[key]);
101
+ if (processedColor !== undefined) {
102
+ updates[key] = processedColor;
103
+ }
99
104
  }
100
105
  }
101
106
  }
@@ -132,24 +137,22 @@ export function isAnimated(prop) {
132
137
  export function styleDiff(oldStyle, newStyle) {
133
138
  'worklet';
134
139
  const diff = {};
135
- Object.keys(oldStyle).forEach((key) => {
140
+ for (const key in oldStyle) {
136
141
  if (newStyle[key] === undefined) {
137
142
  diff[key] = null;
138
143
  }
139
- });
140
- Object.keys(newStyle).forEach((key) => {
144
+ }
145
+ for (const key in newStyle) {
141
146
  const value = newStyle[key];
142
147
  const oldValue = oldStyle[key];
143
148
  if (isAnimated(value)) {
144
149
  // do nothing
145
- return;
150
+ continue;
146
151
  }
147
- if (oldValue !== value &&
148
- JSON.stringify(oldValue) !== JSON.stringify(value)) {
149
- // I'd use deep equal here but that'd take additional work and this was easier
152
+ if (oldValue !== value) {
150
153
  diff[key] = value;
151
154
  }
152
- });
155
+ }
153
156
  return diff;
154
157
  }
155
158
  export function getStyleWithoutAnimations(newStyle) {
@@ -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,98 @@
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) => {
8
+ 'worklet';
9
+ const h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);
10
+ const s = interpolate(value, inputRange, colors.s, Extrapolate.CLAMP);
11
+ const v = interpolate(value, inputRange, colors.v, Extrapolate.CLAMP);
12
+ return hsvToColor(h, s, v);
13
+ };
14
+ const interpolateColorsRGB = (value, inputRange, colors) => {
15
+ 'worklet';
16
+ const r = interpolate(value, inputRange, colors.r, Extrapolate.CLAMP);
17
+ const g = interpolate(value, inputRange, colors.g, Extrapolate.CLAMP);
18
+ const b = interpolate(value, inputRange, colors.b, Extrapolate.CLAMP);
19
+ const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);
20
+ return rgbaColor(r, g, b, a);
21
+ };
22
+ const getInterpolateRGB = (colors) => {
23
+ 'worklet';
24
+ const r = [];
25
+ const g = [];
26
+ const b = [];
27
+ const a = [];
28
+ for (let i = 0; i < colors.length; ++i) {
29
+ const color = colors[i];
30
+ const proocessedColor = processColor(color);
31
+ // explicit check in case if processedColor is 0
32
+ if (proocessedColor !== null && proocessedColor !== undefined) {
33
+ r.push(red(proocessedColor));
34
+ g.push(green(proocessedColor));
35
+ b.push(blue(proocessedColor));
36
+ a.push(opacity(proocessedColor));
37
+ }
38
+ }
39
+ return { r, g, b, a };
40
+ };
41
+ const getInterpolateHSV = (colors) => {
42
+ 'worklet';
43
+ const h = [];
44
+ const s = [];
45
+ const v = [];
46
+ for (let i = 0; i < colors.length; ++i) {
47
+ const color = colors[i];
48
+ const proocessedColor = RGBtoHSV(processColor(color));
49
+ if (proocessedColor) {
50
+ h.push(proocessedColor.h);
51
+ s.push(proocessedColor.s);
52
+ v.push(proocessedColor.v);
53
+ }
54
+ }
55
+ return { h, s, v };
56
+ };
57
+ export const interpolateColor = (value, inputRange, outputRange, colorSpace = 'RGB') => {
58
+ 'worklet';
59
+ if (colorSpace === 'HSV') {
60
+ return interpolateColorsHSV(value, inputRange, getInterpolateHSV(outputRange));
61
+ }
62
+ else if (colorSpace === 'RGB') {
63
+ return interpolateColorsRGB(value, inputRange, getInterpolateRGB(outputRange));
64
+ }
65
+ throw new Error(`Invalid color space provided: ${colorSpace}. Supported values are: ['RGB', 'HSV']`);
66
+ };
67
+ export var ColorSpace;
68
+ (function (ColorSpace) {
69
+ ColorSpace[ColorSpace["RGB"] = 0] = "RGB";
70
+ ColorSpace[ColorSpace["HSV"] = 1] = "HSV";
71
+ })(ColorSpace || (ColorSpace = {}));
72
+ export function useInterpolateConfig(inputRange, outputRange, colorSpace = ColorSpace.RGB) {
73
+ return useSharedValue({
74
+ inputRange,
75
+ outputRange,
76
+ colorSpace,
77
+ cache: makeMutable(null),
78
+ });
79
+ }
80
+ export const interpolateSharableColor = (value, interpolateConfig) => {
81
+ 'worklet';
82
+ let colors = interpolateConfig.value.cache.value;
83
+ if (interpolateConfig.value.colorSpace === ColorSpace.RGB) {
84
+ if (!colors) {
85
+ colors = getInterpolateRGB(interpolateConfig.value.outputRange);
86
+ interpolateConfig.value.cache.value = colors;
87
+ }
88
+ return interpolateColorsRGB(value, interpolateConfig.value.inputRange, colors);
89
+ }
90
+ else if (interpolateConfig.value.colorSpace === ColorSpace.HSV) {
91
+ if (!colors) {
92
+ colors = getInterpolateHSV(interpolateConfig.value.outputRange);
93
+ interpolateConfig.value.cache.value = colors;
94
+ }
95
+ return interpolateColorsHSV(value, interpolateConfig.value.inputRange, colors);
96
+ }
97
+ throw new Error(`Invalid color space provided: ${interpolateConfig.value.colorSpace}. Supported values are: ['RGB', 'HSV']`);
98
+ };
@@ -1,6 +1,6 @@
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
5
  export default class JSReanimated extends NativeReanimated {
6
6
  constructor() {
@@ -0,0 +1 @@
1
+ export {};
@@ -2,34 +2,34 @@ export const DefaultLayout = (values) => {
2
2
  'worklet';
3
3
  return {
4
4
  initialValues: {
5
- originX: values.originX,
6
- originY: values.originY,
7
- width: values.width,
8
- height: values.height,
5
+ originX: values.targetOriginX,
6
+ originY: values.targetOriginY,
7
+ width: values.targetWidth,
8
+ height: values.targetHeight,
9
9
  },
10
10
  animations: {},
11
11
  };
12
12
  };
13
- export const DefaultEntering = (targetValues) => {
13
+ export const DefaultEntering = (values) => {
14
14
  'worklet';
15
15
  return {
16
16
  initialValues: {
17
- originX: targetValues.originX,
18
- originY: targetValues.originY,
19
- width: targetValues.width,
20
- height: targetValues.height,
17
+ originX: values.targetOriginX,
18
+ originY: values.targetOriginY,
19
+ width: values.targetWidth,
20
+ height: values.targetHeight,
21
21
  },
22
22
  animations: {},
23
23
  };
24
24
  };
25
- export const DefaultExiting = (startValues) => {
25
+ export const DefaultExiting = (values) => {
26
26
  'worklet';
27
27
  return {
28
28
  initialValues: {
29
- originX: startValues.originX,
30
- originY: startValues.originY,
31
- width: startValues.width,
32
- height: startValues.height,
29
+ originX: values.currentOriginX,
30
+ originY: values.currentOriginY,
31
+ width: values.currentWidth,
32
+ height: values.currentHeight,
33
33
  },
34
34
  animations: {},
35
35
  };
@@ -14,7 +14,7 @@ export class FlipInXUp extends ComplexAnimationBuilder {
14
14
  transform: [
15
15
  { perspective: 500 },
16
16
  { rotateX: '90deg' },
17
- { translateY: -targetValues.height },
17
+ { translateY: -targetValues.targetHeight },
18
18
  ],
19
19
  },
20
20
  animations: {
@@ -48,7 +48,7 @@ export class FlipInYLeft extends ComplexAnimationBuilder {
48
48
  transform: [
49
49
  { perspective: 500 },
50
50
  { rotateY: '-90deg' },
51
- { translateX: -targetValues.width },
51
+ { translateX: -targetValues.targetWidth },
52
52
  ],
53
53
  },
54
54
  animations: {
@@ -82,7 +82,7 @@ export class FlipInXDown extends ComplexAnimationBuilder {
82
82
  transform: [
83
83
  { perspective: 500 },
84
84
  { rotateX: '-90deg' },
85
- { translateY: targetValues.height },
85
+ { translateY: targetValues.targetHeight },
86
86
  ],
87
87
  },
88
88
  animations: {
@@ -116,7 +116,7 @@ export class FlipInYRight extends ComplexAnimationBuilder {
116
116
  transform: [
117
117
  { perspective: 500 },
118
118
  { rotateY: '90deg' },
119
- { translateX: targetValues.width },
119
+ { translateX: targetValues.targetWidth },
120
120
  ],
121
121
  },
122
122
  animations: {
@@ -216,7 +216,7 @@ export class FlipOutXUp extends ComplexAnimationBuilder {
216
216
  { perspective: delayFunction(delay, animation(500, config)) },
217
217
  { rotateX: delayFunction(delay, animation('90deg', config)) },
218
218
  {
219
- translateY: delayFunction(delay, animation(-targetValues.height, config)),
219
+ translateY: delayFunction(delay, animation(-targetValues.currentHeight, config)),
220
220
  },
221
221
  ],
222
222
  },
@@ -252,7 +252,7 @@ export class FlipOutYLeft extends ComplexAnimationBuilder {
252
252
  { perspective: delayFunction(delay, animation(500, config)) },
253
253
  { rotateY: delayFunction(delay, animation('-90deg', config)) },
254
254
  {
255
- translateX: delayFunction(delay, animation(-targetValues.width, config)),
255
+ translateX: delayFunction(delay, animation(-targetValues.currentWidth, config)),
256
256
  },
257
257
  ],
258
258
  },
@@ -288,7 +288,7 @@ export class FlipOutXDown extends ComplexAnimationBuilder {
288
288
  { perspective: delayFunction(delay, animation(500, config)) },
289
289
  { rotateX: delayFunction(delay, animation('-90deg', config)) },
290
290
  {
291
- translateY: delayFunction(delay, animation(targetValues.height, config)),
291
+ translateY: delayFunction(delay, animation(targetValues.currentHeight, config)),
292
292
  },
293
293
  ],
294
294
  },
@@ -324,7 +324,7 @@ export class FlipOutYRight extends ComplexAnimationBuilder {
324
324
  { perspective: delayFunction(delay, animation(500, config)) },
325
325
  { rotateY: delayFunction(delay, animation('90deg', config)) },
326
326
  {
327
- translateX: delayFunction(delay, animation(targetValues.width, config)),
327
+ translateX: delayFunction(delay, animation(targetValues.currentWidth, config)),
328
328
  },
329
329
  ],
330
330
  },