react-native-reanimated 3.0.0 → 3.0.2

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 (42) hide show
  1. package/README.md +1 -1
  2. package/lib/commonjs/createAnimatedComponent.js +12 -0
  3. package/lib/commonjs/createAnimatedComponent.js.map +1 -1
  4. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +3 -0
  5. package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  6. package/lib/commonjs/reanimated2/initializers.js +1 -1
  7. package/lib/commonjs/reanimated2/initializers.js.map +1 -1
  8. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +5 -0
  9. package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  10. package/lib/commonjs/reanimated2/mock.js.map +1 -1
  11. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js +1 -1
  12. package/lib/commonjs/reanimated2/platform-specific/checkVersion.js.map +1 -1
  13. package/lib/commonjs/reanimated2/threads.js +10 -13
  14. package/lib/commonjs/reanimated2/threads.js.map +1 -1
  15. package/lib/commonjs/reanimated2/utils.js +1 -1
  16. package/lib/commonjs/reanimated2/utils.js.map +1 -1
  17. package/lib/module/createAnimatedComponent.js +12 -0
  18. package/lib/module/createAnimatedComponent.js.map +1 -1
  19. package/lib/module/reanimated2/hook/useAnimatedSensor.js +2 -0
  20. package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
  21. package/lib/module/reanimated2/initializers.js +1 -1
  22. package/lib/module/reanimated2/initializers.js.map +1 -1
  23. package/lib/module/reanimated2/layoutReanimation/animationsManager.js +5 -0
  24. package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -1
  25. package/lib/module/reanimated2/mock.js.map +1 -1
  26. package/lib/module/reanimated2/platform-specific/checkVersion.js +1 -1
  27. package/lib/module/reanimated2/platform-specific/checkVersion.js.map +1 -1
  28. package/lib/module/reanimated2/threads.js +10 -13
  29. package/lib/module/reanimated2/threads.js.map +1 -1
  30. package/lib/module/reanimated2/utils.js +1 -1
  31. package/lib/module/reanimated2/utils.js.map +1 -1
  32. package/mock.js +1 -211
  33. package/package.json +1 -1
  34. package/react-native-reanimated.d.ts +12 -429
  35. package/src/createAnimatedComponent.tsx +9 -0
  36. package/src/reanimated2/hook/useAnimatedSensor.ts +2 -0
  37. package/src/reanimated2/initializers.ts +1 -1
  38. package/src/reanimated2/layoutReanimation/animationsManager.ts +3 -0
  39. package/src/reanimated2/mock.ts +1 -1
  40. package/src/reanimated2/platform-specific/checkVersion.ts +1 -1
  41. package/src/reanimated2/threads.ts +10 -13
  42. package/src/reanimated2/utils.ts +1 -1
@@ -2,24 +2,25 @@ import NativeReanimatedModule from './NativeReanimated';
2
2
  import { isJest, shouldBeUseWeb } from './PlatformChecker';
3
3
  import { makeShareableCloneOnUIRecursive, makeShareableCloneRecursive } from './shareables';
4
4
  const IS_JEST = isJest();
5
+ const IS_WEB = shouldBeUseWeb();
5
6
  let _runOnUIQueue = [];
6
7
  export function setupSetImmediate() {
7
8
  'worklet';
8
9
 
9
- let immediateCalbacks = []; // @ts-ignore – typescript expects this to conform to NodeJS definition and expects the return value to be NodeJS.Immediate which is an object and not a number
10
+ let immediateCallbacks = []; // @ts-ignore – typescript expects this to conform to NodeJS definition and expects the return value to be NodeJS.Immediate which is an object and not a number
10
11
 
11
12
  global.setImmediate = callback => {
12
- immediateCalbacks.push(callback);
13
+ immediateCallbacks.push(callback);
13
14
  return -1;
14
15
  };
15
16
 
16
17
  global.__flushImmediates = () => {
17
- for (let index = 0; index < immediateCalbacks.length; index += 1) {
18
+ for (let index = 0; index < immediateCallbacks.length; index += 1) {
18
19
  // we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to setImmediate calls
19
- immediateCalbacks[index]();
20
+ immediateCallbacks[index]();
20
21
  }
21
22
 
22
- immediateCalbacks = [];
23
+ immediateCallbacks = [];
23
24
  };
24
25
  }
25
26
 
@@ -38,10 +39,8 @@ export const flushImmediates = shouldBeUseWeb() ? () => {// on web flushing is a
38
39
  */
39
40
 
40
41
  export function runOnUI(worklet) {
41
- if (__DEV__ && !shouldBeUseWeb()) {
42
- if (worklet.__workletHash === undefined) {
43
- throw new Error('runOnUI() can only be used on worklets');
44
- }
42
+ if (__DEV__ && !IS_WEB && worklet.__workletHash === undefined) {
43
+ throw new Error('runOnUI() can only be used on worklets');
45
44
  }
46
45
 
47
46
  return function () {
@@ -91,10 +90,8 @@ export function runOnUI(worklet) {
91
90
  */
92
91
 
93
92
  export function runOnUIImmediately(worklet) {
94
- if (__DEV__) {
95
- if (worklet.__workletHash === undefined) {
96
- throw new Error('runOnUI() can only be used on worklets');
97
- }
93
+ if (__DEV__ && !IS_WEB && worklet.__workletHash === undefined) {
94
+ throw new Error('runOnUI() can only be used on worklets');
98
95
  }
99
96
 
100
97
  return function () {
@@ -1 +1 @@
1
- {"version":3,"names":["NativeReanimatedModule","isJest","shouldBeUseWeb","makeShareableCloneOnUIRecursive","makeShareableCloneRecursive","IS_JEST","_runOnUIQueue","setupSetImmediate","immediateCalbacks","global","setImmediate","callback","push","__flushImmediates","index","length","flushImmediatesOnUIThread","flushImmediates","runOnUI","worklet","__DEV__","__workletHash","undefined","Error","args","scheduleOnUI","queue","forEach","runOnUIImmediately","e","runOnJS","fun","__remoteFunction","_WORKLET","_scheduleOnJS"],"sources":["threads.ts"],"sourcesContent":["import NativeReanimatedModule from './NativeReanimated';\nimport { isJest, shouldBeUseWeb } from './PlatformChecker';\nimport { ComplexWorkletFunction } from './commonTypes';\nimport {\n makeShareableCloneOnUIRecursive,\n makeShareableCloneRecursive,\n} from './shareables';\n\nconst IS_JEST = isJest();\n\nlet _runOnUIQueue: Array<[ComplexWorkletFunction<any[], any>, any[]]> = [];\n\nexport function setupSetImmediate() {\n 'worklet';\n\n let immediateCalbacks: Array<() => void> = [];\n\n // @ts-ignore – typescript expects this to conform to NodeJS definition and expects the return value to be NodeJS.Immediate which is an object and not a number\n global.setImmediate = (callback: () => void): number => {\n immediateCalbacks.push(callback);\n return -1;\n };\n\n global.__flushImmediates = () => {\n for (let index = 0; index < immediateCalbacks.length; index += 1) {\n // we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to setImmediate calls\n immediateCalbacks[index]();\n }\n immediateCalbacks = [];\n };\n}\n\nfunction flushImmediatesOnUIThread() {\n 'worklet';\n global.__flushImmediates();\n}\n\nexport const flushImmediates = shouldBeUseWeb()\n ? () => {\n // on web flushing is a noop as immediates are handled by the browser\n }\n : flushImmediatesOnUIThread;\n\n/**\n * Schedule a worklet to execute on the UI runtime. This method does not schedule the work immediately but instead\n * waits for other worklets to be scheduled within the same JS loop. It uses setImmediate to schedule all the worklets\n * at once making sure they will run within the same frame boundaries on the UI thread.\n */\nexport function runOnUI<A extends any[], R>(\n worklet: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n if (__DEV__ && !shouldBeUseWeb()) {\n if (worklet.__workletHash === undefined) {\n throw new Error('runOnUI() can only be used on worklets');\n }\n }\n return (...args) => {\n if (IS_JEST) {\n // Mocking time in Jest is tricky as both requestAnimationFrame and setImmediate\n // callbacks run on the same queue and can be interleaved. There is no way\n // to flush particular queue in Jest and the only control over mocked timers\n // is by using jest.advanceTimersByTime() method which advances all types\n // of timers including immediate and animation callbacks. Ideally we'd like\n // to have some way here to schedule work along with React updates, but\n // that's not possible, and hence in Jest environment instead of using scheduling\n // mechanism we just schedule the work ommiting the queue. This is ok for the\n // uses that we currently have but may not be ok for future tests that we write.\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n return;\n }\n _runOnUIQueue.push([worklet, args]);\n if (_runOnUIQueue.length === 1) {\n setImmediate(() => {\n const queue = _runOnUIQueue;\n _runOnUIQueue = [];\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n queue.forEach(([worklet, args]) => {\n worklet(...args);\n });\n flushImmediates();\n })\n );\n });\n }\n };\n}\n\n/**\n * Schedule a worklet to execute on the UI runtime skipping batching mechanism.\n */\nexport function runOnUIImmediately<A extends any[], R>(\n worklet: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n if (__DEV__) {\n if (worklet.__workletHash === undefined) {\n throw new Error('runOnUI() can only be used on worklets');\n }\n }\n return (...args) => {\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n };\n}\n\nif (__DEV__) {\n try {\n runOnUI(() => {\n 'worklet';\n });\n } catch (e) {\n throw new Error(\n 'Failed to create a worklet. Did you forget to add Reanimated Babel plugin in babel.config.js? See installation docs at https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation#babel-plugin.'\n );\n }\n}\n\nexport function runOnJS<A extends any[], R>(\n fun: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n 'worklet';\n if (fun.__remoteFunction) {\n // in development mode the function provided as `fun` throws an error message\n // such that when someone accidently calls it directly on the UI runtime, they\n // see that they should use `runOnJS` instead. To facilitate that we purt the\n // reference to the original remote function in the `__remoteFunction` property.\n fun = fun.__remoteFunction;\n }\n if (!_WORKLET) {\n return fun;\n }\n return (...args) => {\n _scheduleOnJS(\n fun,\n args.length > 0 ? makeShareableCloneOnUIRecursive(args) : undefined\n );\n };\n}\n"],"mappings":"AAAA,OAAOA,sBAAP,MAAmC,oBAAnC;AACA,SAASC,MAAT,EAAiBC,cAAjB,QAAuC,mBAAvC;AAEA,SACEC,+BADF,EAEEC,2BAFF,QAGO,cAHP;AAKA,MAAMC,OAAO,GAAGJ,MAAM,EAAtB;AAEA,IAAIK,aAAiE,GAAG,EAAxE;AAEA,OAAO,SAASC,iBAAT,GAA6B;EAClC;;EAEA,IAAIC,iBAAoC,GAAG,EAA3C,CAHkC,CAKlC;;EACAC,MAAM,CAACC,YAAP,GAAuBC,QAAD,IAAkC;IACtDH,iBAAiB,CAACI,IAAlB,CAAuBD,QAAvB;IAC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ApB,CAACR,OAAD,EAAUK,IAAV,CAAoB;YACjCL,OAAO,CAAC,GAAGK,IAAJ,CAAP;UACD,CAFD;UAGAP,eAAe;QAChB,CAN0B,CAD7B;MASD,CAZW,CAAZ;IAaD;EACF,CAnCD;AAoCD;AAED;AACA;AACA;;AACA,OAAO,SAASW,kBAAT,CACLT,OADK,EAEiB;EACtB,IAAIC,OAAJ,EAAa;IACX,IAAID,OAAO,CAACE,aAAR,KAA0BC,SAA9B,EAAyC;MACvC,MAAM,IAAIC,KAAJ,CAAU,wCAAV,CAAN;IACD;EACF;;EACD,OAAO,YAAa;IAAA,mCAATC,IAAS;MAATA,IAAS;IAAA;;IAClBxB,sBAAsB,CAACyB,YAAvB,CACErB,2BAA2B,CAAC,MAAM;MAChC;;MACAe,OAAO,CAAC,GAAGK,IAAJ,CAAP;IACD,CAH0B,CAD7B;EAMD,CAPD;AAQD;;AAED,IAAIJ,OAAJ,EAAa;EACX,IAAI;IACFF,OAAO,CAAC,MAAM;MACZ;IACD,CAFM,CAAP;EAGD,CAJD,CAIE,OAAOW,CAAP,EAAU;IACV,MAAM,IAAIN,KAAJ,CACJ,wNADI,CAAN;EAGD;AACF;;AAED,OAAO,SAASO,OAAT,CACLC,GADK,EAEiB;EACtB;;EACA,IAAIA,GAAG,CAACC,gBAAR,EAA0B;IACxB;IACA;IACA;IACA;IACAD,GAAG,GAAGA,GAAG,CAACC,gBAAV;EACD;;EACD,IAAI,CAACC,QAAL,EAAe;IACb,OAAOF,GAAP;EACD;;EACD,OAAO,YAAa;IAAA,mCAATP,IAAS;MAATA,IAAS;IAAA;;IAClBU,aAAa,CACXH,GADW,EAEXP,IAAI,CAACT,MAAL,GAAc,CAAd,GAAkBZ,+BAA+B,CAACqB,IAAD,CAAjD,GAA0DF,SAF/C,CAAb;EAID,CALD;AAMD"}
1
+ {"version":3,"names":["NativeReanimatedModule","isJest","shouldBeUseWeb","makeShareableCloneOnUIRecursive","makeShareableCloneRecursive","IS_JEST","IS_WEB","_runOnUIQueue","setupSetImmediate","immediateCallbacks","global","setImmediate","callback","push","__flushImmediates","index","length","flushImmediatesOnUIThread","flushImmediates","runOnUI","worklet","__DEV__","__workletHash","undefined","Error","args","scheduleOnUI","queue","forEach","runOnUIImmediately","e","runOnJS","fun","__remoteFunction","_WORKLET","_scheduleOnJS"],"sources":["threads.ts"],"sourcesContent":["import NativeReanimatedModule from './NativeReanimated';\nimport { isJest, shouldBeUseWeb } from './PlatformChecker';\nimport { ComplexWorkletFunction } from './commonTypes';\nimport {\n makeShareableCloneOnUIRecursive,\n makeShareableCloneRecursive,\n} from './shareables';\n\nconst IS_JEST = isJest();\nconst IS_WEB = shouldBeUseWeb();\n\nlet _runOnUIQueue: Array<[ComplexWorkletFunction<any[], any>, any[]]> = [];\n\nexport function setupSetImmediate() {\n 'worklet';\n\n let immediateCallbacks: Array<() => void> = [];\n\n // @ts-ignore – typescript expects this to conform to NodeJS definition and expects the return value to be NodeJS.Immediate which is an object and not a number\n global.setImmediate = (callback: () => void): number => {\n immediateCallbacks.push(callback);\n return -1;\n };\n\n global.__flushImmediates = () => {\n for (let index = 0; index < immediateCallbacks.length; index += 1) {\n // we use classic 'for' loop because the size of the currentTasks array may change while executing some of the callbacks due to setImmediate calls\n immediateCallbacks[index]();\n }\n immediateCallbacks = [];\n };\n}\n\nfunction flushImmediatesOnUIThread() {\n 'worklet';\n global.__flushImmediates();\n}\n\nexport const flushImmediates = shouldBeUseWeb()\n ? () => {\n // on web flushing is a noop as immediates are handled by the browser\n }\n : flushImmediatesOnUIThread;\n\n/**\n * Schedule a worklet to execute on the UI runtime. This method does not schedule the work immediately but instead\n * waits for other worklets to be scheduled within the same JS loop. It uses setImmediate to schedule all the worklets\n * at once making sure they will run within the same frame boundaries on the UI thread.\n */\nexport function runOnUI<A extends any[], R>(\n worklet: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n if (__DEV__ && !IS_WEB && worklet.__workletHash === undefined) {\n throw new Error('runOnUI() can only be used on worklets');\n }\n return (...args) => {\n if (IS_JEST) {\n // Mocking time in Jest is tricky as both requestAnimationFrame and setImmediate\n // callbacks run on the same queue and can be interleaved. There is no way\n // to flush particular queue in Jest and the only control over mocked timers\n // is by using jest.advanceTimersByTime() method which advances all types\n // of timers including immediate and animation callbacks. Ideally we'd like\n // to have some way here to schedule work along with React updates, but\n // that's not possible, and hence in Jest environment instead of using scheduling\n // mechanism we just schedule the work ommiting the queue. This is ok for the\n // uses that we currently have but may not be ok for future tests that we write.\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n return;\n }\n _runOnUIQueue.push([worklet, args]);\n if (_runOnUIQueue.length === 1) {\n setImmediate(() => {\n const queue = _runOnUIQueue;\n _runOnUIQueue = [];\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n queue.forEach(([worklet, args]) => {\n worklet(...args);\n });\n flushImmediates();\n })\n );\n });\n }\n };\n}\n\n/**\n * Schedule a worklet to execute on the UI runtime skipping batching mechanism.\n */\nexport function runOnUIImmediately<A extends any[], R>(\n worklet: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n if (__DEV__ && !IS_WEB && worklet.__workletHash === undefined) {\n throw new Error('runOnUI() can only be used on worklets');\n }\n return (...args) => {\n NativeReanimatedModule.scheduleOnUI(\n makeShareableCloneRecursive(() => {\n 'worklet';\n worklet(...args);\n })\n );\n };\n}\n\nif (__DEV__) {\n try {\n runOnUI(() => {\n 'worklet';\n });\n } catch (e) {\n throw new Error(\n 'Failed to create a worklet. Did you forget to add Reanimated Babel plugin in babel.config.js? See installation docs at https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation#babel-plugin.'\n );\n }\n}\n\nexport function runOnJS<A extends any[], R>(\n fun: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n 'worklet';\n if (fun.__remoteFunction) {\n // in development mode the function provided as `fun` throws an error message\n // such that when someone accidently calls it directly on the UI runtime, they\n // see that they should use `runOnJS` instead. To facilitate that we purt the\n // reference to the original remote function in the `__remoteFunction` property.\n fun = fun.__remoteFunction;\n }\n if (!_WORKLET) {\n return fun;\n }\n return (...args) => {\n _scheduleOnJS(\n fun,\n args.length > 0 ? makeShareableCloneOnUIRecursive(args) : undefined\n );\n };\n}\n"],"mappings":"AAAA,OAAOA,sBAAP,MAAmC,oBAAnC;AACA,SAASC,MAAT,EAAiBC,cAAjB,QAAuC,mBAAvC;AAEA,SACEC,+BADF,EAEEC,2BAFF,QAGO,cAHP;AAKA,MAAMC,OAAO,GAAGJ,MAAM,EAAtB;AACA,MAAMK,MAAM,GAAGJ,cAAc,EAA7B;AAEA,IAAIK,aAAiE,GAAG,EAAxE;AAEA,OAAO,SAASC,iBAAT,GAA6B;EAClC;;EAEA,IAAIC,kBAAqC,GAAG,EAA5C,CAHkC,CAKlC;;EACAC,MAAM,CAACC,YAAP,GAAuBC,QAAD,IAAkC;IACtDH,kBAAkB,CAACI,IAAnB,CAAwBD,QAAxB;IACA,OAAO,CAAC,CAAR;EACD,CAHD;;EAKAF,MAAM,CAACI,iBAAP,GAA2B,MAAM;IAC/B,KAAK,IAAIC,KAAK,GAAG,CAAjB,EAAoBA,KAAK,GAAGN,kBAAkB,CAACO,MAA/C,EAAuDD,KAAK,IAAI,CAAhE,EAAmE;MACjE;MACAN,kBAAkB,CAACM,KAAD,CAAlB;IACD;;IACDN,kBAAkB,GAAG,EAArB;EACD,CAND;AAOD;;AAED,SAASQ,yBAAT,GAAqC;EACnC;;EACAP,MAAM,CAACI,iBAAP;AACD;;AAED,OAAO,MAAMI,eAAe,GAAGhB,cAAc,KACzC,MAAM,CACJ;AACD,CAHwC,GAIzCe,yBAJG;AAMP;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,OAAT,CACLC,OADK,EAEiB;EACtB,IAAIC,OAAO,IAAI,CAACf,MAAZ,IAAsBc,OAAO,CAACE,aAAR,KAA0BC,SAApD,EAA+D;IAC7D,MAAM,IAAIC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AAM;MACZ;IACD,CAFM,CAAP;EAGD,CAJD,CAIE,OAAOW,CAAP,EAAU;IACV,MAAM,IAAIN,KAAJ,CACJ,wNADI,CAAN;EAGD;AACF;;AAED,OAAO,SAASO,OAAT,CACLC,GADK,EAEiB;EACtB;;EACA,IAAIA,GAAG,CAACC,gBAAR,EAA0B;IACxB;IACA;IACA;IACA;IACAD,GAAG,GAAGA,GAAG,CAACC,gBAAV;EACD;;EACD,IAAI,CAACC,QAAL,EAAe;IACb,OAAOF,GAAP;EACD;;EACD,OAAO,YAAa;IAAA,mCAATP,IAAS;MAATA,IAAS;IAAA;;IAClBU,aAAa,CACXH,GADW,EAEXP,IAAI,CAACT,MAAL,GAAc,CAAd,GAAkBb,+BAA+B,CAACsB,IAAD,CAAjD,GAA0DF,SAF/C,CAAb;EAID,CALD;AAMD"}
@@ -21,6 +21,6 @@ export function getRelativeCoords(parentRef, absoluteX, absoluteY) {
21
21
  export function isSharedValue(value) {
22
22
  'worklet';
23
23
 
24
- return typeof value === 'object' && value._isReanimatedSharedValue === true;
24
+ return (value === null || value === void 0 ? void 0 : value._isReanimatedSharedValue) === true;
25
25
  }
26
26
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["measure","getRelativeCoords","parentRef","absoluteX","absoluteY","parentCoords","x","y","isSharedValue","value","_isReanimatedSharedValue"],"sources":["utils.ts"],"sourcesContent":["import { Component } from 'react';\nimport { measure } from './NativeMethods';\nimport { RefObjectFunction } from './hook/commonTypes';\nimport { SharedValue } from './commonTypes';\n\nexport interface ComponentCoords {\n x: number;\n y: number;\n}\n\n/**\n * Given an absolute position and a component ref, returns the relative\n * position in the component's local coordinate space.\n */\nexport function getRelativeCoords(\n parentRef: RefObjectFunction<Component>,\n absoluteX: number,\n absoluteY: number\n): ComponentCoords | null {\n 'worklet';\n const parentCoords = measure(parentRef);\n if (parentCoords === null) {\n return null;\n }\n return {\n x: absoluteX - parentCoords.x,\n y: absoluteY - parentCoords.y,\n };\n}\n\nexport function isSharedValue<T>(value: any): value is SharedValue<T> {\n 'worklet';\n return typeof value === 'object' && value._isReanimatedSharedValue === true;\n}\n"],"mappings":"AACA,SAASA,OAAT,QAAwB,iBAAxB;;AASA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAT,CACLC,SADK,EAELC,SAFK,EAGLC,SAHK,EAImB;EACxB;;EACA,MAAMC,YAAY,GAAGL,OAAO,CAACE,SAAD,CAA5B;;EACA,IAAIG,YAAY,KAAK,IAArB,EAA2B;IACzB,OAAO,IAAP;EACD;;EACD,OAAO;IACLC,CAAC,EAAEH,SAAS,GAAGE,YAAY,CAACC,CADvB;IAELC,CAAC,EAAEH,SAAS,GAAGC,YAAY,CAACE;EAFvB,CAAP;AAID;AAED,OAAO,SAASC,aAAT,CAA0BC,KAA1B,EAA+D;EACpE;;EACA,OAAO,OAAOA,KAAP,KAAiB,QAAjB,IAA6BA,KAAK,CAACC,wBAAN,KAAmC,IAAvE;AACD"}
1
+ {"version":3,"names":["measure","getRelativeCoords","parentRef","absoluteX","absoluteY","parentCoords","x","y","isSharedValue","value","_isReanimatedSharedValue"],"sources":["utils.ts"],"sourcesContent":["import { Component } from 'react';\nimport { measure } from './NativeMethods';\nimport { RefObjectFunction } from './hook/commonTypes';\nimport { SharedValue } from './commonTypes';\n\nexport interface ComponentCoords {\n x: number;\n y: number;\n}\n\n/**\n * Given an absolute position and a component ref, returns the relative\n * position in the component's local coordinate space.\n */\nexport function getRelativeCoords(\n parentRef: RefObjectFunction<Component>,\n absoluteX: number,\n absoluteY: number\n): ComponentCoords | null {\n 'worklet';\n const parentCoords = measure(parentRef);\n if (parentCoords === null) {\n return null;\n }\n return {\n x: absoluteX - parentCoords.x,\n y: absoluteY - parentCoords.y,\n };\n}\n\nexport function isSharedValue<T>(value: any): value is SharedValue<T> {\n 'worklet';\n return value?._isReanimatedSharedValue === true;\n}\n"],"mappings":"AACA,SAASA,OAAT,QAAwB,iBAAxB;;AASA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAT,CACLC,SADK,EAELC,SAFK,EAGLC,SAHK,EAImB;EACxB;;EACA,MAAMC,YAAY,GAAGL,OAAO,CAACE,SAAD,CAA5B;;EACA,IAAIG,YAAY,KAAK,IAArB,EAA2B;IACzB,OAAO,IAAP;EACD;;EACD,OAAO;IACLC,CAAC,EAAEH,SAAS,GAAGE,YAAY,CAACC,CADvB;IAELC,CAAC,EAAEH,SAAS,GAAGC,YAAY,CAACE;EAFvB,CAAP;AAID;AAED,OAAO,SAASC,aAAT,CAA0BC,KAA1B,EAA+D;EACpE;;EACA,OAAO,CAAAA,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEC,wBAAP,MAAoC,IAA3C;AACD"}
package/mock.js CHANGED
@@ -8,89 +8,13 @@
8
8
  * ```
9
9
  */
10
10
 
11
- const React = require('react');
12
- const {
13
- View,
14
- Text,
15
- Image,
16
- Animated,
17
- Platform,
18
- processColor,
19
- } = require('react-native');
11
+ const { View, Text, Image, Animated, processColor } = require('react-native');
20
12
  const ReanimatedV2 = require('./src/reanimated2/mock');
21
13
 
22
14
  function NOOP() {
23
15
  // noop
24
16
  }
25
17
 
26
- function simulateCallbackFactory(...params) {
27
- return (callback) => {
28
- callback &&
29
- setTimeout(() => {
30
- // user defined callback
31
- // eslint-disable-next-line node/no-callback-literal
32
- callback(...params);
33
- }, 0);
34
- };
35
- }
36
-
37
- class Code extends React.Component {
38
- render() {
39
- return null;
40
- }
41
- }
42
-
43
- const getValue = (node) => {
44
- if (typeof node === 'number') {
45
- return node;
46
- }
47
- return (node && node[' __value']) || 0;
48
- };
49
-
50
- class AnimatedValue {
51
- constructor(val) {
52
- this[' __value'] = val;
53
- }
54
-
55
- setValue(val) {
56
- this[' __value'] = val;
57
- }
58
-
59
- interpolate() {
60
- return this;
61
- }
62
- }
63
-
64
- function createMockComponent(name) {
65
- return class extends React.Component {
66
- static displayName = name;
67
-
68
- render() {
69
- return this.props.children;
70
- }
71
- };
72
- }
73
-
74
- function createTransitioningComponent(Component) {
75
- return class extends React.Component {
76
- static displayName = `Transitioning.${
77
- Component.displayName || Component.name || 'Component'
78
- }`;
79
-
80
- setNativeProps() {
81
- // noop
82
- }
83
-
84
- animateNextTransition() {
85
- // noop
86
- }
87
-
88
- render() {
89
- return React.createElement(Component, this.props);
90
- }
91
- };
92
- }
93
-
94
18
  const Reanimated = {
95
19
  SpringUtils: {
96
20
  makeDefaultConfig: NOOP,
@@ -103,29 +27,6 @@ const Reanimated = {
103
27
  Image,
104
28
  ScrollView: Animated.ScrollView,
105
29
  FlatList: Animated.FlatList,
106
- Code,
107
-
108
- Clock: NOOP,
109
- Node: NOOP,
110
- Value: AnimatedValue,
111
-
112
- EasingNode: {
113
- linear: NOOP,
114
- ease: NOOP,
115
- quad: NOOP,
116
- cubic: NOOP,
117
- poly: () => NOOP,
118
- sin: NOOP,
119
- circle: NOOP,
120
- exp: NOOP,
121
- elastic: () => NOOP,
122
- back: () => NOOP,
123
- bounce: () => NOOP,
124
- bezier: () => NOOP,
125
- in: () => NOOP,
126
- out: () => NOOP,
127
- inOut: () => NOOP,
128
- },
129
30
 
130
31
  Extrapolate: {
131
32
  EXTEND: 'extend',
@@ -135,105 +36,8 @@ const Reanimated = {
135
36
 
136
37
  processColor,
137
38
 
138
- add: (...vals) =>
139
- new AnimatedValue(vals.map((v) => getValue(v)).reduce((acc, v) => acc + v)),
140
- sub: (...vals) =>
141
- new AnimatedValue(vals.map((v) => getValue(v)).reduce((acc, v) => acc - v)),
142
- divide: (...vals) =>
143
- new AnimatedValue(vals.map((v) => getValue(v)).reduce((acc, v) => acc / v)),
144
- multiply: (...vals) =>
145
- new AnimatedValue(vals.map((v) => getValue(v)).reduce((acc, v) => acc * v)),
146
- pow: (...vals) =>
147
- new AnimatedValue(
148
- vals.map((v) => getValue(v)).reduce((acc, v) => acc ** v)
149
- ),
150
- modulo: (a, b) => new AnimatedValue(getValue(a) % getValue(b)),
151
- sqrt: (a) => new AnimatedValue(Math.sqrt(getValue(a))),
152
- log: (a) => new AnimatedValue(Math.log(getValue(a))),
153
- sin: (a) => new AnimatedValue(Math.sin(getValue(a))),
154
- cos: (a) => new AnimatedValue(Math.cos(getValue(a))),
155
- tan: (a) => new AnimatedValue(Math.tan(getValue(a))),
156
- acos: (a) => new AnimatedValue(Math.acos(getValue(a))),
157
- asin: (a) => new AnimatedValue(Math.asin(getValue(a))),
158
- atan: (a) => new AnimatedValue(Math.atan(getValue(a))),
159
- exp: (a) => new AnimatedValue(Math.exp(getValue(a))),
160
- round: (a) => new AnimatedValue(Math.round(getValue(a))),
161
- floor: (a) => new AnimatedValue(Math.floor(getValue(a))),
162
- ceil: (a) => new AnimatedValue(Math.ceil(getValue(a))),
163
- lessThan: (a, b) => new AnimatedValue(getValue(a) < getValue(b)),
164
- eq: (a, b) => new AnimatedValue(getValue(a) === getValue(b)),
165
- greaterThan: (a, b) => new AnimatedValue(getValue(a) > getValue(b)),
166
- lessOrEq: (a, b) => new AnimatedValue(getValue(a) <= getValue(b)),
167
- greaterOrEq: (a, b) => new AnimatedValue(getValue(a) >= getValue(b)),
168
- neq: (a, b) => new AnimatedValue(getValue(a) !== getValue(b)),
169
- and: (a, b) => new AnimatedValue(getValue(a) && getValue(b)),
170
- or: (a, b) => new AnimatedValue(getValue(a) || getValue(b)),
171
- defined: (a) =>
172
- new AnimatedValue(getValue(a) !== null && getValue(a) !== undefined),
173
- not: (a) => new AnimatedValue(!getValue(a)),
174
- set: (a, b) => {
175
- a.setValue(getValue(b));
176
- return a;
177
- },
178
- concat: (a, b) => `${a}${b}`,
179
- cond: (a, b, c) => {
180
- if (getValue(a)) {
181
- return b;
182
- } else {
183
- return c;
184
- }
185
- },
186
- block: (a) => a[a.length - 1],
187
- call: (a, b) => b(a.map(getValue)),
188
- debug: NOOP,
189
- onChange: NOOP,
190
- startClock: NOOP,
191
- stopClock: NOOP,
192
- clockRunning: NOOP,
193
- event: NOOP,
194
- abs: (a) => Math.abs(getValue(a)),
195
- acc: NOOP,
196
- color: (r, g, b, a = 1) => {
197
- const color =
198
- 16777216 * Math.round(getValue(a) * 255) +
199
- 65536 * getValue(r) +
200
- 256 * getValue(g) +
201
- getValue(b);
202
- if (Platform.OS === 'android') {
203
- // on Android color is represented as signed 32 bit int
204
- if (color < (1 << 31) >>> 0) {
205
- return new AnimatedValue(color);
206
- }
207
- return new AnimatedValue(color - 2 ** 32);
208
- }
209
- return new AnimatedValue(color);
210
- },
211
- diff: NOOP,
212
- diffClamp: NOOP,
213
39
  interpolate: NOOP,
214
- interpolateNode: NOOP,
215
40
  interpolateColor: NOOP,
216
- interpolateColors: NOOP,
217
- max: (a, b) => Math.max(getValue(a), getValue(b)),
218
- min: (a, b) => Math.min(getValue(a), getValue(b)),
219
-
220
- decay: () => ({
221
- start: simulateCallbackFactory({ finished: true }),
222
- stop: simulateCallbackFactory({ finished: true }),
223
- }),
224
- timing: () => ({
225
- start: simulateCallbackFactory({ finished: true }),
226
- stop: simulateCallbackFactory({ finished: true }),
227
- }),
228
- spring: () => ({
229
- start: simulateCallbackFactory({ finished: true }),
230
- stop: simulateCallbackFactory({ finished: true }),
231
- }),
232
-
233
- proc: (cb) => cb,
234
-
235
- useCode: NOOP,
236
- useValue: (a) => new AnimatedValue(a),
237
41
  createAnimatedComponent: (Component) => Component,
238
42
  addWhitelistedUIProps: NOOP,
239
43
  addWhitelistedNativeProps: NOOP,
@@ -248,18 +52,4 @@ module.exports = {
248
52
  default: {
249
53
  ...Reanimated,
250
54
  },
251
-
252
- Transitioning: {
253
- View: createTransitioningComponent(View),
254
- },
255
-
256
- Transition: {
257
- Sequence: createMockComponent('Transition.Sequence'),
258
- Together: createMockComponent('Transition.Together'),
259
- In: createMockComponent('Transition.In'),
260
- Out: createMockComponent('Transition.Out'),
261
- Change: createMockComponent('Transition.Change'),
262
- },
263
-
264
- createTransitioningComponent,
265
55
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-reanimated",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "More powerful alternative to Animated library for React Native.",
5
5
  "scripts": {
6
6
  "test": "yarn run format:js && yarn run lint:js && yarn run test:unit",