react-native-reanimated 3.0.0-rc.4 → 3.0.0-rc.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +97 -15
- package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.h +32 -8
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +16 -1
- package/Common/cpp/NativeModules/NativeReanimatedModule.h +8 -1
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +17 -0
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +8 -0
- package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.cpp +2 -1
- package/Common/cpp/ReanimatedRuntime/ReanimatedRuntime.h +1 -0
- package/Common/cpp/Tools/RuntimeDecorator.cpp +2 -1
- package/android/CMakeLists.txt +1 -0
- package/android/build.gradle +9 -1
- package/android/src/fabric/java/com/swmansion/reanimated/NativeProxy.java +16 -25
- package/android/src/main/cpp/LayoutAnimations.cpp +42 -50
- package/android/src/main/cpp/LayoutAnimations.h +17 -3
- package/android/src/main/cpp/NativeProxy.cpp +55 -6
- package/android/src/main/java/com/swmansion/reanimated/NodesManager.java +1 -1
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/AnimationsManager.java +208 -223
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/LayoutAnimations.java +7 -5
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/NativeMethodsHolder.java +5 -3
- package/android/src/main/java/com/swmansion/reanimated/layoutReanimation/ViewHierarchyObserver.java +1 -1
- package/android/src/paper/java/com/swmansion/reanimated/NativeProxy.java +20 -7
- package/android/src/reactNativeVersionPatch/nativeHierarchyManager/62/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +8 -44
- package/android/src/reactNativeVersionPatch/nativeHierarchyManager/latest/com/swmansion/reanimated/layoutReanimation/ReanimatedNativeHierarchyManager.java +15 -61
- package/ios/LayoutReanimation/REAAnimationsManager.h +18 -8
- package/ios/LayoutReanimation/REAAnimationsManager.m +197 -162
- package/ios/LayoutReanimation/REAUIManager.mm +63 -70
- package/ios/native/NativeProxy.mm +55 -48
- package/lib/commonjs/createAnimatedComponent.js +26 -26
- package/lib/commonjs/createAnimatedComponent.js.map +1 -1
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +4 -0
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/core.js +9 -9
- package/lib/commonjs/reanimated2/core.js.map +1 -1
- package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
- package/lib/commonjs/reanimated2/jestUtils.js +17 -9
- package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js +23 -62
- package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +1 -1
- package/lib/module/createAnimatedComponent.js +27 -26
- package/lib/module/createAnimatedComponent.js.map +1 -1
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +4 -0
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/module/reanimated2/core.js +7 -9
- package/lib/module/reanimated2/core.js.map +1 -1
- package/lib/module/reanimated2/globals.d.js.map +1 -1
- package/lib/module/reanimated2/jestUtils.js +17 -9
- package/lib/module/reanimated2/jestUtils.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js +22 -61
- package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +1 -1
- package/package.json +2 -2
- package/src/createAnimatedComponent.tsx +48 -39
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +15 -0
- package/src/reanimated2/core.ts +19 -10
- package/src/reanimated2/globals.d.ts +10 -6
- package/src/reanimated2/jestUtils.ts +14 -6
- package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +24 -50
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Default.js +0 -55
- package/lib/commonjs/reanimated2/layoutReanimation/defaultAnimations/Default.js.map +0 -1
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Default.js +0 -40
- package/lib/module/reanimated2/layoutReanimation/defaultAnimations/Default.js.map +0 -1
- package/src/reanimated2/layoutReanimation/defaultAnimations/Default.ts +0 -49
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeReanimatedModule","Platform","nativeShouldBeMock","shouldBeUseWeb","isWeb","global","_setGlobalConsole","undefined","testWorklet","throwUninitializedReanimatedException","Error","checkPluginState","throwError","__workletHash","isConfigured","isConfiguredCheck","pushFrame","frame","requestFrame","native","requestAnimationFrame","_WORKLET","_log","s","console","log","runOnUI","worklet","makeShareable","value","getViewProp","viewTag","propName","_IS_FABRIC","Promise","resolve","reject","result","substr","_getTimestamp","getTimestamp","_frameTimestamp","_eventTimestamp","_getCurrentTime","OS","workletValueSetter","previousAnimation","_animation","cancelled","onFrame","animation","_value","current","isHigherOrder","callback","initializeAnimation","timestamp","onStart","step","finished","workletValueSetterJS","_setValue","makeMutable","makeRemote","object","startMapper","mapper","inputs","outputs","updater","viewDescriptors","stopMapper","mapperId","runOnJS","fun","__callAsync","installCoreFunctions","capturableConsole","debug","warn","error","info","featuresConfig","enableLayoutAnimations","setByUser","flag","isCallByUser","configureProps","uiProps","nativeProps","jestResetJsReanimatedModule","jestResetModule"],"sources":["core.ts"],"sourcesContent":["/* global _WORKLET _getCurrentTime _frameTimestamp _eventTimestamp _setGlobalConsole */\nimport NativeReanimatedModule from './NativeReanimated';\nimport { Platform } from 'react-native';\nimport { nativeShouldBeMock, shouldBeUseWeb, isWeb } from './PlatformChecker';\nimport {\n BasicWorkletFunction,\n ComplexWorkletFunction,\n SharedValue,\n AnimationObject,\n AnimatableValue,\n Timestamp,\n} from './commonTypes';\nimport { Descriptor } from './hook/commonTypes';\nimport JSReanimated from './js-reanimated/JSReanimated';\n\nif (global._setGlobalConsole === undefined) {\n // it can happen when Reanimated plugin wasn't added, but the user uses the only API from version 1\n global._setGlobalConsole = () => {\n // noop\n };\n}\n\nexport type ReanimatedConsole = Pick<\n Console,\n 'debug' | 'log' | 'warn' | 'info' | 'error'\n>;\n\nexport type WorkletValue =\n | (() => AnimationObject)\n | AnimationObject\n | AnimatableValue\n | Descriptor;\ninterface WorkletValueSetterContext {\n _animation?: AnimationObject | null;\n _value?: AnimatableValue | Descriptor;\n value?: AnimatableValue;\n _setValue?: (val: AnimatableValue | Descriptor) => void;\n}\n\nconst testWorklet: BasicWorkletFunction<void> = () => {\n 'worklet';\n};\n\nconst throwUninitializedReanimatedException = () => {\n throw new Error(\n \"Failed to initialize react-native-reanimated library, make sure you followed installation steps here: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation/ \\n1) Make sure reanimated's babel plugin is installed in your babel.config.js (you should have 'react-native-reanimated/plugin' listed there - also see the above link for details) \\n2) Make sure you reset build cache after updating the config, run: yarn start --reset-cache\"\n );\n};\n\nexport const checkPluginState: (throwError: boolean) => boolean = (\n throwError = true\n) => {\n if (!testWorklet.__workletHash && !shouldBeUseWeb()) {\n if (throwError) {\n throwUninitializedReanimatedException();\n }\n return false;\n }\n return true;\n};\n\nexport const isConfigured: (throwError?: boolean) => boolean = (\n throwError = false\n) => {\n return checkPluginState(throwError);\n};\n\nexport const isConfiguredCheck: () => void = () => {\n checkPluginState(true);\n};\n\nfunction pushFrame(frame: (timestamp: Timestamp) => void): void {\n (NativeReanimatedModule as JSReanimated).pushFrame(frame);\n}\n\nexport function requestFrame(frame: (timestamp: Timestamp) => void): void {\n 'worklet';\n if (NativeReanimatedModule.native) {\n requestAnimationFrame(frame);\n } else {\n pushFrame(frame);\n }\n}\n\nglobal._WORKLET = false;\nglobal._log = function (s: string) {\n console.log(s);\n};\n\nexport function runOnUI<A extends any[], R>(\n worklet: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n return makeShareable(worklet);\n}\n\nexport function makeShareable<T>(value: T): T {\n isConfiguredCheck();\n return NativeReanimatedModule.makeShareable(value);\n}\n\nexport function getViewProp<T>(viewTag: string, propName: string): Promise<T> {\n if (global._IS_FABRIC) {\n throw new Error(\n '[react-native-reanimated] `getViewProp` is not supported on Fabric yet'\n );\n }\n\n return new Promise((resolve, reject) => {\n return NativeReanimatedModule.getViewProp(\n viewTag,\n propName,\n (result: T) => {\n if (typeof result === 'string' && result.substr(0, 6) === 'error:') {\n reject(result);\n } else {\n resolve(result);\n }\n }\n );\n });\n}\n\nlet _getTimestamp: () => number;\nif (nativeShouldBeMock()) {\n _getTimestamp = () => {\n return (NativeReanimatedModule as JSReanimated).getTimestamp();\n };\n} else {\n _getTimestamp = () => {\n 'worklet';\n if (_frameTimestamp) {\n return _frameTimestamp;\n }\n if (_eventTimestamp) {\n return _eventTimestamp;\n }\n return _getCurrentTime();\n };\n}\n\nexport function getTimestamp(): number {\n 'worklet';\n if (Platform.OS === 'web') {\n return (NativeReanimatedModule as JSReanimated).getTimestamp();\n }\n return _getTimestamp();\n}\n\nfunction workletValueSetter<T extends WorkletValue>(\n this: WorkletValueSetterContext,\n value: T\n): void {\n 'worklet';\n const previousAnimation = this._animation;\n if (previousAnimation) {\n previousAnimation.cancelled = true;\n this._animation = null;\n }\n if (\n typeof value === 'function' ||\n (value !== null &&\n typeof value === 'object' &&\n (value as AnimationObject).onFrame !== undefined)\n ) {\n const animation: AnimationObject =\n typeof value === 'function'\n ? (value as () => AnimationObject)()\n : (value as AnimationObject);\n // prevent setting again to the same value\n // and triggering the mappers that treat this value as an input\n // this happens when the animation's target value(stored in animation.current until animation.onStart is called) is set to the same value as a current one(this._value)\n // built in animations that are not higher order(withTiming, withSpring) hold target value in .current\n if (this._value === animation.current && !animation.isHigherOrder) {\n animation.callback && animation.callback(true);\n return;\n }\n // animated set\n const initializeAnimation = (timestamp: number) => {\n animation.onStart(animation, this.value, timestamp, previousAnimation);\n };\n initializeAnimation(getTimestamp());\n const step = (timestamp: number) => {\n if (animation.cancelled) {\n animation.callback && animation.callback(false /* finished */);\n return;\n }\n const finished = animation.onFrame(animation, timestamp);\n animation.finished = true;\n animation.timestamp = timestamp;\n this._value = animation.current;\n if (finished) {\n animation.callback && animation.callback(true /* finished */);\n } else {\n requestAnimationFrame(step);\n }\n };\n\n this._animation = animation;\n\n if (_frameTimestamp) {\n // frame\n step(_frameTimestamp);\n } else {\n requestAnimationFrame(step);\n }\n } else {\n // prevent setting again to the same value\n // and triggering the mappers that treat this value as an input\n if (this._value === value) {\n return;\n }\n this._value = value as Descriptor | AnimatableValue;\n }\n}\n\n// We cannot use pushFrame\n// so we use own implementation for js\nfunction workletValueSetterJS<T extends WorkletValue>(\n this: WorkletValueSetterContext,\n value: T\n): void {\n const previousAnimation = this._animation;\n if (previousAnimation) {\n previousAnimation.cancelled = true;\n this._animation = null;\n }\n if (\n typeof value === 'function' ||\n (value !== null &&\n typeof value === 'object' &&\n (value as AnimationObject).onFrame)\n ) {\n // animated set\n const animation: AnimationObject =\n typeof value === 'function'\n ? (value as () => AnimationObject)()\n : (value as AnimationObject);\n let initializeAnimation: ((timestamp: number) => void) | null = (\n timestamp: number\n ) => {\n animation.onStart(animation, this.value, timestamp, previousAnimation);\n };\n const step = (timestamp: number) => {\n if (animation.cancelled) {\n animation.callback && animation.callback(false /* finished */);\n return;\n }\n if (initializeAnimation) {\n initializeAnimation(timestamp);\n initializeAnimation = null; // prevent closure from keeping ref to previous animation\n }\n const finished = animation.onFrame(animation, timestamp);\n animation.timestamp = timestamp;\n this._setValue && this._setValue(animation.current as AnimatableValue);\n if (finished) {\n animation.callback && animation.callback(true /* finished */);\n } else {\n requestFrame(step);\n }\n };\n\n this._animation = animation;\n\n requestFrame(step);\n } else {\n this._setValue && this._setValue(value as AnimatableValue | Descriptor);\n }\n}\n\nexport function makeMutable<T>(value: T): SharedValue<T> {\n isConfiguredCheck();\n return NativeReanimatedModule.makeMutable(value);\n}\n\nexport function makeRemote<T>(object = {}): T {\n isConfiguredCheck();\n return NativeReanimatedModule.makeRemote(object);\n}\n\nexport function startMapper(\n mapper: () => void,\n inputs: any[] = [],\n outputs: any[] = [],\n updater: () => void = () => {\n // noop\n },\n viewDescriptors: Descriptor[] | SharedValue<Descriptor[]> = []\n): number {\n isConfiguredCheck();\n return NativeReanimatedModule.startMapper(\n mapper,\n inputs,\n outputs,\n updater,\n viewDescriptors\n );\n}\n\nexport function stopMapper(mapperId: number): void {\n NativeReanimatedModule.stopMapper(mapperId);\n}\n\nexport interface RunOnJSFunction<A extends any[], R> {\n __callAsync?: (...args: A) => void;\n (...args: A): R;\n}\n\nexport function runOnJS<A extends any[], R>(\n fun: RunOnJSFunction<A, R>\n): () => void {\n 'worklet';\n if (!_WORKLET) {\n return fun;\n }\n if (!fun.__callAsync) {\n throw new Error(\n \"Attempting to call runOnJS with an object that is not a host function. Using runOnJS is only possible with methods that are defined on the main React-Native Javascript thread and that aren't marked as worklets\"\n );\n } else {\n return fun.__callAsync;\n }\n}\n\nNativeReanimatedModule.installCoreFunctions(\n NativeReanimatedModule.native\n ? (workletValueSetter as <T>(value: T) => void)\n : (workletValueSetterJS as <T>(value: T) => void)\n);\n\nif (!isWeb() && isConfigured()) {\n const capturableConsole = console;\n runOnUI(() => {\n 'worklet';\n const console = {\n debug: runOnJS(capturableConsole.debug),\n log: runOnJS(capturableConsole.log),\n warn: runOnJS(capturableConsole.warn),\n error: runOnJS(capturableConsole.error),\n info: runOnJS(capturableConsole.info),\n };\n _setGlobalConsole(console);\n })();\n}\n\ntype FeaturesConfig = {\n enableLayoutAnimations: boolean;\n setByUser: boolean;\n};\n\nlet featuresConfig: FeaturesConfig = {\n enableLayoutAnimations: false,\n setByUser: false,\n};\n\nexport function enableLayoutAnimations(\n flag: boolean,\n isCallByUser = true\n): void {\n if (isCallByUser) {\n featuresConfig = {\n enableLayoutAnimations: flag,\n setByUser: true,\n };\n NativeReanimatedModule.enableLayoutAnimations(flag);\n } else if (\n !featuresConfig.setByUser &&\n featuresConfig.enableLayoutAnimations !== flag\n ) {\n featuresConfig.enableLayoutAnimations = flag;\n NativeReanimatedModule.enableLayoutAnimations(flag);\n }\n}\n\nexport function configureProps(uiProps: string[], nativeProps: string[]): void {\n if (!nativeShouldBeMock()) {\n NativeReanimatedModule.configureProps(uiProps, nativeProps);\n }\n}\n\nexport function jestResetJsReanimatedModule() {\n (NativeReanimatedModule as JSReanimated).jestResetModule();\n}\n"],"mappings":"AAAA;AACA,OAAOA,sBAAP,MAAmC,oBAAnC;AACA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,kBAAT,EAA6BC,cAA7B,EAA6CC,KAA7C,QAA0D,mBAA1D;;AAYA,IAAIC,MAAM,CAACC,iBAAP,KAA6BC,SAAjC,EAA4C;EAC1C;EACAF,MAAM,CAACC,iBAAP,GAA2B,MAAM,CAC/B;EACD,CAFD;AAGD;;AAmBD,MAAME,WAAuC,GAAG,MAAM;EACpD;AACD,CAFD;;AAIA,MAAMC,qCAAqC,GAAG,MAAM;EAClD,MAAM,IAAIC,KAAJ,CACJ,4cADI,CAAN;AAGD,CAJD;;AAMA,OAAO,MAAMC,gBAAkD,GAAG,YAE7D;EAAA,IADHC,UACG,uEADU,IACV;;EACH,IAAI,CAACJ,WAAW,CAACK,aAAb,IAA8B,CAACV,cAAc,EAAjD,EAAqD;IACnD,IAAIS,UAAJ,EAAgB;MACdH,qCAAqC;IACtC;;IACD,OAAO,KAAP;EACD;;EACD,OAAO,IAAP;AACD,CAVM;AAYP,OAAO,MAAMK,YAA+C,GAAG,YAE1D;EAAA,IADHF,UACG,uEADU,KACV;EACH,OAAOD,gBAAgB,CAACC,UAAD,CAAvB;AACD,CAJM;AAMP,OAAO,MAAMG,iBAA6B,GAAG,MAAM;EACjDJ,gBAAgB,CAAC,IAAD,CAAhB;AACD,CAFM;;AAIP,SAASK,SAAT,CAAmBC,KAAnB,EAAgE;EAC7DjB,sBAAD,CAAyCgB,SAAzC,CAAmDC,KAAnD;AACD;;AAED,OAAO,S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B,CAACkB,OAAD,CAAjB;EACD,CAVM,CAAP;AAWD;;AAOD,IAAI0D,cAA8B,GAAG;EACnCC,sBAAsB,EAAE,KADW;EAEnCC,SAAS,EAAE;AAFwB,CAArC;AAKA,OAAO,SAASD,sBAAT,CACLE,IADK,EAGC;EAAA,IADNC,YACM,uEADS,IACT;;EACN,IAAIA,YAAJ,EAAkB;IAChBJ,cAAc,GAAG;MACfC,sBAAsB,EAAEE,IADT;MAEfD,SAAS,EAAE;IAFI,CAAjB;IAIApF,sBAAsB,CAACmF,sBAAvB,CAA8CE,IAA9C;EACD,CAND,MAMO,IACL,CAACH,cAAc,CAACE,SAAhB,IACAF,cAAc,CAACC,sBAAf,KAA0CE,IAFrC,EAGL;IACAH,cAAc,CAACC,sBAAf,GAAwCE,IAAxC;IACArF,sBAAsB,CAACmF,sBAAvB,CAA8CE,IAA9C;EACD;AACF;AAED,OAAO,SAASE,cAAT,CAAwBC,OAAxB,EAA2CC,WAA3C,EAAwE;EAC7E,IAAI,CAACvF,kBAAkB,EAAvB,EAA2B;IACzBF,sBAAsB,CAACuF,cAAvB,CAAsCC,OAAtC,EAA+CC,WAA/C;EACD;AACF;AAED,OAAO,SAASC,2BAAT,GAAuC;EAC3C1F,sBAAD,CAAyC2F,eAAzC;AACD"}
|
|
1
|
+
{"version":3,"names":["NativeReanimatedModule","Platform","nativeShouldBeMock","shouldBeUseWeb","isWeb","global","_setGlobalConsole","undefined","testWorklet","throwUninitializedReanimatedException","Error","checkPluginState","throwError","__workletHash","isConfigured","isConfiguredCheck","pushFrame","frame","requestFrame","native","requestAnimationFrame","_WORKLET","_log","s","console","log","runOnUI","worklet","makeShareable","value","getViewProp","viewTag","propName","_IS_FABRIC","Promise","resolve","reject","result","substr","_getTimestamp","getTimestamp","_frameTimestamp","_eventTimestamp","_getCurrentTime","OS","workletValueSetter","previousAnimation","_animation","cancelled","onFrame","animation","_value","current","isHigherOrder","callback","initializeAnimation","timestamp","onStart","currentTimestamp","step","finished","workletValueSetterJS","_setValue","makeMutable","makeRemote","object","startMapper","mapper","inputs","outputs","updater","viewDescriptors","stopMapper","mapperId","runOnJS","fun","__callAsync","installCoreFunctions","capturableConsole","debug","warn","error","info","featuresConfig","enableLayoutAnimations","setByUser","flag","isCallByUser","configureLayoutAnimations","type","config","viewSharedValue","configureLayoutAnimation","configureProps","uiProps","nativeProps","jestResetJsReanimatedModule","jestResetModule"],"sources":["core.ts"],"sourcesContent":["/* global _WORKLET _getCurrentTime _frameTimestamp _eventTimestamp _setGlobalConsole */\nimport NativeReanimatedModule from './NativeReanimated';\nimport { Platform } from 'react-native';\nimport { nativeShouldBeMock, shouldBeUseWeb, isWeb } from './PlatformChecker';\nimport {\n BasicWorkletFunction,\n ComplexWorkletFunction,\n SharedValue,\n AnimationObject,\n AnimatableValue,\n Timestamp,\n} from './commonTypes';\nimport { Descriptor } from './hook/commonTypes';\nimport JSReanimated from './js-reanimated/JSReanimated';\nimport { LayoutAnimationFunction } from './layoutReanimation';\n\nif (global._setGlobalConsole === undefined) {\n // it can happen when Reanimated plugin wasn't added, but the user uses the only API from version 1\n global._setGlobalConsole = () => {\n // noop\n };\n}\n\nexport type ReanimatedConsole = Pick<\n Console,\n 'debug' | 'log' | 'warn' | 'info' | 'error'\n>;\n\nexport type WorkletValue =\n | (() => AnimationObject)\n | AnimationObject\n | AnimatableValue\n | Descriptor;\ninterface WorkletValueSetterContext {\n _animation?: AnimationObject | null;\n _value?: AnimatableValue | Descriptor;\n value?: AnimatableValue;\n _setValue?: (val: AnimatableValue | Descriptor) => void;\n}\n\nconst testWorklet: BasicWorkletFunction<void> = () => {\n 'worklet';\n};\n\nconst throwUninitializedReanimatedException = () => {\n throw new Error(\n \"Failed to initialize react-native-reanimated library, make sure you followed installation steps here: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/installation/ \\n1) Make sure reanimated's babel plugin is installed in your babel.config.js (you should have 'react-native-reanimated/plugin' listed there - also see the above link for details) \\n2) Make sure you reset build cache after updating the config, run: yarn start --reset-cache\"\n );\n};\n\nexport const checkPluginState: (throwError: boolean) => boolean = (\n throwError = true\n) => {\n if (!testWorklet.__workletHash && !shouldBeUseWeb()) {\n if (throwError) {\n throwUninitializedReanimatedException();\n }\n return false;\n }\n return true;\n};\n\nexport const isConfigured: (throwError?: boolean) => boolean = (\n throwError = false\n) => {\n return checkPluginState(throwError);\n};\n\nexport const isConfiguredCheck: () => void = () => {\n checkPluginState(true);\n};\n\nfunction pushFrame(frame: (timestamp: Timestamp) => void): void {\n (NativeReanimatedModule as JSReanimated).pushFrame(frame);\n}\n\nexport function requestFrame(frame: (timestamp: Timestamp) => void): void {\n 'worklet';\n if (NativeReanimatedModule.native) {\n requestAnimationFrame(frame);\n } else {\n pushFrame(frame);\n }\n}\n\nglobal._WORKLET = false;\nglobal._log = function (s: string) {\n console.log(s);\n};\n\nexport function runOnUI<A extends any[], R>(\n worklet: ComplexWorkletFunction<A, R>\n): (...args: A) => void {\n return makeShareable(worklet);\n}\n\nexport function makeShareable<T>(value: T): T {\n isConfiguredCheck();\n return NativeReanimatedModule.makeShareable(value);\n}\n\nexport function getViewProp<T>(viewTag: string, propName: string): Promise<T> {\n if (global._IS_FABRIC) {\n throw new Error(\n '[react-native-reanimated] `getViewProp` is not supported on Fabric yet'\n );\n }\n\n return new Promise((resolve, reject) => {\n return NativeReanimatedModule.getViewProp(\n viewTag,\n propName,\n (result: T) => {\n if (typeof result === 'string' && result.substr(0, 6) === 'error:') {\n reject(result);\n } else {\n resolve(result);\n }\n }\n );\n });\n}\n\nlet _getTimestamp: () => number;\nif (nativeShouldBeMock()) {\n _getTimestamp = () => {\n return (NativeReanimatedModule as JSReanimated).getTimestamp();\n };\n} else {\n _getTimestamp = () => {\n 'worklet';\n if (_frameTimestamp) {\n return _frameTimestamp;\n }\n if (_eventTimestamp) {\n return _eventTimestamp;\n }\n return _getCurrentTime();\n };\n}\n\nexport function getTimestamp(): number {\n 'worklet';\n if (Platform.OS === 'web') {\n return (NativeReanimatedModule as JSReanimated).getTimestamp();\n }\n return _getTimestamp();\n}\n\nfunction workletValueSetter<T extends WorkletValue>(\n this: WorkletValueSetterContext,\n value: T\n): void {\n 'worklet';\n const previousAnimation = this._animation;\n if (previousAnimation) {\n previousAnimation.cancelled = true;\n this._animation = null;\n }\n if (\n typeof value === 'function' ||\n (value !== null &&\n typeof value === 'object' &&\n (value as AnimationObject).onFrame !== undefined)\n ) {\n const animation: AnimationObject =\n typeof value === 'function'\n ? (value as () => AnimationObject)()\n : (value as AnimationObject);\n // prevent setting again to the same value\n // and triggering the mappers that treat this value as an input\n // this happens when the animation's target value(stored in animation.current until animation.onStart is called) is set to the same value as a current one(this._value)\n // built in animations that are not higher order(withTiming, withSpring) hold target value in .current\n if (this._value === animation.current && !animation.isHigherOrder) {\n animation.callback && animation.callback(true);\n return;\n }\n // animated set\n const initializeAnimation = (timestamp: number) => {\n animation.onStart(animation, this.value, timestamp, previousAnimation);\n };\n const currentTimestamp = getTimestamp();\n initializeAnimation(currentTimestamp);\n const step = (timestamp: number) => {\n if (animation.cancelled) {\n animation.callback && animation.callback(false /* finished */);\n return;\n }\n const finished = animation.onFrame(animation, timestamp);\n animation.finished = true;\n animation.timestamp = timestamp;\n this._value = animation.current;\n if (finished) {\n animation.callback && animation.callback(true /* finished */);\n } else {\n requestAnimationFrame(step);\n }\n };\n\n this._animation = animation;\n step(currentTimestamp);\n } else {\n // prevent setting again to the same value\n // and triggering the mappers that treat this value as an input\n if (this._value === value) {\n return;\n }\n this._value = value as Descriptor | AnimatableValue;\n }\n}\n\n// We cannot use pushFrame\n// so we use own implementation for js\nfunction workletValueSetterJS<T extends WorkletValue>(\n this: WorkletValueSetterContext,\n value: T\n): void {\n const previousAnimation = this._animation;\n if (previousAnimation) {\n previousAnimation.cancelled = true;\n this._animation = null;\n }\n if (\n typeof value === 'function' ||\n (value !== null &&\n typeof value === 'object' &&\n (value as AnimationObject).onFrame)\n ) {\n // animated set\n const animation: AnimationObject =\n typeof value === 'function'\n ? (value as () => AnimationObject)()\n : (value as AnimationObject);\n let initializeAnimation: ((timestamp: number) => void) | null = (\n timestamp: number\n ) => {\n animation.onStart(animation, this.value, timestamp, previousAnimation);\n };\n const step = (timestamp: number) => {\n if (animation.cancelled) {\n animation.callback && animation.callback(false /* finished */);\n return;\n }\n if (initializeAnimation) {\n initializeAnimation(timestamp);\n initializeAnimation = null; // prevent closure from keeping ref to previous animation\n }\n const finished = animation.onFrame(animation, timestamp);\n animation.timestamp = timestamp;\n this._setValue && this._setValue(animation.current as AnimatableValue);\n if (finished) {\n animation.callback && animation.callback(true /* finished */);\n } else {\n requestFrame(step);\n }\n };\n\n this._animation = animation;\n step(getTimestamp());\n } else {\n this._setValue && this._setValue(value as AnimatableValue | Descriptor);\n }\n}\n\nexport function makeMutable<T>(value: T): SharedValue<T> {\n isConfiguredCheck();\n return NativeReanimatedModule.makeMutable(value);\n}\n\nexport function makeRemote<T>(object = {}): T {\n isConfiguredCheck();\n return NativeReanimatedModule.makeRemote(object);\n}\n\nexport function startMapper(\n mapper: () => void,\n inputs: any[] = [],\n outputs: any[] = [],\n updater: () => void = () => {\n // noop\n },\n viewDescriptors: Descriptor[] | SharedValue<Descriptor[]> = []\n): number {\n isConfiguredCheck();\n return NativeReanimatedModule.startMapper(\n mapper,\n inputs,\n outputs,\n updater,\n viewDescriptors\n );\n}\n\nexport function stopMapper(mapperId: number): void {\n NativeReanimatedModule.stopMapper(mapperId);\n}\n\nexport interface RunOnJSFunction<A extends any[], R> {\n __callAsync?: (...args: A) => void;\n (...args: A): R;\n}\n\nexport function runOnJS<A extends any[], R>(\n fun: RunOnJSFunction<A, R>\n): () => void {\n 'worklet';\n if (!_WORKLET) {\n return fun;\n }\n if (!fun.__callAsync) {\n throw new Error(\n \"Attempting to call runOnJS with an object that is not a host function. Using runOnJS is only possible with methods that are defined on the main React-Native Javascript thread and that aren't marked as worklets\"\n );\n } else {\n return fun.__callAsync;\n }\n}\n\nNativeReanimatedModule.installCoreFunctions(\n NativeReanimatedModule.native\n ? (workletValueSetter as <T>(value: T) => void)\n : (workletValueSetterJS as <T>(value: T) => void)\n);\n\nif (!isWeb() && isConfigured()) {\n const capturableConsole = console;\n runOnUI(() => {\n 'worklet';\n const console = {\n debug: runOnJS(capturableConsole.debug),\n log: runOnJS(capturableConsole.log),\n warn: runOnJS(capturableConsole.warn),\n error: runOnJS(capturableConsole.error),\n info: runOnJS(capturableConsole.info),\n };\n _setGlobalConsole(console);\n })();\n}\n\ntype FeaturesConfig = {\n enableLayoutAnimations: boolean;\n setByUser: boolean;\n};\n\nlet featuresConfig: FeaturesConfig = {\n enableLayoutAnimations: false,\n setByUser: false,\n};\n\nexport function enableLayoutAnimations(\n flag: boolean,\n isCallByUser = true\n): void {\n if (isCallByUser) {\n featuresConfig = {\n enableLayoutAnimations: flag,\n setByUser: true,\n };\n NativeReanimatedModule.enableLayoutAnimations(flag);\n } else if (\n !featuresConfig.setByUser &&\n featuresConfig.enableLayoutAnimations !== flag\n ) {\n featuresConfig.enableLayoutAnimations = flag;\n NativeReanimatedModule.enableLayoutAnimations(flag);\n }\n}\n\nexport function configureLayoutAnimations(\n viewTag: number,\n type: string,\n config: LayoutAnimationFunction | Keyframe,\n viewSharedValue: SharedValue<null | Record<string, unknown>> | null\n): void {\n NativeReanimatedModule.configureLayoutAnimation(\n viewTag,\n type,\n config,\n viewSharedValue\n );\n}\n\nexport function configureProps(uiProps: string[], nativeProps: string[]): void {\n if (!nativeShouldBeMock()) {\n NativeReanimatedModule.configureProps(uiProps, nativeProps);\n }\n}\n\nexport function jestResetJsReanimatedModule() {\n (NativeReanimatedModule as JSReanimated).jestResetModule();\n}\n"],"mappings":"AAAA;AACA,OAAOA,sBAAP,MAAmC,oBAAnC;AACA,SAASC,QAAT,QAAyB,cAAzB;AACA,SAASC,kBAAT,EAA6BC,cAA7B,EAA6CC,KAA7C,QAA0D,mBAA1D;;AAaA,IAAIC,MAAM,CAACC,iBAAP,KAA6BC,SAAjC,EAA4C;EAC1C;EACA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E,IAA9C;EACD;AACF;AAED,OAAO,SAASE,yBAAT,CACLzD,OADK,EAEL0D,IAFK,EAGLC,MAHK,EAILC,eAJK,EAKC;EACN3F,sBAAsB,CAAC4F,wBAAvB,CACE7D,OADF,EAEE0D,IAFF,EAGEC,MAHF,EAIEC,eAJF;AAMD;AAED,OAAO,SAASE,cAAT,CAAwBC,OAAxB,EAA2CC,WAA3C,EAAwE;EAC7E,IAAI,CAAC7F,kBAAkB,EAAvB,EAA2B;IACzBF,sBAAsB,CAAC6F,cAAvB,CAAsCC,OAAtC,EAA+CC,WAA/C;EACD;AACF;AAED,OAAO,SAASC,2BAAT,GAAuC;EAC3ChG,sBAAD,CAAyCiG,eAAzC;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["globals.d.ts"],"sourcesContent":["import type {\n AnimatedStyle,\n StyleProps,\n MeasuredDimensions,\n} from './commonTypes';\nimport type { ReanimatedConsole } from './core';\nimport type { FrameCallbackRegistryUI } from './frameCallback/FrameCallbackRegistryUI';\nimport type { ShadowNodeWrapper } from './hook/commonTypes';\nimport type { NativeReanimated } from './NativeReanimated/NativeReanimated';\n\ndeclare global {\n const _WORKLET: boolean;\n const _IS_FABRIC: boolean;\n const _frameTimestamp: number | null;\n const _eventTimestamp: number;\n const __reanimatedModuleProxy: NativeReanimated;\n const _setGlobalConsole: (console?: ReanimatedConsole) => void;\n const _log: (s: string) => void;\n const _getCurrentTime: () => number;\n const _stopObservingProgress: (tag: number
|
|
1
|
+
{"version":3,"names":[],"sources":["globals.d.ts"],"sourcesContent":["import type {\n AnimatedStyle,\n StyleProps,\n MeasuredDimensions,\n} from './commonTypes';\nimport type { ReanimatedConsole } from './core';\nimport type { FrameCallbackRegistryUI } from './frameCallback/FrameCallbackRegistryUI';\nimport type { ShadowNodeWrapper } from './hook/commonTypes';\nimport type { NativeReanimated } from './NativeReanimated/NativeReanimated';\n\ndeclare global {\n const _WORKLET: boolean;\n const _IS_FABRIC: boolean;\n const _frameTimestamp: number | null;\n const _eventTimestamp: number;\n const __reanimatedModuleProxy: NativeReanimated;\n const _setGlobalConsole: (console?: ReanimatedConsole) => void;\n const _log: (s: string) => void;\n const _getCurrentTime: () => number;\n const _stopObservingProgress: (\n tag: number,\n cancelled: boolean,\n removeView: boolean\n ) => void;\n const _startObservingProgress: (\n tag: number,\n viewSharedValue: { value: unknown; _value: unknown },\n type: string\n ) => void;\n const _setGestureState: (handlerTag: number, newState: number) => void;\n const _updatePropsPaper: (\n tag: number,\n name: string,\n updates: StyleProps | AnimatedStyle\n ) => void;\n const _updatePropsFabric: (\n shadowNodeWrapper: ShadowNodeWrapper,\n props: StyleProps | AnimatedStyle\n ) => void;\n const _removeShadowNodeFromRegistry: (\n shadowNodeWrapper: ShadowNodeWrapper\n ) => void;\n const _measure: (viewTag: number) => MeasuredDimensions;\n const _scrollTo: (\n viewTag: number,\n x: number,\n y: number,\n animated: boolean\n ) => void;\n const _dispatchCommand: (\n shadowNodeWrapper: ShadowNodeWrapper,\n commandName: string,\n args: Array<unknown>\n ) => void;\n const _chronoNow: () => number;\n const performance: { now: () => number };\n const LayoutAnimationRepository: {\n configs: Record<string, unknown>;\n registerConfig(tag: number, config: Record<string, unknown>): void;\n removeConfig(tag: number): void;\n startAnimationForTag(tag: number, type: string, yogaValues: unknown): void;\n };\n const ReanimatedDataMock: {\n now: () => number;\n };\n const _frameCallbackRegistry: FrameCallbackRegistryUI;\n\n namespace NodeJS {\n interface Global {\n _WORKLET: boolean;\n _IS_FABRIC: boolean;\n _frameTimestamp: number | null;\n _eventTimestamp: number;\n __reanimatedModuleProxy: NativeReanimated;\n _setGlobalConsole: (console?: ReanimatedConsole) => void;\n _log: (s: string) => void;\n _getCurrentTime: () => number;\n _stopObservingProgress: (tag: number, flag: boolean) => void;\n _startObservingProgress: (\n tag: number,\n flag: { value: boolean; _value: boolean }\n ) => void;\n _setGestureState: (handlerTag: number, newState: number) => void;\n _updatePropsPaper: (\n tag: number,\n name: string,\n updates: StyleProps | AnimatedStyle\n ) => void;\n _updatePropsFabric: (\n shadowNodeWrapper: ShadowNodeWrapper,\n props: StyleProps | AnimatedStyle\n ) => void;\n _removeShadowNodeFromRegistry: (\n shadowNodeWrapper: ShadowNodeWrapper\n ) => void;\n _measure: (viewTag: number) => MeasuredDimensions;\n _scrollTo: (\n viewTag: number,\n x: number,\n y: number,\n animated: boolean\n ) => void;\n _dispatchCommand: (\n shadowNodeWrapper: ShadowNodeWrapper,\n commandName: string,\n args: Array<unknown>\n ) => void;\n _chronoNow: () => number;\n performance: { now: () => number };\n LayoutAnimationRepository: {\n startAnimationForTag(\n tag: number,\n type: string,\n yogaValues: Record<string, number>,\n config: LayoutAnimationFunction | Keyframe,\n viewSharedValue: { value: unknown; _value: unknown }\n ): void;\n };\n ReanimatedDataMock: {\n now: () => number;\n };\n _frameCallbackRegistry: FrameCallbackRegistryUI;\n }\n }\n}\n"],"mappings":""}
|
|
@@ -184,17 +184,25 @@ export const advanceAnimationByFrame = count => {
|
|
|
184
184
|
};
|
|
185
185
|
export const setUpTests = function () {
|
|
186
186
|
let userConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
187
|
-
let expect;
|
|
187
|
+
let expect = global.expect;
|
|
188
188
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
} catch (_) {
|
|
192
|
-
// for Jest in version 28+
|
|
193
|
-
const {
|
|
194
|
-
expect: expectModule
|
|
195
|
-
} = require('@jest/globals');
|
|
189
|
+
if (expect === undefined) {
|
|
190
|
+
const expectModule = require('expect');
|
|
196
191
|
|
|
197
|
-
expect = expectModule;
|
|
192
|
+
expect = expectModule; // Starting from Jest 28, "expect" package uses named exports instead of default export.
|
|
193
|
+
// So, requiring "expect" package doesn't give direct access to "expect" function anymore.
|
|
194
|
+
// It gives access to the module object instead.
|
|
195
|
+
// We use this info to detect if the project uses Jest 28 or higher.
|
|
196
|
+
|
|
197
|
+
if (typeof expect === 'object') {
|
|
198
|
+
const jestGlobals = require('@jest/globals');
|
|
199
|
+
|
|
200
|
+
expect = jestGlobals.expect;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (expect === undefined || expect.extend === undefined) {
|
|
204
|
+
expect = expectModule.default;
|
|
205
|
+
}
|
|
198
206
|
}
|
|
199
207
|
|
|
200
208
|
require('setimmediate');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["jestResetJsReanimatedModule","config","fps","isAnimatedStyle","style","animatedStyle","getAnimatedStyleFromObject","current","value","getCurrentStyle","received","styleObject","props","currentStyle","Array","isArray","forEach","checkEqual","expectStyle","length","i","property","findStyleDiff","expect","requireAllMatch","diffs","isEqual","push","Object","keys","undefined","compareStyle","expectedStyle","message","pass","exact","currentStyleStr","JSON","stringify","expectedStyleStr","differences","map","diff","join","frameTime","requestAnimationFrameCopy","currentTimestamp","requestAnimationFrame","callback","setTimeout","beforeTest","global","ReanimatedDataMock","now","jest","useFakeTimers","afterTest","useRealTimers","tickTravel","advanceTimersByTime","withReanimatedTimer","animationTest","advanceAnimationByTime","time","Math","ceil","advanceAnimationByFrame","count","setUpTests","userConfig","require","_","expectModule","round","extend","toHaveAnimatedStyle","getAnimatedStyle"],"sources":["jestUtils.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\nimport { jestResetJsReanimatedModule } from './core';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R> {\n toHaveAnimatedStyle(\n style: Record<string, unknown>[] | Record<string, unknown>\n ): R;\n }\n }\n}\n\nlet config = {\n fps: 60,\n};\n\nconst isAnimatedStyle = (style) => {\n return !!style.animatedStyle;\n};\n\nconst getAnimatedStyleFromObject = (style) => {\n return style.animatedStyle.current.value;\n};\n\nconst getCurrentStyle = (received) => {\n const styleObject = received.props.style;\n let currentStyle = {};\n if (Array.isArray(styleObject)) {\n received.props.style.forEach((style) => {\n if (isAnimatedStyle(style)) {\n currentStyle = {\n ...currentStyle,\n ...getAnimatedStyleFromObject(style),\n };\n } else {\n currentStyle = {\n ...currentStyle,\n ...style,\n };\n }\n });\n } else {\n if (isAnimatedStyle(styleObject)) {\n currentStyle = getAnimatedStyleFromObject(styleObject);\n } else {\n currentStyle = {\n ...styleObject,\n ...received.props.animatedStyle.value,\n };\n }\n }\n return currentStyle;\n};\n\nconst checkEqual = (currentStyle, expectStyle) => {\n if (Array.isArray(expectStyle)) {\n if (expectStyle.length !== currentStyle.length) return false;\n for (let i = 0; i < currentStyle.length; i++) {\n if (!checkEqual(currentStyle[i], expectStyle[i])) {\n return false;\n }\n }\n } else if (typeof currentStyle === 'object' && currentStyle) {\n for (const property in expectStyle) {\n if (!checkEqual(currentStyle[property], expectStyle[property])) {\n return false;\n }\n }\n } else {\n return currentStyle === expectStyle;\n }\n return true;\n};\n\nconst findStyleDiff = (current, expect, requireAllMatch) => {\n const diffs = [];\n let isEqual = true;\n for (const property in expect) {\n if (!checkEqual(current[property], expect[property])) {\n isEqual = false;\n diffs.push({\n property: property,\n current: current[property],\n expect: expect[property],\n });\n }\n }\n\n if (\n requireAllMatch &&\n Object.keys(current).length !== Object.keys(expect).length\n ) {\n isEqual = false;\n for (const property in current) {\n if (expect[property] === undefined) {\n diffs.push({\n property: property,\n current: current[property],\n expect: expect[property],\n });\n }\n }\n }\n\n return { isEqual, diffs };\n};\n\nconst compareStyle = (received, expectedStyle, config) => {\n if (!received.props.style) {\n return { message: () => message, pass: false };\n }\n const { exact } = config;\n const currentStyle = getCurrentStyle(received);\n const { isEqual, diffs } = findStyleDiff(currentStyle, expectedStyle, exact);\n\n if (isEqual) {\n return { message: () => 'ok', pass: true };\n }\n\n const currentStyleStr = JSON.stringify(currentStyle);\n const expectedStyleStr = JSON.stringify(expectedStyle);\n const differences = diffs\n .map(\n (diff) =>\n `- '${diff.property}' should be ${JSON.stringify(\n diff.expect\n )}, but is ${JSON.stringify(diff.current)}`\n )\n .join('\\n');\n\n return {\n message: () =>\n `Expected: ${expectedStyleStr}\\nReceived: ${currentStyleStr}\\n\\nDifferences:\\n${differences}`,\n pass: false,\n };\n};\n\nlet frameTime = 1000 / config.fps;\nlet requestAnimationFrameCopy;\nlet currentTimestamp = 0;\n\nconst requestAnimationFrame = (callback) => {\n setTimeout(callback, frameTime);\n};\n\nconst beforeTest = () => {\n jestResetJsReanimatedModule();\n requestAnimationFrameCopy = global.requestAnimationFrame;\n global.requestAnimationFrame = requestAnimationFrame;\n global.ReanimatedDataMock = {\n now: () => currentTimestamp,\n };\n currentTimestamp = 0;\n jest.useFakeTimers();\n};\n\nconst afterTest = () => {\n jest.useRealTimers();\n global.requestAnimationFrame = requestAnimationFrameCopy;\n};\n\nconst tickTravel = () => {\n currentTimestamp += frameTime;\n jest.advanceTimersByTime(frameTime);\n};\n\nexport const withReanimatedTimer = (animationTest) => {\n beforeTest();\n animationTest();\n afterTest();\n};\n\nexport const advanceAnimationByTime = (time = frameTime) => {\n for (let i = 0; i <= Math.ceil(time / frameTime); i++) {\n tickTravel();\n }\n jest.advanceTimersByTime(frameTime);\n};\n\nexport const advanceAnimationByFrame = (count) => {\n for (let i = 0; i <= count; i++) {\n tickTravel();\n }\n jest.advanceTimersByTime(frameTime);\n};\n\nexport const setUpTests = (userConfig = {}) => {\n let expect;\n try {\n expect = require('expect');\n } catch (_) {\n // for Jest in version 28+\n const { expect: expectModule } = require('@jest/globals');\n expect = expectModule;\n }\n\n require('setimmediate');\n frameTime = Math.round(1000 / config.fps);\n\n config = {\n ...config,\n ...userConfig,\n };\n\n expect.extend({\n toHaveAnimatedStyle(received, expectedStyle, config = {}) {\n return compareStyle(received, expectedStyle, config);\n },\n });\n};\n\nexport const getAnimatedStyle = (received) => {\n return getCurrentStyle(received);\n};\n"],"mappings":"AAAA;AACA;AACA,SAASA,2BAAT,QAA4C,QAA5C;AAaA,IAAIC,MAAM,GAAG;EACXC,GAAG,EAAE;AADM,CAAb;;AAIA,MAAMC,eAAe,GAAIC,KAAD,IAAW;EAC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,KAArB,EAA4B/C,CAAC,EAA7B,EAAiC;IAC/BsC,UAAU;EACX;;EACDJ,IAAI,CAACK,mBAAL,CAAyBf,SAAzB;AACD,CALM;AAOP,OAAO,MAAMwB,UAAU,GAAG,YAAqB;EAAA,IAApBC,UAAoB,uEAAP,EAAO;EAC7C,IAAI9C,MAAJ;;EACA,IAAI;IACFA,MAAM,GAAG+C,OAAO,CAAC,QAAD,CAAhB;EACD,CAFD,CAEE,OAAOC,CAAP,EAAU;IACV;IACA,MAAM;MAAEhD,MAAM,EAAEiD;IAAV,IAA2BF,OAAO,CAAC,eAAD,CAAxC;;IACA/C,MAAM,GAAGiD,YAAT;EACD;;EAEDF,OAAO,CAAC,cAAD,CAAP;;EACA1B,SAAS,GAAGoB,IAAI,CAACS,KAAL,CAAW,OAAOxE,MAAM,CAACC,GAAzB,CAAZ;EAEAD,MAAM,GAAG,EACP,GAAGA,MADI;IAEP,GAAGoE;EAFI,CAAT;EAKA9C,MAAM,CAACmD,MAAP,CAAc;IACZC,mBAAmB,CAACjE,QAAD,EAAWsB,aAAX,EAAuC;MAAA,IAAb/B,MAAa,uEAAJ,EAAI;MACxD,OAAO8B,YAAY,CAACrB,QAAD,EAAWsB,aAAX,EAA0B/B,MAA1B,CAAnB;IACD;;EAHW,CAAd;AAKD,CAvBM;AAyBP,OAAO,MAAM2E,gBAAgB,GAAIlE,QAAD,IAAc;EAC5C,OAAOD,eAAe,CAACC,QAAD,CAAtB;AACD,CAFM"}
|
|
1
|
+
{"version":3,"names":["jestResetJsReanimatedModule","config","fps","isAnimatedStyle","style","animatedStyle","getAnimatedStyleFromObject","current","value","getCurrentStyle","received","styleObject","props","currentStyle","Array","isArray","forEach","checkEqual","expectStyle","length","i","property","findStyleDiff","expect","requireAllMatch","diffs","isEqual","push","Object","keys","undefined","compareStyle","expectedStyle","message","pass","exact","currentStyleStr","JSON","stringify","expectedStyleStr","differences","map","diff","join","frameTime","requestAnimationFrameCopy","currentTimestamp","requestAnimationFrame","callback","setTimeout","beforeTest","global","ReanimatedDataMock","now","jest","useFakeTimers","afterTest","useRealTimers","tickTravel","advanceTimersByTime","withReanimatedTimer","animationTest","advanceAnimationByTime","time","Math","ceil","advanceAnimationByFrame","count","setUpTests","userConfig","expectModule","require","jestGlobals","extend","default","round","toHaveAnimatedStyle","getAnimatedStyle"],"sources":["jestUtils.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\nimport { jestResetJsReanimatedModule } from './core';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace jest {\n interface Matchers<R> {\n toHaveAnimatedStyle(\n style: Record<string, unknown>[] | Record<string, unknown>\n ): R;\n }\n }\n}\n\nlet config = {\n fps: 60,\n};\n\nconst isAnimatedStyle = (style) => {\n return !!style.animatedStyle;\n};\n\nconst getAnimatedStyleFromObject = (style) => {\n return style.animatedStyle.current.value;\n};\n\nconst getCurrentStyle = (received) => {\n const styleObject = received.props.style;\n let currentStyle = {};\n if (Array.isArray(styleObject)) {\n received.props.style.forEach((style) => {\n if (isAnimatedStyle(style)) {\n currentStyle = {\n ...currentStyle,\n ...getAnimatedStyleFromObject(style),\n };\n } else {\n currentStyle = {\n ...currentStyle,\n ...style,\n };\n }\n });\n } else {\n if (isAnimatedStyle(styleObject)) {\n currentStyle = getAnimatedStyleFromObject(styleObject);\n } else {\n currentStyle = {\n ...styleObject,\n ...received.props.animatedStyle.value,\n };\n }\n }\n return currentStyle;\n};\n\nconst checkEqual = (currentStyle, expectStyle) => {\n if (Array.isArray(expectStyle)) {\n if (expectStyle.length !== currentStyle.length) return false;\n for (let i = 0; i < currentStyle.length; i++) {\n if (!checkEqual(currentStyle[i], expectStyle[i])) {\n return false;\n }\n }\n } else if (typeof currentStyle === 'object' && currentStyle) {\n for (const property in expectStyle) {\n if (!checkEqual(currentStyle[property], expectStyle[property])) {\n return false;\n }\n }\n } else {\n return currentStyle === expectStyle;\n }\n return true;\n};\n\nconst findStyleDiff = (current, expect, requireAllMatch) => {\n const diffs = [];\n let isEqual = true;\n for (const property in expect) {\n if (!checkEqual(current[property], expect[property])) {\n isEqual = false;\n diffs.push({\n property: property,\n current: current[property],\n expect: expect[property],\n });\n }\n }\n\n if (\n requireAllMatch &&\n Object.keys(current).length !== Object.keys(expect).length\n ) {\n isEqual = false;\n for (const property in current) {\n if (expect[property] === undefined) {\n diffs.push({\n property: property,\n current: current[property],\n expect: expect[property],\n });\n }\n }\n }\n\n return { isEqual, diffs };\n};\n\nconst compareStyle = (received, expectedStyle, config) => {\n if (!received.props.style) {\n return { message: () => message, pass: false };\n }\n const { exact } = config;\n const currentStyle = getCurrentStyle(received);\n const { isEqual, diffs } = findStyleDiff(currentStyle, expectedStyle, exact);\n\n if (isEqual) {\n return { message: () => 'ok', pass: true };\n }\n\n const currentStyleStr = JSON.stringify(currentStyle);\n const expectedStyleStr = JSON.stringify(expectedStyle);\n const differences = diffs\n .map(\n (diff) =>\n `- '${diff.property}' should be ${JSON.stringify(\n diff.expect\n )}, but is ${JSON.stringify(diff.current)}`\n )\n .join('\\n');\n\n return {\n message: () =>\n `Expected: ${expectedStyleStr}\\nReceived: ${currentStyleStr}\\n\\nDifferences:\\n${differences}`,\n pass: false,\n };\n};\n\nlet frameTime = 1000 / config.fps;\nlet requestAnimationFrameCopy;\nlet currentTimestamp = 0;\n\nconst requestAnimationFrame = (callback) => {\n setTimeout(callback, frameTime);\n};\n\nconst beforeTest = () => {\n jestResetJsReanimatedModule();\n requestAnimationFrameCopy = global.requestAnimationFrame;\n global.requestAnimationFrame = requestAnimationFrame;\n global.ReanimatedDataMock = {\n now: () => currentTimestamp,\n };\n currentTimestamp = 0;\n jest.useFakeTimers();\n};\n\nconst afterTest = () => {\n jest.useRealTimers();\n global.requestAnimationFrame = requestAnimationFrameCopy;\n};\n\nconst tickTravel = () => {\n currentTimestamp += frameTime;\n jest.advanceTimersByTime(frameTime);\n};\n\nexport const withReanimatedTimer = (animationTest) => {\n beforeTest();\n animationTest();\n afterTest();\n};\n\nexport const advanceAnimationByTime = (time = frameTime) => {\n for (let i = 0; i <= Math.ceil(time / frameTime); i++) {\n tickTravel();\n }\n jest.advanceTimersByTime(frameTime);\n};\n\nexport const advanceAnimationByFrame = (count) => {\n for (let i = 0; i <= count; i++) {\n tickTravel();\n }\n jest.advanceTimersByTime(frameTime);\n};\n\nexport const setUpTests = (userConfig = {}) => {\n let expect = global.expect;\n if (expect === undefined) {\n const expectModule = require('expect');\n expect = expectModule;\n // Starting from Jest 28, \"expect\" package uses named exports instead of default export.\n // So, requiring \"expect\" package doesn't give direct access to \"expect\" function anymore.\n // It gives access to the module object instead.\n // We use this info to detect if the project uses Jest 28 or higher.\n if (typeof expect === 'object') {\n const jestGlobals = require('@jest/globals');\n expect = jestGlobals.expect;\n }\n if (expect === undefined || expect.extend === undefined) {\n expect = expectModule.default;\n }\n }\n\n require('setimmediate');\n frameTime = Math.round(1000 / config.fps);\n\n config = {\n ...config,\n ...userConfig,\n };\n\n expect.extend({\n toHaveAnimatedStyle(received, expectedStyle, config = {}) {\n return compareStyle(received, expectedStyle, config);\n },\n });\n};\n\nexport const getAnimatedStyle = (received) => {\n return getCurrentStyle(received);\n};\n"],"mappings":"AAAA;AACA;AACA,SAASA,2BAAT,QAA4C,QAA5C;AAaA,IAAIC,MAAM,GAAG;EACXC,GAAG,EAAE;AADM,CAAb;;AAIA,MAAMC,eAAe,GAAIC,KAAD,IAAW;EACjC,OAAO,CAAC,CAACA,KAAK,CAACC,aAAf;AACD,CAFD;;AAIA,MAAMC,0BAA0B,GAAIF,KAAD,IAAW;EAC5C,OAAOA,KAAK,CAACC,aAAN,CAAoBE,OAApB,CAA4BC,KAAnC;AACD,CAFD;;AAIA,MAAMC,eAAe,GAAIC,QAAD,IAAc;EACpC,MAAMC,WAAW,GAAGD,QAAQ,CAACE,KAAT,CAAeR,KAAnC;EACA,IAAIS,YAAY,GAAG,EAAnB;;EACA,IAAIC,KAAK,CAACC,OAAN,CAAcJ,WAA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,GAAG+C,YAAT,CAFwB,CAGxB;IACA;IACA;IACA;;IACA,IAAI,OAAO/C,MAAP,KAAkB,QAAtB,EAAgC;MAC9B,MAAMiD,WAAW,GAAGD,OAAO,CAAC,eAAD,CAA3B;;MACAhD,MAAM,GAAGiD,WAAW,CAACjD,MAArB;IACD;;IACD,IAAIA,MAAM,KAAKO,SAAX,IAAwBP,MAAM,CAACkD,MAAP,KAAkB3C,SAA9C,EAAyD;MACvDP,MAAM,GAAG+C,YAAY,CAACI,OAAtB;IACD;EACF;;EAEDH,OAAO,CAAC,cAAD,CAAP;;EACA3B,SAAS,GAAGoB,IAAI,CAACW,KAAL,CAAW,OAAO1E,MAAM,CAACC,GAAzB,CAAZ;EAEAD,MAAM,GAAG,EACP,GAAGA,MADI;IAEP,GAAGoE;EAFI,CAAT;EAKA9C,MAAM,CAACkD,MAAP,CAAc;IACZG,mBAAmB,CAAClE,QAAD,EAAWsB,aAAX,EAAuC;MAAA,IAAb/B,MAAa,uEAAJ,EAAI;MACxD,OAAO8B,YAAY,CAACrB,QAAD,EAAWsB,aAAX,EAA0B/B,MAA1B,CAAnB;IACD;;EAHW,CAAd;AAKD,CA/BM;AAiCP,OAAO,MAAM4E,gBAAgB,GAAInE,QAAD,IAAc;EAC5C,OAAOD,eAAe,CAACC,QAAD,CAAtB;AACD,CAFM"}
|
|
@@ -1,89 +1,50 @@
|
|
|
1
1
|
/* global _stopObservingProgress, _startObservingProgress */
|
|
2
2
|
import { runOnUI } from '../core';
|
|
3
3
|
import { withStyleAnimation } from '../animation/styleAnimation';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import { LogBox } from 'react-native';
|
|
5
|
+
LogBox.ignoreLogs(['Overriding previous layout animation with']);
|
|
6
6
|
runOnUI(() => {
|
|
7
7
|
'worklet';
|
|
8
8
|
|
|
9
|
-
const configs = Object.create(null);
|
|
10
9
|
const enteringAnimationForTag = {};
|
|
11
10
|
global.LayoutAnimationRepository = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
registerConfig(tag, config) {
|
|
15
|
-
configs[tag] = config;
|
|
16
|
-
enteringAnimationForTag[tag] = null;
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
removeConfig(tag) {
|
|
20
|
-
delete configs[tag];
|
|
21
|
-
delete enteringAnimationForTag[tag];
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
startAnimationForTag(tag, type, yogaValues) {
|
|
25
|
-
if (configs[tag] == null) {
|
|
26
|
-
return; // :(
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const style = configs[tag][type](yogaValues);
|
|
11
|
+
startAnimationForTag(tag, type, yogaValues, config, viewSharedValue) {
|
|
12
|
+
const style = config(yogaValues);
|
|
30
13
|
let currentAnimation = style.animations;
|
|
31
14
|
|
|
32
15
|
if (type === 'entering') {
|
|
33
|
-
enteringAnimationForTag[tag] =
|
|
34
|
-
} else if (type === 'layout'
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
currentAnimation
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
for (const key in layoutAnimation) {
|
|
44
|
-
currentAnimation[key] = layoutAnimation[key];
|
|
16
|
+
enteringAnimationForTag[tag] = currentAnimation;
|
|
17
|
+
} else if (type === 'layout') {
|
|
18
|
+
// When layout animation is requested, but entering is still running, we merge
|
|
19
|
+
// new layout animation targets into the ongoing animation
|
|
20
|
+
const enteringAnimation = enteringAnimationForTag[tag];
|
|
21
|
+
|
|
22
|
+
if (enteringAnimation) {
|
|
23
|
+
currentAnimation = { ...enteringAnimation,
|
|
24
|
+
...style.animations
|
|
25
|
+
};
|
|
45
26
|
}
|
|
46
27
|
}
|
|
47
28
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
_stopObservingProgress(tag, false);
|
|
51
|
-
|
|
52
|
-
_startObservingProgress(tag, sv);
|
|
53
|
-
|
|
54
|
-
const backupColor = {};
|
|
55
|
-
|
|
56
|
-
for (const key in style.initialValues) {
|
|
57
|
-
if (ColorProperties.includes(key)) {
|
|
58
|
-
const value = style.initialValues[key];
|
|
59
|
-
backupColor[key] = value;
|
|
60
|
-
style.initialValues[key] = processColor(value);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
sv.value = Object.assign({}, sv._value, style.initialValues);
|
|
65
|
-
|
|
66
|
-
_stopObservingProgress(tag, false);
|
|
29
|
+
_stopObservingProgress(tag, false, false);
|
|
67
30
|
|
|
31
|
+
viewSharedValue._value = Object.assign({}, viewSharedValue._value, style.initialValues);
|
|
68
32
|
const animation = withStyleAnimation(currentAnimation);
|
|
69
33
|
|
|
70
34
|
animation.callback = finished => {
|
|
71
35
|
if (finished) {
|
|
72
|
-
|
|
36
|
+
delete enteringAnimationForTag[tag];
|
|
37
|
+
const shouldRemoveView = type === 'exiting';
|
|
38
|
+
|
|
39
|
+
_stopObservingProgress(tag, finished, shouldRemoveView);
|
|
73
40
|
}
|
|
74
41
|
|
|
75
42
|
style.callback && style.callback(finished);
|
|
76
43
|
};
|
|
77
44
|
|
|
78
|
-
|
|
79
|
-
configs[tag].sv._value = { ...configs[tag].sv.value,
|
|
80
|
-
...backupColor
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
configs[tag].sv.value = animation;
|
|
45
|
+
viewSharedValue.value = animation;
|
|
85
46
|
|
|
86
|
-
_startObservingProgress(tag,
|
|
47
|
+
_startObservingProgress(tag, viewSharedValue, type);
|
|
87
48
|
}
|
|
88
49
|
|
|
89
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["runOnUI","withStyleAnimation","
|
|
1
|
+
{"version":3,"names":["runOnUI","withStyleAnimation","LogBox","ignoreLogs","enteringAnimationForTag","global","LayoutAnimationRepository","startAnimationForTag","tag","type","yogaValues","config","viewSharedValue","style","currentAnimation","animations","enteringAnimation","_stopObservingProgress","_value","Object","assign","initialValues","animation","callback","finished","shouldRemoveView","value","_startObservingProgress"],"sources":["LayoutAnimationRepository.ts"],"sourcesContent":["/* global _stopObservingProgress, _startObservingProgress */\nimport { runOnUI } from '../core';\nimport { withStyleAnimation } from '../animation/styleAnimation';\nimport { LogBox } from 'react-native';\n\nLogBox.ignoreLogs(['Overriding previous layout animation with']);\n\nrunOnUI(() => {\n 'worklet';\n\n const enteringAnimationForTag: Record<string, any> = {};\n\n global.LayoutAnimationRepository = {\n startAnimationForTag(tag, type, yogaValues, config, viewSharedValue) {\n const style = config(yogaValues);\n let currentAnimation = style.animations;\n\n if (type === 'entering') {\n enteringAnimationForTag[tag] = currentAnimation;\n } else if (type === 'layout') {\n // When layout animation is requested, but entering is still running, we merge\n // new layout animation targets into the ongoing animation\n const enteringAnimation = enteringAnimationForTag[tag];\n if (enteringAnimation) {\n currentAnimation = { ...enteringAnimation, ...style.animations };\n }\n }\n _stopObservingProgress(tag, false, false);\n viewSharedValue._value = Object.assign(\n {},\n viewSharedValue._value,\n style.initialValues\n );\n const animation = withStyleAnimation(currentAnimation);\n\n animation.callback = (finished?: boolean) => {\n if (finished) {\n delete enteringAnimationForTag[tag];\n const shouldRemoveView = type === 'exiting';\n _stopObservingProgress(tag, finished, shouldRemoveView);\n }\n style.callback && style.callback(finished);\n };\n\n viewSharedValue.value = animation;\n _startObservingProgress(tag, viewSharedValue, type);\n },\n };\n})();\n"],"mappings":"AAAA;AACA,SAASA,OAAT,QAAwB,SAAxB;AACA,SAASC,kBAAT,QAAmC,6BAAnC;AACA,SAASC,MAAT,QAAuB,cAAvB;AAEAA,MAAM,CAACC,UAAP,CAAkB,CAAC,2CAAD,CAAlB;AAEAH,OAAO,CAAC,MAAM;EACZ;;EAEA,MAAMI,uBAA4C,GAAG,EAArD;EAEAC,MAAM,CAACC,yBAAP,GAAmC;IACjCC,oBAAoB,CAACC,GAAD,EAAMC,IAAN,EAAYC,UAAZ,EAAwBC,MAAxB,EAAgCC,eAAhC,EAAiD;MACnE,MAAMC,KAAK,GAAGF,MAAM,CAAC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
|
+
"version": "3.0.0-rc.6",
|
|
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",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"madge": "^5.0.1",
|
|
124
124
|
"prettier": "^2.5.1",
|
|
125
125
|
"react": "17.0.2",
|
|
126
|
-
"react-native": "0.70.
|
|
126
|
+
"react-native": "0.70.5",
|
|
127
127
|
"react-native-builder-bob": "^0.18.3",
|
|
128
128
|
"react-native-codegen": "^0.0.7",
|
|
129
129
|
"react-native-gesture-handler": "^2.4.2",
|
|
@@ -8,14 +8,10 @@ import { adaptViewConfig } from './ConfigHelper';
|
|
|
8
8
|
import { RNRenderer } from './reanimated2/platform-specific/RNRenderer';
|
|
9
9
|
import {
|
|
10
10
|
makeMutable,
|
|
11
|
-
|
|
11
|
+
configureLayoutAnimations,
|
|
12
12
|
enableLayoutAnimations,
|
|
13
|
+
runOnUI,
|
|
13
14
|
} from './reanimated2/core';
|
|
14
|
-
import {
|
|
15
|
-
DefaultEntering,
|
|
16
|
-
DefaultExiting,
|
|
17
|
-
DefaultLayout,
|
|
18
|
-
} from './reanimated2/layoutReanimation/defaultAnimations/Default';
|
|
19
15
|
import {
|
|
20
16
|
isJest,
|
|
21
17
|
isChromeDebugger,
|
|
@@ -26,6 +22,7 @@ import {
|
|
|
26
22
|
BaseAnimationBuilder,
|
|
27
23
|
EntryExitAnimationFunction,
|
|
28
24
|
ILayoutAnimationBuilder,
|
|
25
|
+
LayoutAnimationFunction,
|
|
29
26
|
} from './reanimated2/layoutReanimation';
|
|
30
27
|
import {
|
|
31
28
|
SharedValue,
|
|
@@ -43,6 +40,25 @@ function dummyListener() {
|
|
|
43
40
|
// event is used.
|
|
44
41
|
}
|
|
45
42
|
|
|
43
|
+
function maybeBuild(
|
|
44
|
+
layoutAnimationOrBuilder:
|
|
45
|
+
| ILayoutAnimationBuilder
|
|
46
|
+
| LayoutAnimationFunction
|
|
47
|
+
| Keyframe
|
|
48
|
+
): LayoutAnimationFunction | Keyframe {
|
|
49
|
+
const isAnimationBuilder = (
|
|
50
|
+
value: ILayoutAnimationBuilder | LayoutAnimationFunction | Keyframe
|
|
51
|
+
): value is ILayoutAnimationBuilder =>
|
|
52
|
+
'build' in layoutAnimationOrBuilder &&
|
|
53
|
+
typeof layoutAnimationOrBuilder.build === 'function';
|
|
54
|
+
|
|
55
|
+
if (isAnimationBuilder(layoutAnimationOrBuilder)) {
|
|
56
|
+
return layoutAnimationOrBuilder.build();
|
|
57
|
+
} else {
|
|
58
|
+
return layoutAnimationOrBuilder;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
46
62
|
type NestedArray<T> = T | NestedArray<T>[];
|
|
47
63
|
function flattenArray<T>(array: NestedArray<T>): T[] {
|
|
48
64
|
if (!Array.isArray(array)) {
|
|
@@ -399,42 +415,35 @@ export default function createAnimatedComponent(
|
|
|
399
415
|
setLocalRef: (ref) => {
|
|
400
416
|
// TODO update config
|
|
401
417
|
const tag = findNodeHandle(ref);
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
(
|
|
405
|
-
|
|
406
|
-
) {
|
|
407
|
-
enableLayoutAnimations(true, false);
|
|
408
|
-
let layout = this.props.layout ? this.props.layout : DefaultLayout;
|
|
409
|
-
let entering = this.props.entering
|
|
410
|
-
? this.props.entering
|
|
411
|
-
: DefaultEntering;
|
|
412
|
-
let exiting = this.props.exiting
|
|
413
|
-
? this.props.exiting
|
|
414
|
-
: DefaultExiting;
|
|
415
|
-
|
|
416
|
-
if (has('build', layout)) {
|
|
417
|
-
layout = layout.build();
|
|
418
|
+
const { layout, entering, exiting } = this.props;
|
|
419
|
+
if ((layout || entering || exiting) && tag != null) {
|
|
420
|
+
if (!shouldBeUseWeb()) {
|
|
421
|
+
enableLayoutAnimations(true, false);
|
|
418
422
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
423
|
+
if (layout) {
|
|
424
|
+
configureLayoutAnimations(
|
|
425
|
+
tag,
|
|
426
|
+
'layout',
|
|
427
|
+
maybeBuild(layout),
|
|
428
|
+
this.sv
|
|
429
|
+
);
|
|
422
430
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
431
|
+
if (entering) {
|
|
432
|
+
configureLayoutAnimations(
|
|
433
|
+
tag,
|
|
434
|
+
'entering',
|
|
435
|
+
maybeBuild(entering),
|
|
436
|
+
this.sv
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
if (exiting) {
|
|
440
|
+
configureLayoutAnimations(
|
|
441
|
+
tag,
|
|
442
|
+
'exiting',
|
|
443
|
+
maybeBuild(exiting),
|
|
444
|
+
this.sv
|
|
445
|
+
);
|
|
426
446
|
}
|
|
427
|
-
|
|
428
|
-
const config = {
|
|
429
|
-
layout,
|
|
430
|
-
entering,
|
|
431
|
-
exiting,
|
|
432
|
-
sv: this.sv,
|
|
433
|
-
};
|
|
434
|
-
runOnUI(() => {
|
|
435
|
-
'worklet';
|
|
436
|
-
global.LayoutAnimationRepository.registerConfig(tag, config);
|
|
437
|
-
})();
|
|
438
447
|
}
|
|
439
448
|
|
|
440
449
|
if (ref !== this._component) {
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
AnimatedKeyboardInfo,
|
|
7
7
|
} from '../commonTypes';
|
|
8
8
|
import { Descriptor } from '../hook/commonTypes';
|
|
9
|
+
import { LayoutAnimationFunction } from '../layoutReanimation';
|
|
9
10
|
|
|
10
11
|
export class NativeReanimated {
|
|
11
12
|
native: boolean;
|
|
@@ -91,6 +92,20 @@ export class NativeReanimated {
|
|
|
91
92
|
return this.InnerNativeModule.getViewProp(viewTag, propName, callback);
|
|
92
93
|
}
|
|
93
94
|
|
|
95
|
+
configureLayoutAnimation(
|
|
96
|
+
viewTag: number,
|
|
97
|
+
type: string,
|
|
98
|
+
config: Keyframe | LayoutAnimationFunction,
|
|
99
|
+
viewSharedValue: SharedValue<null | Record<string, unknown>> | null
|
|
100
|
+
) {
|
|
101
|
+
this.InnerNativeModule.configureLayoutAnimation(
|
|
102
|
+
viewTag,
|
|
103
|
+
type,
|
|
104
|
+
config,
|
|
105
|
+
viewSharedValue
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
94
109
|
enableLayoutAnimations(flag: boolean): void {
|
|
95
110
|
this.InnerNativeModule.enableLayoutAnimations(flag);
|
|
96
111
|
}
|
package/src/reanimated2/core.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from './commonTypes';
|
|
13
13
|
import { Descriptor } from './hook/commonTypes';
|
|
14
14
|
import JSReanimated from './js-reanimated/JSReanimated';
|
|
15
|
+
import { LayoutAnimationFunction } from './layoutReanimation';
|
|
15
16
|
|
|
16
17
|
if (global._setGlobalConsole === undefined) {
|
|
17
18
|
// it can happen when Reanimated plugin wasn't added, but the user uses the only API from version 1
|
|
@@ -178,7 +179,8 @@ function workletValueSetter<T extends WorkletValue>(
|
|
|
178
179
|
const initializeAnimation = (timestamp: number) => {
|
|
179
180
|
animation.onStart(animation, this.value, timestamp, previousAnimation);
|
|
180
181
|
};
|
|
181
|
-
|
|
182
|
+
const currentTimestamp = getTimestamp();
|
|
183
|
+
initializeAnimation(currentTimestamp);
|
|
182
184
|
const step = (timestamp: number) => {
|
|
183
185
|
if (animation.cancelled) {
|
|
184
186
|
animation.callback && animation.callback(false /* finished */);
|
|
@@ -196,13 +198,7 @@ function workletValueSetter<T extends WorkletValue>(
|
|
|
196
198
|
};
|
|
197
199
|
|
|
198
200
|
this._animation = animation;
|
|
199
|
-
|
|
200
|
-
if (_frameTimestamp) {
|
|
201
|
-
// frame
|
|
202
|
-
step(_frameTimestamp);
|
|
203
|
-
} else {
|
|
204
|
-
requestAnimationFrame(step);
|
|
205
|
-
}
|
|
201
|
+
step(currentTimestamp);
|
|
206
202
|
} else {
|
|
207
203
|
// prevent setting again to the same value
|
|
208
204
|
// and triggering the mappers that treat this value as an input
|
|
@@ -260,8 +256,7 @@ function workletValueSetterJS<T extends WorkletValue>(
|
|
|
260
256
|
};
|
|
261
257
|
|
|
262
258
|
this._animation = animation;
|
|
263
|
-
|
|
264
|
-
requestFrame(step);
|
|
259
|
+
step(getTimestamp());
|
|
265
260
|
} else {
|
|
266
261
|
this._setValue && this._setValue(value as AnimatableValue | Descriptor);
|
|
267
262
|
}
|
|
@@ -371,6 +366,20 @@ export function enableLayoutAnimations(
|
|
|
371
366
|
}
|
|
372
367
|
}
|
|
373
368
|
|
|
369
|
+
export function configureLayoutAnimations(
|
|
370
|
+
viewTag: number,
|
|
371
|
+
type: string,
|
|
372
|
+
config: LayoutAnimationFunction | Keyframe,
|
|
373
|
+
viewSharedValue: SharedValue<null | Record<string, unknown>> | null
|
|
374
|
+
): void {
|
|
375
|
+
NativeReanimatedModule.configureLayoutAnimation(
|
|
376
|
+
viewTag,
|
|
377
|
+
type,
|
|
378
|
+
config,
|
|
379
|
+
viewSharedValue
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
|
|
374
383
|
export function configureProps(uiProps: string[], nativeProps: string[]): void {
|
|
375
384
|
if (!nativeShouldBeMock()) {
|
|
376
385
|
NativeReanimatedModule.configureProps(uiProps, nativeProps);
|
|
@@ -17,10 +17,15 @@ declare global {
|
|
|
17
17
|
const _setGlobalConsole: (console?: ReanimatedConsole) => void;
|
|
18
18
|
const _log: (s: string) => void;
|
|
19
19
|
const _getCurrentTime: () => number;
|
|
20
|
-
const _stopObservingProgress: (
|
|
20
|
+
const _stopObservingProgress: (
|
|
21
|
+
tag: number,
|
|
22
|
+
cancelled: boolean,
|
|
23
|
+
removeView: boolean
|
|
24
|
+
) => void;
|
|
21
25
|
const _startObservingProgress: (
|
|
22
26
|
tag: number,
|
|
23
|
-
|
|
27
|
+
viewSharedValue: { value: unknown; _value: unknown },
|
|
28
|
+
type: string
|
|
24
29
|
) => void;
|
|
25
30
|
const _setGestureState: (handlerTag: number, newState: number) => void;
|
|
26
31
|
const _updatePropsPaper: (
|
|
@@ -103,13 +108,12 @@ declare global {
|
|
|
103
108
|
_chronoNow: () => number;
|
|
104
109
|
performance: { now: () => number };
|
|
105
110
|
LayoutAnimationRepository: {
|
|
106
|
-
configs: Record<string, unknown>;
|
|
107
|
-
registerConfig(tag: number, config: Record<string, unknown>): void;
|
|
108
|
-
removeConfig(tag: number): void;
|
|
109
111
|
startAnimationForTag(
|
|
110
112
|
tag: number,
|
|
111
113
|
type: string,
|
|
112
|
-
yogaValues:
|
|
114
|
+
yogaValues: Record<string, number>,
|
|
115
|
+
config: LayoutAnimationFunction | Keyframe,
|
|
116
|
+
viewSharedValue: { value: unknown; _value: unknown }
|
|
113
117
|
): void;
|
|
114
118
|
};
|
|
115
119
|
ReanimatedDataMock: {
|