react-native-reanimated 3.0.0-rc.7 → 3.0.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Common/cpp/AnimatedSensor/AnimatedSensorModule.cpp +32 -37
- package/Common/cpp/AnimatedSensor/AnimatedSensorModule.h +4 -3
- package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.cpp +76 -0
- package/Common/cpp/LayoutAnimations/LayoutAnimationsManager.h +41 -0
- package/Common/cpp/NativeModules/NativeReanimatedModule.cpp +161 -165
- package/Common/cpp/NativeModules/NativeReanimatedModule.h +36 -34
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.cpp +22 -34
- package/Common/cpp/NativeModules/NativeReanimatedModuleSpec.h +13 -14
- package/Common/cpp/SharedItems/RuntimeManager.h +1 -34
- package/Common/cpp/SharedItems/Shareables.cpp +142 -0
- package/Common/cpp/SharedItems/Shareables.h +455 -0
- package/Common/cpp/Tools/PlatformDepMethodsHolder.h +6 -0
- package/Common/cpp/Tools/RuntimeDecorator.cpp +54 -26
- package/Common/cpp/Tools/RuntimeDecorator.h +11 -2
- package/Common/cpp/Tools/Scheduler.cpp +10 -0
- package/Common/cpp/Tools/SingleInstanceChecker.h +1 -1
- package/android/src/main/cpp/LayoutAnimations.cpp +6 -16
- package/android/src/main/cpp/LayoutAnimations.h +4 -4
- package/android/src/main/cpp/NativeProxy.cpp +50 -63
- package/ios/native/NativeProxy.mm +26 -42
- package/lib/commonjs/createAnimatedComponent.js +7 -11
- package/lib/commonjs/createAnimatedComponent.js.map +1 -1
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
- package/lib/commonjs/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/ViewDescriptorsSet.js +27 -55
- package/lib/commonjs/reanimated2/ViewDescriptorsSet.js.map +1 -1
- package/lib/commonjs/reanimated2/WorkletEventHandler.js +5 -3
- package/lib/commonjs/reanimated2/WorkletEventHandler.js.map +1 -1
- package/lib/commonjs/reanimated2/animation/util.js.map +1 -1
- package/lib/commonjs/reanimated2/commonTypes.js +7 -0
- package/lib/commonjs/reanimated2/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/core.js +111 -209
- package/lib/commonjs/reanimated2/core.js.map +1 -1
- package/lib/commonjs/reanimated2/globals.d.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js +15 -9
- package/lib/commonjs/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js +18 -8
- package/lib/commonjs/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js +27 -36
- package/lib/commonjs/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js +24 -50
- package/lib/commonjs/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/useSharedValue.js +3 -2
- package/lib/commonjs/reanimated2/hook/useSharedValue.js.map +1 -1
- package/lib/commonjs/reanimated2/hook/utils.js.map +1 -1
- package/lib/commonjs/reanimated2/interpolateColor.js.map +1 -1
- package/lib/commonjs/reanimated2/jestUtils.js +8 -33
- package/lib/commonjs/reanimated2/jestUtils.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js +16 -100
- package/lib/commonjs/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/commonjs/reanimated2/js-reanimated/index.js +5 -0
- package/lib/commonjs/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js +91 -0
- package/lib/commonjs/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
- package/lib/commonjs/reanimated2/layoutReanimation/index.js +1 -1
- package/lib/commonjs/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/commonjs/reanimated2/mappers.js +186 -0
- package/lib/commonjs/reanimated2/mappers.js.map +1 -0
- package/lib/commonjs/reanimated2/mutables.js +173 -0
- package/lib/commonjs/reanimated2/mutables.js.map +1 -0
- package/lib/commonjs/reanimated2/shareables.js +153 -0
- package/lib/commonjs/reanimated2/shareables.js.map +1 -0
- package/lib/commonjs/reanimated2/threads.js +58 -0
- package/lib/commonjs/reanimated2/threads.js.map +1 -0
- package/lib/commonjs/reanimated2/time.js +55 -0
- package/lib/commonjs/reanimated2/time.js.map +1 -0
- package/lib/commonjs/reanimated2/valueSetter.js +81 -0
- package/lib/commonjs/reanimated2/valueSetter.js.map +1 -0
- package/lib/module/createAnimatedComponent.js +7 -12
- package/lib/module/createAnimatedComponent.js.map +1 -1
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js +24 -25
- package/lib/module/reanimated2/NativeReanimated/NativeReanimated.js.map +1 -1
- package/lib/module/reanimated2/ViewDescriptorsSet.js +27 -53
- package/lib/module/reanimated2/ViewDescriptorsSet.js.map +1 -1
- package/lib/module/reanimated2/WorkletEventHandler.js +4 -3
- package/lib/module/reanimated2/WorkletEventHandler.js.map +1 -1
- package/lib/module/reanimated2/animation/util.js.map +1 -1
- package/lib/module/reanimated2/commonTypes.js +7 -0
- package/lib/module/reanimated2/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/core.js +66 -188
- package/lib/module/reanimated2/core.js.map +1 -1
- package/lib/module/reanimated2/globals.d.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js +16 -6
- package/lib/module/reanimated2/hook/useAnimatedKeyboard.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedRef.js +17 -8
- package/lib/module/reanimated2/hook/useAnimatedRef.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedSensor.js +29 -34
- package/lib/module/reanimated2/hook/useAnimatedSensor.js.map +1 -1
- package/lib/module/reanimated2/hook/useAnimatedStyle.js +26 -52
- package/lib/module/reanimated2/hook/useAnimatedStyle.js.map +1 -1
- package/lib/module/reanimated2/hook/useSharedValue.js +3 -2
- package/lib/module/reanimated2/hook/useSharedValue.js.map +1 -1
- package/lib/module/reanimated2/hook/utils.js.map +1 -1
- package/lib/module/reanimated2/interpolateColor.js.map +1 -1
- package/lib/module/reanimated2/jestUtils.js +8 -31
- package/lib/module/reanimated2/jestUtils.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js +16 -95
- package/lib/module/reanimated2/js-reanimated/JSReanimated.js.map +1 -1
- package/lib/module/reanimated2/js-reanimated/index.js +5 -0
- package/lib/module/reanimated2/js-reanimated/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/commonTypes.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationBuilder/index.js.map +1 -1
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js +84 -0
- package/lib/module/reanimated2/layoutReanimation/animationsManager.js.map +1 -0
- package/lib/module/reanimated2/layoutReanimation/index.js +1 -1
- package/lib/module/reanimated2/layoutReanimation/index.js.map +1 -1
- package/lib/module/reanimated2/mappers.js +173 -0
- package/lib/module/reanimated2/mappers.js.map +1 -0
- package/lib/module/reanimated2/mutables.js +149 -0
- package/lib/module/reanimated2/mutables.js.map +1 -0
- package/lib/module/reanimated2/shareables.js +133 -0
- package/lib/module/reanimated2/shareables.js.map +1 -0
- package/lib/module/reanimated2/threads.js +45 -0
- package/lib/module/reanimated2/threads.js.map +1 -0
- package/lib/module/reanimated2/time.js +37 -0
- package/lib/module/reanimated2/time.js.map +1 -0
- package/lib/module/reanimated2/valueSetter.js +66 -0
- package/lib/module/reanimated2/valueSetter.js.map +1 -0
- package/package.json +1 -1
- package/plugin.js +31 -15
- package/src/createAnimatedComponent.tsx +8 -24
- package/src/reanimated2/NativeReanimated/NativeReanimated.ts +34 -53
- package/src/reanimated2/ViewDescriptorsSet.ts +30 -69
- package/src/reanimated2/WorkletEventHandler.ts +4 -11
- package/src/reanimated2/animation/util.ts +1 -0
- package/src/reanimated2/commonTypes.ts +29 -4
- package/src/reanimated2/core.ts +103 -230
- package/src/reanimated2/globals.d.ts +26 -26
- package/src/reanimated2/hook/useAnimatedKeyboard.ts +18 -9
- package/src/reanimated2/hook/useAnimatedRef.ts +27 -9
- package/src/reanimated2/hook/useAnimatedSensor.ts +33 -31
- package/src/reanimated2/hook/useAnimatedStyle.ts +26 -64
- package/src/reanimated2/hook/useSharedValue.ts +6 -3
- package/src/reanimated2/hook/utils.ts +1 -1
- package/src/reanimated2/interpolateColor.ts +2 -2
- package/src/reanimated2/jestUtils.ts +14 -29
- package/src/reanimated2/js-reanimated/JSReanimated.ts +19 -93
- package/src/reanimated2/js-reanimated/index.ts +4 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/commonTypes.ts +7 -0
- package/src/reanimated2/layoutReanimation/animationBuilder/index.ts +1 -0
- package/src/reanimated2/layoutReanimation/animationsManager.ts +94 -0
- package/src/reanimated2/layoutReanimation/index.ts +1 -1
- package/src/reanimated2/mappers.ts +179 -0
- package/src/reanimated2/mutables.ts +151 -0
- package/src/reanimated2/shareables.ts +121 -0
- package/src/reanimated2/threads.ts +46 -0
- package/src/reanimated2/time.ts +30 -0
- package/src/reanimated2/valueSetter.ts +64 -0
- package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.cpp +0 -127
- package/Common/cpp/LayoutAnimations/LayoutAnimationsProxy.h +0 -56
- package/Common/cpp/Registries/MapperRegistry.cpp +0 -147
- package/Common/cpp/Registries/MapperRegistry.h +0 -29
- package/Common/cpp/Registries/WorkletsCache.cpp +0 -45
- package/Common/cpp/Registries/WorkletsCache.h +0 -24
- package/Common/cpp/SharedItems/FrozenObject.cpp +0 -35
- package/Common/cpp/SharedItems/FrozenObject.h +0 -36
- package/Common/cpp/SharedItems/HostFunctionHandler.h +0 -28
- package/Common/cpp/SharedItems/MutableValue.cpp +0 -134
- package/Common/cpp/SharedItems/MutableValue.h +0 -54
- package/Common/cpp/SharedItems/MutableValueSetterProxy.cpp +0 -47
- package/Common/cpp/SharedItems/MutableValueSetterProxy.h +0 -25
- package/Common/cpp/SharedItems/RemoteObject.cpp +0 -45
- package/Common/cpp/SharedItems/RemoteObject.h +0 -35
- package/Common/cpp/SharedItems/ShareableValue.cpp +0 -529
- package/Common/cpp/SharedItems/ShareableValue.h +0 -63
- package/Common/cpp/SharedItems/ValueWrapper.h +0 -183
- package/Common/cpp/Tools/JSIStoreValueUser.cpp +0 -55
- package/Common/cpp/Tools/JSIStoreValueUser.h +0 -37
- package/Common/cpp/Tools/Mapper.cpp +0 -86
- package/Common/cpp/Tools/Mapper.h +0 -51
- package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -58
- package/lib/commonjs/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
- package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js +0 -52
- package/lib/module/reanimated2/layoutReanimation/LayoutAnimationRepository.js.map +0 -1
- package/src/reanimated2/layoutReanimation/LayoutAnimationRepository.ts +0 -49
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useRef","processColor","makeRemote","isWeb","isJest","colorProps","WorkletEventHandler","useEvent","handler","eventNames","rebuild","initRef","current","updateWorklet","useHandler","handlers","dependencies","context","savedDependencies","buildDependencies","doDependenciesDiffer","areDependenciesEqual","useWeb","buildWorkletsHash","Object","values","reduce","acc","worklet","__workletHash","toString","handlersList","filter","undefined","map","workletHash","closure","_closure","push","nextDeps","prevDeps","is","x","y","objectIs","areHookInputsEqual","length","i","hasColorProps","updates","colorPropsSet","Set","key","has","parseColors","indexOf","processedColor","canApplyOptimalisation","upadterFn","FUNCTIONLESS_FLAG","STATEMENTLESS_FLAG","optimalization","__optimalization","isAnimated","prop","propsToCheck","currentProp","pop","Array","isArray","item","onFrame","styleDiff","oldStyle","newStyle","diff","value","oldValue","getStyleWithoutAnimations","validateAnimatedStyles","styles","Error"],"sources":["utils.ts"],"sourcesContent":["import { MutableRefObject, useEffect, useRef } from 'react';\nimport { processColor } from '../Colors';\nimport {\n AnimatedStyle,\n Context,\n NativeEvent,\n NestedObjectValues,\n StyleProps,\n WorkletFunction,\n AnimationObject,\n} from '../commonTypes';\nimport { makeRemote } from '../core';\nimport { isWeb, isJest } from '../PlatformChecker';\nimport { colorProps } from '../UpdateProps';\nimport WorkletEventHandler from '../WorkletEventHandler';\nimport { ContextWithDependencies, DependencyList } from './commonTypes';\n\ninterface Handler<T, TContext extends Context> extends WorkletFunction {\n (event: T, context: TContext): void;\n}\n\ninterface Handlers<T, TContext extends Context> {\n [key: string]: Handler<T, TContext> | undefined;\n}\n\nexport interface UseHandlerContext<TContext extends Context> {\n context: TContext;\n doDependenciesDiffer: boolean;\n useWeb: boolean;\n}\n\nexport function useEvent<T extends NativeEvent<T>>(\n handler: (event: T) => void,\n eventNames: string[] = [],\n rebuild = false\n): MutableRefObject<WorkletEventHandler<T> | null> {\n const initRef = useRef<WorkletEventHandler<T> | null>(null);\n if (initRef.current === null) {\n initRef.current = new WorkletEventHandler(handler, eventNames);\n } else if (rebuild) {\n initRef.current.updateWorklet(handler);\n }\n\n return initRef;\n}\n\nexport function useHandler<T, TContext extends Context>(\n handlers: Handlers<T, TContext>,\n dependencies?: DependencyList\n): UseHandlerContext<TContext> {\n const initRef = useRef<ContextWithDependencies<TContext> | null>(null);\n if (initRef.current === null) {\n initRef.current = {\n context: makeRemote({}),\n savedDependencies: [],\n };\n }\n\n useEffect(() => {\n return () => {\n initRef.current = null;\n };\n }, []);\n\n const { context, savedDependencies } = initRef.current;\n\n dependencies = buildDependencies(dependencies, handlers);\n\n const doDependenciesDiffer = !areDependenciesEqual(\n dependencies,\n savedDependencies\n );\n initRef.current.savedDependencies = dependencies;\n const useWeb = isWeb() || isJest();\n\n return { context, doDependenciesDiffer, useWeb };\n}\n\n// builds one big hash from multiple worklets' hashes\nexport function buildWorkletsHash(\n handlers: Record<string, WorkletFunction> | Array<WorkletFunction>\n): string {\n return Object.values(handlers).reduce(\n (acc: string, worklet: WorkletFunction) =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n acc + worklet.__workletHash!.toString(),\n ''\n );\n}\n\n// builds dependencies array for gesture handlers\nexport function buildDependencies(\n dependencies: DependencyList,\n handlers: Record<string, WorkletFunction | undefined>\n): Array<unknown> {\n const handlersList: WorkletFunction[] = Object.values(handlers).filter(\n (handler) => handler !== undefined\n ) as WorkletFunction[];\n if (!dependencies) {\n dependencies = handlersList.map((handler) => {\n return {\n workletHash: handler.__workletHash,\n closure: handler._closure,\n };\n });\n } else {\n dependencies.push(buildWorkletsHash(handlersList));\n }\n return dependencies;\n}\n\n// this is supposed to work as useEffect comparison\nexport function areDependenciesEqual(\n nextDeps: DependencyList,\n prevDeps: DependencyList\n): boolean {\n function is(x: number, y: number) {\n /* eslint-disable no-self-compare */\n return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y);\n /* eslint-enable no-self-compare */\n }\n const objectIs: (nextDeps: unknown, prevDeps: unknown) => boolean =\n typeof Object.is === 'function' ? Object.is : is;\n\n function areHookInputsEqual(\n nextDeps: DependencyList,\n prevDeps: DependencyList\n ): boolean {\n if (!nextDeps || !prevDeps || prevDeps.length !== nextDeps.length) {\n return false;\n }\n for (let i = 0; i < prevDeps.length; ++i) {\n if (!objectIs(nextDeps[i], prevDeps[i])) {\n return false;\n }\n }\n return true;\n }\n\n return areHookInputsEqual(nextDeps, prevDeps);\n}\n\nexport function hasColorProps(updates: AnimatedStyle): boolean {\n const colorPropsSet = new Set(colorProps);\n for (const key in updates) {\n if (colorPropsSet.has(key)) {\n return true;\n }\n }\n return false;\n}\n\nexport function parseColors(updates: AnimatedStyle): void {\n 'worklet';\n for (const key in updates) {\n if (colorProps.indexOf(key) !== -1) {\n // value could be an animation in which case processColor will recognize it and will return undefined\n // -> in such a case we don't want to override style of that key\n const processedColor = processColor(updates[key]);\n if (processedColor !== undefined) {\n updates[key] = processedColor;\n }\n }\n }\n}\n\nexport function canApplyOptimalisation(upadterFn: WorkletFunction): number {\n const FUNCTIONLESS_FLAG = 0b00000001;\n const STATEMENTLESS_FLAG = 0b00000010;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const optimalization = upadterFn.__optimalization!;\n return (\n optimalization & FUNCTIONLESS_FLAG && optimalization & STATEMENTLESS_FLAG\n );\n}\n\nexport function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {\n 'worklet';\n const propsToCheck: NestedObjectValues<AnimationObject>[] = [prop];\n while (propsToCheck.length > 0) {\n const currentProp: NestedObjectValues<AnimationObject> =\n propsToCheck.pop() as NestedObjectValues<AnimationObject>;\n if (Array.isArray(currentProp)) {\n for (const item of currentProp) {\n propsToCheck.push(item);\n }\n } else if (currentProp?.onFrame !== undefined) {\n return true;\n } else if (typeof currentProp === 'object') {\n for (const item of Object.values(currentProp)) {\n propsToCheck.push(item);\n }\n }\n // if none of the above, it's not the animated prop, check next one\n }\n\n // when none of the props were animated return false\n return false;\n}\n\nexport function styleDiff<T extends AnimatedStyle>(\n oldStyle: AnimatedStyle,\n newStyle: AnimatedStyle\n): Partial<T> {\n 'worklet';\n const diff: any = {};\n for (const key in oldStyle) {\n if (newStyle[key] === undefined) {\n diff[key] = null;\n }\n }\n for (const key in newStyle) {\n const value = newStyle[key];\n const oldValue = oldStyle[key];\n\n if (isAnimated(value)) {\n // do nothing\n continue;\n }\n if (oldValue !== value) {\n diff[key] = value;\n }\n }\n return diff;\n}\n\nexport function getStyleWithoutAnimations(newStyle: AnimatedStyle): StyleProps {\n 'worklet';\n const diff: StyleProps = {};\n\n for (const key in newStyle) {\n const value = newStyle[key];\n if (isAnimated(value)) {\n continue;\n }\n diff[key] = value;\n }\n return diff;\n}\n\nexport const validateAnimatedStyles = (styles: AnimatedStyle): void => {\n 'worklet';\n if (typeof styles !== 'object') {\n throw new Error(\n `useAnimatedStyle has to return an object, found ${typeof styles} instead`\n );\n } else if (Array.isArray(styles)) {\n throw new Error(\n 'useAnimatedStyle has to return an object and cannot return static styles combined with dynamic ones. Please do merging where a component receives props.'\n );\n }\n};\n"],"mappings":"AAAA,SAA2BA,SAA3B,EAAsCC,MAAtC,QAAoD,OAApD;AACA,SAASC,YAAT,QAA6B,WAA7B;AAUA,SAASC,UAAT,QAA2B,SAA3B;AACA,SAASC,KAAT,EAAgBC,MAAhB,QAA8B,oBAA9B;AACA,SAASC,UAAT,QAA2B,gBAA3B;AACA,OAAOC,mBAAP,MAAgC,wBAAhC;AAiBA,OAAO,SAASC,QAAT,CACLC,OADK,EAI4C;EAAA,IAFjDC,UAEiD,uEAF1B,EAE0B;EAAA,IADjDC,OACiD,uEADvC,KACuC;EACjD,MAAMC,OAAO,GAAGX,MAAM,CAAgC,IAAhC,CAAtB;;EACA,IAAIW,OAAO,CAACC,OAAR,KAAoB,IAAxB,EAA8B;IAC5BD,OAAO,CAACC,OAAR,GAAkB,IAAIN,mBAAJ,CAAwBE,OAAxB,EAAiCC,UAAjC,CAAlB;EACD,CAFD,MAEO,IAAIC,OAAJ,EAAa;IAClBC,OAAO,CAACC,OAAR,CAAgBC,aAAhB,CAA8BL,OAA9B;EACD;;EAED,OAAOG,OAAP;AACD;AAED,OAAO,SAASG,UAAT,CACLC,QADK,EAELC,YAFK,EAGwB;EAC7B,MAAML,OAAO,GAAGX,MAAM,CAA2C,IAA3C,CAAtB;;EACA,IAAIW,OAAO,CAACC,OAAR,KAAoB,IAAxB,EAA8B;IAC5BD,OAAO,CAACC,OAAR,GAAkB;MAChBK,OAAO,EAAEf,UAAU,CAAC,EAAD,CADH;MAEhBgB,iBAAiB,EAAE;IAFH,CAAlB;EAID;;EAEDnB,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACXY,OAAO,CAACC,OAAR,GAAkB,IAAlB;IACD,CAFD;EAGD,CAJQ,EAIN,EAJM,CAAT;EAMA,MAAM;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makeRemote","isWeb","isJest","colorProps","WorkletEventHandler","useEvent","handler","eventNames","rebuild","initRef","current","updateWorklet","useHandler","handlers","dependencies","context","savedDependencies","buildDependencies","doDependenciesDiffer","areDependenciesEqual","useWeb","buildWorkletsHash","Object","values","reduce","acc","worklet","__workletHash","toString","handlersList","filter","undefined","map","workletHash","closure","_closure","push","nextDeps","prevDeps","is","x","y","objectIs","areHookInputsEqual","length","i","hasColorProps","updates","colorPropsSet","Set","key","has","parseColors","indexOf","processedColor","canApplyOptimalisation","upadterFn","FUNCTIONLESS_FLAG","STATEMENTLESS_FLAG","optimalization","__optimalization","isAnimated","prop","propsToCheck","currentProp","pop","Array","isArray","item","onFrame","styleDiff","oldStyle","newStyle","diff","value","oldValue","getStyleWithoutAnimations","validateAnimatedStyles","styles","Error"],"sources":["utils.ts"],"sourcesContent":["import { MutableRefObject, useEffect, useRef } from 'react';\nimport { processColor } from '../Colors';\nimport {\n AnimatedStyle,\n Context,\n NativeEvent,\n NestedObjectValues,\n StyleProps,\n WorkletFunction,\n AnimationObject,\n} from '../commonTypes';\nimport { makeRemote } from '../core';\nimport { isWeb, isJest } from '../PlatformChecker';\nimport { colorProps } from '../UpdateProps';\nimport WorkletEventHandler from '../WorkletEventHandler';\nimport { ContextWithDependencies, DependencyList } from './commonTypes';\n\ninterface Handler<T, TContext extends Context> extends WorkletFunction {\n (event: T, context: TContext): void;\n}\n\ninterface Handlers<T, TContext extends Context> {\n [key: string]: Handler<T, TContext> | undefined;\n}\n\nexport interface UseHandlerContext<TContext extends Context> {\n context: TContext;\n doDependenciesDiffer: boolean;\n useWeb: boolean;\n}\n\nexport function useEvent<T extends NativeEvent<T>>(\n handler: (event: T) => void,\n eventNames: string[] = [],\n rebuild = false\n): MutableRefObject<WorkletEventHandler<T> | null> {\n const initRef = useRef<WorkletEventHandler<T> | null>(null);\n if (initRef.current === null) {\n initRef.current = new WorkletEventHandler(handler, eventNames);\n } else if (rebuild) {\n initRef.current.updateWorklet(handler);\n }\n\n return initRef;\n}\n\nexport function useHandler<T, TContext extends Context>(\n handlers: Handlers<T, TContext>,\n dependencies?: DependencyList\n): UseHandlerContext<TContext> {\n const initRef = useRef<ContextWithDependencies<TContext> | null>(null);\n if (initRef.current === null) {\n initRef.current = {\n context: makeRemote<TContext>({} as TContext),\n savedDependencies: [],\n };\n }\n\n useEffect(() => {\n return () => {\n initRef.current = null;\n };\n }, []);\n\n const { context, savedDependencies } = initRef.current;\n\n dependencies = buildDependencies(dependencies, handlers);\n\n const doDependenciesDiffer = !areDependenciesEqual(\n dependencies,\n savedDependencies\n );\n initRef.current.savedDependencies = dependencies;\n const useWeb = isWeb() || isJest();\n\n return { context, doDependenciesDiffer, useWeb };\n}\n\n// builds one big hash from multiple worklets' hashes\nexport function buildWorkletsHash(\n handlers: Record<string, WorkletFunction> | Array<WorkletFunction>\n): string {\n return Object.values(handlers).reduce(\n (acc: string, worklet: WorkletFunction) =>\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n acc + worklet.__workletHash!.toString(),\n ''\n );\n}\n\n// builds dependencies array for gesture handlers\nexport function buildDependencies(\n dependencies: DependencyList,\n handlers: Record<string, WorkletFunction | undefined>\n): Array<unknown> {\n const handlersList: WorkletFunction[] = Object.values(handlers).filter(\n (handler) => handler !== undefined\n ) as WorkletFunction[];\n if (!dependencies) {\n dependencies = handlersList.map((handler) => {\n return {\n workletHash: handler.__workletHash,\n closure: handler._closure,\n };\n });\n } else {\n dependencies.push(buildWorkletsHash(handlersList));\n }\n return dependencies;\n}\n\n// this is supposed to work as useEffect comparison\nexport function areDependenciesEqual(\n nextDeps: DependencyList,\n prevDeps: DependencyList\n): boolean {\n function is(x: number, y: number) {\n /* eslint-disable no-self-compare */\n return (x === y && (x !== 0 || 1 / x === 1 / y)) || (x !== x && y !== y);\n /* eslint-enable no-self-compare */\n }\n const objectIs: (nextDeps: unknown, prevDeps: unknown) => boolean =\n typeof Object.is === 'function' ? Object.is : is;\n\n function areHookInputsEqual(\n nextDeps: DependencyList,\n prevDeps: DependencyList\n ): boolean {\n if (!nextDeps || !prevDeps || prevDeps.length !== nextDeps.length) {\n return false;\n }\n for (let i = 0; i < prevDeps.length; ++i) {\n if (!objectIs(nextDeps[i], prevDeps[i])) {\n return false;\n }\n }\n return true;\n }\n\n return areHookInputsEqual(nextDeps, prevDeps);\n}\n\nexport function hasColorProps(updates: AnimatedStyle): boolean {\n const colorPropsSet = new Set(colorProps);\n for (const key in updates) {\n if (colorPropsSet.has(key)) {\n return true;\n }\n }\n return false;\n}\n\nexport function parseColors(updates: AnimatedStyle): void {\n 'worklet';\n for (const key in updates) {\n if (colorProps.indexOf(key) !== -1) {\n // value could be an animation in which case processColor will recognize it and will return undefined\n // -> in such a case we don't want to override style of that key\n const processedColor = processColor(updates[key]);\n if (processedColor !== undefined) {\n updates[key] = processedColor;\n }\n }\n }\n}\n\nexport function canApplyOptimalisation(upadterFn: WorkletFunction): number {\n const FUNCTIONLESS_FLAG = 0b00000001;\n const STATEMENTLESS_FLAG = 0b00000010;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const optimalization = upadterFn.__optimalization!;\n return (\n optimalization & FUNCTIONLESS_FLAG && optimalization & STATEMENTLESS_FLAG\n );\n}\n\nexport function isAnimated(prop: NestedObjectValues<AnimationObject>): boolean {\n 'worklet';\n const propsToCheck: NestedObjectValues<AnimationObject>[] = [prop];\n while (propsToCheck.length > 0) {\n const currentProp: NestedObjectValues<AnimationObject> =\n propsToCheck.pop() as NestedObjectValues<AnimationObject>;\n if (Array.isArray(currentProp)) {\n for (const item of currentProp) {\n propsToCheck.push(item);\n }\n } else if (currentProp?.onFrame !== undefined) {\n return true;\n } else if (typeof currentProp === 'object') {\n for (const item of Object.values(currentProp)) {\n propsToCheck.push(item);\n }\n }\n // if none of the above, it's not the animated prop, check next one\n }\n\n // when none of the props were animated return false\n return false;\n}\n\nexport function styleDiff<T extends AnimatedStyle>(\n oldStyle: AnimatedStyle,\n newStyle: AnimatedStyle\n): Partial<T> {\n 'worklet';\n const diff: any = {};\n for (const key in oldStyle) {\n if (newStyle[key] === undefined) {\n diff[key] = null;\n }\n }\n for (const key in newStyle) {\n const value = newStyle[key];\n const oldValue = oldStyle[key];\n\n if (isAnimated(value)) {\n // do nothing\n continue;\n }\n if (oldValue !== value) {\n diff[key] = value;\n }\n }\n return diff;\n}\n\nexport function getStyleWithoutAnimations(newStyle: AnimatedStyle): StyleProps {\n 'worklet';\n const diff: StyleProps = {};\n\n for (const key in newStyle) {\n const value = newStyle[key];\n if (isAnimated(value)) {\n continue;\n }\n diff[key] = value;\n }\n return diff;\n}\n\nexport const validateAnimatedStyles = (styles: AnimatedStyle): void => {\n 'worklet';\n if (typeof styles !== 'object') {\n throw new Error(\n `useAnimatedStyle has to return an object, found ${typeof styles} instead`\n );\n } else if (Array.isArray(styles)) {\n throw new Error(\n 'useAnimatedStyle has to return an object and cannot return static styles combined with dynamic ones. Please do merging where a component receives props.'\n );\n }\n};\n"],"mappings":"AAAA,SAA2BA,SAA3B,EAAsCC,MAAtC,QAAoD,OAApD;AACA,SAASC,YAAT,QAA6B,WAA7B;AAUA,SAASC,UAAT,QAA2B,SAA3B;AACA,SAASC,KAAT,EAAgBC,MAAhB,QAA8B,oBAA9B;AACA,SAASC,UAAT,QAA2B,gBAA3B;AACA,OAAOC,mBAAP,MAAgC,wBAAhC;AAiBA,OAAO,SAASC,QAAT,CACLC,OADK,EAI4C;EAAA,IAFjDC,UAEiD,uEAF1B,EAE0B;EAAA,IADjDC,OACiD,uEADvC,KACuC;EACjD,MAAMC,OAAO,GAAGX,MAAM,CAAgC,IAAhC,CAAtB;;EACA,IAAIW,OAAO,CAACC,OAAR,KAAoB,IAAxB,EAA8B;IAC5BD,OAAO,CAACC,OAAR,GAAkB,IAAIN,mBAAJ,CAAwBE,OAAxB,EAAiCC,UAAjC,CAAlB;EACD,CAFD,MAEO,IAAIC,OAAJ,EAAa;IAClBC,OAAO,CAACC,OAAR,CAAgBC,aAAhB,CAA8BL,O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KAAD,CAAd,EAAuB;MACrB;IACD;;IACDD,IAAI,CAACvB,GAAD,CAAJ,GAAYwB,KAAZ;EACD;;EACD,OAAOD,IAAP;AACD;AAED,OAAO,MAAMI,sBAAsB,GAAIC,MAAD,IAAiC;EACrE;;EACA,IAAI,OAAOA,MAAP,KAAkB,QAAtB,EAAgC;IAC9B,MAAM,IAAIC,KAAJ,CACH,mDAAkD,OAAOD,MAAO,UAD7D,CAAN;EAGD,CAJD,MAIO,IAAIZ,KAAK,CAACC,OAAN,CAAcW,MAAd,CAAJ,EAA2B;IAChC,MAAM,IAAIC,KAAJ,CACJ,0JADI,CAAN;EAGD;AACF,CAXM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["hsvToColor","RGBtoHSV","rgbaColor","processColor","red","green","blue","opacity","makeMutable","interpolate","useSharedValue","Extrapolate","EXTEND","CLAMP","IDENTITY","interpolateColorsHSV","value","inputRange","colors","h","s","v","interpolateColorsRGB","r","g","b","a","getInterpolateRGB","i","length","color","processedColor","undefined","push","getInterpolateHSV","interpolateColor","outputRange","colorSpace","Error","ColorSpace","useInterpolateConfig","RGB","cache","interpolateSharableColor","interpolateConfig","HSV"],"sources":["interpolateColor.ts"],"sourcesContent":["import {\n hsvToColor,\n RGBtoHSV,\n rgbaColor,\n processColor,\n red,\n green,\n blue,\n opacity,\n} from './Colors';\nimport { makeMutable } from './core';\nimport { interpolate } from './interpolation';\nimport { SharedValue } from './commonTypes';\nimport { useSharedValue } from './hook/useSharedValue';\n\nexport const Extrapolate = {\n EXTEND: 'extend',\n CLAMP: 'clamp',\n IDENTITY: 'identity',\n};\n\nconst interpolateColorsHSV = (\n value: number,\n inputRange: readonly number[],\n colors: InterpolateHSV\n) => {\n 'worklet';\n const h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);\n const s = interpolate(value, inputRange, colors.s, Extrapolate.CLAMP);\n const v = interpolate(value, inputRange, colors.v, Extrapolate.CLAMP);\n return hsvToColor(h, s, v);\n};\n\nconst interpolateColorsRGB = (\n value: number,\n inputRange: readonly number[],\n colors: InterpolateRGB\n) => {\n 'worklet';\n const r = interpolate(value, inputRange, colors.r, Extrapolate.CLAMP);\n const g = interpolate(value, inputRange, colors.g, Extrapolate.CLAMP);\n const b = interpolate(value, inputRange, colors.b, Extrapolate.CLAMP);\n const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);\n return rgbaColor(r, g, b, a);\n};\n\ninterface InterpolateRGB {\n r: number[];\n g: number[];\n b: number[];\n a: number[];\n}\n\nconst getInterpolateRGB = (\n colors: readonly (string | number)[]\n): InterpolateRGB => {\n 'worklet';\n\n const r = [];\n const g = [];\n const b = [];\n const a = [];\n for (let i = 0; i < colors.length; ++i) {\n const color = colors[i];\n const processedColor = processColor(color);\n // explicit check in case if processedColor is 0\n if (processedColor !== null && processedColor !== undefined) {\n r.push(red(processedColor));\n g.push(green(processedColor));\n b.push(blue(processedColor));\n a.push(opacity(processedColor));\n }\n }\n return { r, g, b, a };\n};\n\ninterface InterpolateHSV {\n h: number[];\n s: number[];\n v: number[];\n}\n\nconst getInterpolateHSV = (\n colors: readonly (string | number)[]\n): InterpolateHSV => {\n 'worklet';\n const h = [];\n const s = [];\n const v = [];\n for (let i = 0; i < colors.length; ++i) {\n const color = colors[i];\n const processedColor = RGBtoHSV(processColor(color) as any);\n if (processedColor) {\n h.push(processedColor.h);\n s.push(processedColor.s);\n v.push(processedColor.v);\n }\n }\n return { h, s, v };\n};\n\nexport const interpolateColor = (\n value: number,\n inputRange: readonly number[],\n outputRange: readonly (string | number)[],\n colorSpace: 'RGB' | 'HSV' = 'RGB'\n): string | number => {\n 'worklet';\n if (colorSpace === 'HSV') {\n return interpolateColorsHSV(\n value,\n inputRange,\n getInterpolateHSV(outputRange)\n );\n } else if (colorSpace === 'RGB') {\n return interpolateColorsRGB(\n value,\n inputRange,\n getInterpolateRGB(outputRange)\n );\n }\n throw new Error(\n `Invalid color space provided: ${colorSpace}. Supported values are: ['RGB', 'HSV']`\n );\n};\n\nexport enum ColorSpace {\n RGB = 0,\n HSV = 1,\n}\n\nexport interface InterpolateConfig {\n inputRange: readonly number[];\n outputRange: readonly (string | number)[];\n colorSpace: ColorSpace;\n cache: SharedValue<InterpolateRGB | InterpolateHSV | null>;\n}\n\nexport function useInterpolateConfig(\n inputRange: readonly number[],\n outputRange: readonly (string | number)[],\n colorSpace = ColorSpace.RGB\n): SharedValue<InterpolateConfig> {\n return useSharedValue({\n inputRange,\n outputRange,\n colorSpace,\n cache: makeMutable(null),\n });\n}\n\nexport const interpolateSharableColor = (\n value: number,\n interpolateConfig: SharedValue<InterpolateConfig>\n): string | number => {\n 'worklet';\n let colors = interpolateConfig.value.cache.value;\n if (interpolateConfig.value.colorSpace === ColorSpace.RGB) {\n if (!colors) {\n colors = getInterpolateRGB(interpolateConfig.value.outputRange);\n interpolateConfig.value.cache.value = colors;\n }\n return interpolateColorsRGB(\n value,\n interpolateConfig.value.inputRange,\n colors as InterpolateRGB\n );\n } else if (interpolateConfig.value.colorSpace === ColorSpace.HSV) {\n if (!colors) {\n colors = getInterpolateHSV(interpolateConfig.value.outputRange);\n interpolateConfig.value.cache.value = colors;\n }\n return interpolateColorsHSV(\n value,\n interpolateConfig.value.inputRange,\n colors as InterpolateHSV\n );\n }\n throw new Error(\n `Invalid color space provided: ${interpolateConfig.value.colorSpace}. Supported values are: ['RGB', 'HSV']`\n );\n};\n"],"mappings":"AAAA,SACEA,UADF,EAEEC,QAFF,EAGEC,SAHF,EAIEC,YAJF,EAKEC,GALF,EAMEC,KANF,EAOEC,IAPF,EAQEC,OARF,QASO,UATP;AAUA,SAASC,WAAT,QAA4B,QAA5B;AACA,SAASC,WAAT,QAA4B,iBAA5B;AAEA,SAASC,cAAT,QAA+B,uBAA/B;AAEA,OAAO,MAAMC,WAAW,GAAG;EACzBC,MAAM,EAAE,QADiB;EAEzBC,KAAK,EAAE,OAFkB;EAGzBC,QAAQ,EAAE;AAHe,CAApB;;AAMP,MAAMC,oBA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C,CAAC,CAACY,IAAF,CAAOF,cAAc,CAACV,CAAtB;IACD;EACF;;EACD,OAAO;IAAEF,CAAF;IAAKC,CAAL;IAAQC;EAAR,CAAP;AACD,CAjBD;;AAmBA,OAAO,MAAMc,gBAAgB,GAAG,UAC9BnB,KAD8B,EAE9BC,UAF8B,EAG9BmB,WAH8B,EAKV;EACpB;;EADoB,IADpBC,UACoB,uEADQ,KACR;;EAEpB,IAAIA,UAAU,KAAK,KAAnB,EAA0B;IACxB,OAAOtB,oBAAoB,CACzBC,KADyB,EAEzBC,UAFyB,EAGzBiB,iBAAiB,CAACE,WAAD,CAHQ,CAA3B;EAKD,CAND,MAMO,IAAIC,UAAU,KAAK,KAAnB,EAA0B;IAC/B,OAAOf,oBAAoB,CACzBN,KADyB,EAEzBC,UAFyB,EAGzBU,iBAAiB,CAACS,WAAD,CAHQ,CAA3B;EAKD;;EACD,MAAM,IAAIE,KAAJ,CACH,iCAAgCD,UAAW,wCADxC,CAAN;AAGD,CAvBM;AAyBP,WAAYE,UAAZ;;WAAYA,U;EAAAA,U,CAAAA,U;EAAAA,U,CAAAA,U;GAAAA,U,KAAAA,U;;AAYZ,OAAO,SAASC,oBAAT,CACLvB,UADK,EAELmB,WAFK,EAI2B;EAAA,IADhCC,UACgC,uEADnBE,UAAU,CAACE,GACQ;EAChC,OAAO/B,cAAc,
|
|
1
|
+
{"version":3,"names":["hsvToColor","RGBtoHSV","rgbaColor","processColor","red","green","blue","opacity","makeMutable","interpolate","useSharedValue","Extrapolate","EXTEND","CLAMP","IDENTITY","interpolateColorsHSV","value","inputRange","colors","h","s","v","interpolateColorsRGB","r","g","b","a","getInterpolateRGB","i","length","color","processedColor","undefined","push","getInterpolateHSV","interpolateColor","outputRange","colorSpace","Error","ColorSpace","useInterpolateConfig","RGB","cache","interpolateSharableColor","interpolateConfig","HSV"],"sources":["interpolateColor.ts"],"sourcesContent":["import {\n hsvToColor,\n RGBtoHSV,\n rgbaColor,\n processColor,\n red,\n green,\n blue,\n opacity,\n} from './Colors';\nimport { makeMutable } from './core';\nimport { interpolate } from './interpolation';\nimport { SharedValue } from './commonTypes';\nimport { useSharedValue } from './hook/useSharedValue';\n\nexport const Extrapolate = {\n EXTEND: 'extend',\n CLAMP: 'clamp',\n IDENTITY: 'identity',\n};\n\nconst interpolateColorsHSV = (\n value: number,\n inputRange: readonly number[],\n colors: InterpolateHSV\n) => {\n 'worklet';\n const h = interpolate(value, inputRange, colors.h, Extrapolate.CLAMP);\n const s = interpolate(value, inputRange, colors.s, Extrapolate.CLAMP);\n const v = interpolate(value, inputRange, colors.v, Extrapolate.CLAMP);\n return hsvToColor(h, s, v);\n};\n\nconst interpolateColorsRGB = (\n value: number,\n inputRange: readonly number[],\n colors: InterpolateRGB\n) => {\n 'worklet';\n const r = interpolate(value, inputRange, colors.r, Extrapolate.CLAMP);\n const g = interpolate(value, inputRange, colors.g, Extrapolate.CLAMP);\n const b = interpolate(value, inputRange, colors.b, Extrapolate.CLAMP);\n const a = interpolate(value, inputRange, colors.a, Extrapolate.CLAMP);\n return rgbaColor(r, g, b, a);\n};\n\ninterface InterpolateRGB {\n r: number[];\n g: number[];\n b: number[];\n a: number[];\n}\n\nconst getInterpolateRGB = (\n colors: readonly (string | number)[]\n): InterpolateRGB => {\n 'worklet';\n\n const r = [];\n const g = [];\n const b = [];\n const a = [];\n for (let i = 0; i < colors.length; ++i) {\n const color = colors[i];\n const processedColor = processColor(color);\n // explicit check in case if processedColor is 0\n if (processedColor !== null && processedColor !== undefined) {\n r.push(red(processedColor));\n g.push(green(processedColor));\n b.push(blue(processedColor));\n a.push(opacity(processedColor));\n }\n }\n return { r, g, b, a };\n};\n\ninterface InterpolateHSV {\n h: number[];\n s: number[];\n v: number[];\n}\n\nconst getInterpolateHSV = (\n colors: readonly (string | number)[]\n): InterpolateHSV => {\n 'worklet';\n const h = [];\n const s = [];\n const v = [];\n for (let i = 0; i < colors.length; ++i) {\n const color = colors[i];\n const processedColor = RGBtoHSV(processColor(color) as any);\n if (processedColor) {\n h.push(processedColor.h);\n s.push(processedColor.s);\n v.push(processedColor.v);\n }\n }\n return { h, s, v };\n};\n\nexport const interpolateColor = (\n value: number,\n inputRange: readonly number[],\n outputRange: readonly (string | number)[],\n colorSpace: 'RGB' | 'HSV' = 'RGB'\n): string | number => {\n 'worklet';\n if (colorSpace === 'HSV') {\n return interpolateColorsHSV(\n value,\n inputRange,\n getInterpolateHSV(outputRange)\n );\n } else if (colorSpace === 'RGB') {\n return interpolateColorsRGB(\n value,\n inputRange,\n getInterpolateRGB(outputRange)\n );\n }\n throw new Error(\n `Invalid color space provided: ${colorSpace}. Supported values are: ['RGB', 'HSV']`\n );\n};\n\nexport enum ColorSpace {\n RGB = 0,\n HSV = 1,\n}\n\nexport interface InterpolateConfig {\n inputRange: readonly number[];\n outputRange: readonly (string | number)[];\n colorSpace: ColorSpace;\n cache: SharedValue<InterpolateRGB | InterpolateHSV | null>;\n}\n\nexport function useInterpolateConfig(\n inputRange: readonly number[],\n outputRange: readonly (string | number)[],\n colorSpace = ColorSpace.RGB\n): SharedValue<InterpolateConfig> {\n return useSharedValue<InterpolateConfig>({\n inputRange,\n outputRange,\n colorSpace,\n cache: makeMutable<InterpolateRGB | InterpolateHSV | null>(null),\n });\n}\n\nexport const interpolateSharableColor = (\n value: number,\n interpolateConfig: SharedValue<InterpolateConfig>\n): string | number => {\n 'worklet';\n let colors = interpolateConfig.value.cache.value;\n if (interpolateConfig.value.colorSpace === ColorSpace.RGB) {\n if (!colors) {\n colors = getInterpolateRGB(interpolateConfig.value.outputRange);\n interpolateConfig.value.cache.value = colors;\n }\n return interpolateColorsRGB(\n value,\n interpolateConfig.value.inputRange,\n colors as InterpolateRGB\n );\n } else if (interpolateConfig.value.colorSpace === ColorSpace.HSV) {\n if (!colors) {\n colors = getInterpolateHSV(interpolateConfig.value.outputRange);\n interpolateConfig.value.cache.value = colors;\n }\n return interpolateColorsHSV(\n value,\n interpolateConfig.value.inputRange,\n colors as InterpolateHSV\n );\n }\n throw new Error(\n `Invalid color space provided: ${interpolateConfig.value.colorSpace}. Supported values are: ['RGB', 'HSV']`\n );\n};\n"],"mappings":"AAAA,SACEA,UADF,EAEEC,QAFF,EAGEC,SAHF,EAIEC,YAJF,EAKEC,GALF,EAMEC,KANF,EAOEC,IAPF,EAQEC,OARF,QASO,UATP;AAUA,SAASC,WAAT,QAA4B,QAA5B;AACA,SAASC,WAAT,QAA4B,iBAA5B;AAEA,SAASC,cAAT,QAA+B,uBAA/B;AAEA,OAAO,MAAMC,WAAW,GAAG;EACzBC,MAAM,EAAE,QADiB;EAEzBC,KAAK,EAAE,OAFkB;EAGzBC,QAAQ,EAAE;AAHe,CAApB;;AAMP,MAAMC,oBAAoB,GAAG,CAC3BC,KAD2B,EAE3BC,UAF2B,EAG3BC,MAH2B,KAIxB;EACH;;EACA,MAAMC,CAAC,GAAGV,WAAW,CAACO,KAAD,EAAQC,UAAR,EAAoBC,MAAM,CAACC,CAA3B,EAA8BR,WAAW,CAACE,KAA1C,CAArB;EACA,MAAMO,CAAC,GAAGX,WAAW,CAACO,KAAD,EAAQC,UAAR,EAAoBC,MAAM,CAACE,CAA3B,EAA8BT,WAAW,CAACE,KAA1C,CAArB;EACA,MAAMQ,CAAC,GAAGZ,WAAW,CAACO,KAAD,EAAQC,UAAR,EAAoBC,MAAM,CAACG,CAA3B,EAA8BV,WAAW,CAACE,KAA1C,CAArB;EACA,OAAOb,UAAU,CAACmB,CAAD,EAAIC,CAAJ,EAAOC,CAAP,CAAjB;AACD,CAVD;;AAYA,MAAMC,oBAAoB,GAAG,CAC3BN,KAD2B,EAE3BC,UAF2B,EAG3BC,MAH2B,KAIxB;EACH;;EACA,MAAMK,CAAC,GAAGd,WAAW,CAACO,KAAD,EAAQC,UAAR,EAAoBC,MAAM,CAACK,CAA3B,EAA8BZ,WAAW,CAACE,KAA1C,CAArB;EACA,MAAMW,CAAC,GAAGf,WAAW,CAACO,KAAD,EAAQC,UAAR,EAAoBC,MAAM,CAACM,C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CAAN;AAGD,CA9BM"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2
2
|
// @ts-nocheck
|
|
3
|
-
import { jestResetJsReanimatedModule } from './core';
|
|
4
3
|
let config = {
|
|
5
4
|
fps: 60
|
|
6
5
|
};
|
|
@@ -133,54 +132,32 @@ const compareStyle = (received, expectedStyle, config) => {
|
|
|
133
132
|
};
|
|
134
133
|
|
|
135
134
|
let frameTime = 1000 / config.fps;
|
|
136
|
-
let requestAnimationFrameCopy;
|
|
137
|
-
let currentTimestamp = 0;
|
|
138
|
-
|
|
139
|
-
const requestAnimationFrame = callback => {
|
|
140
|
-
setTimeout(callback, frameTime);
|
|
141
|
-
};
|
|
142
135
|
|
|
143
136
|
const beforeTest = () => {
|
|
144
|
-
jestResetJsReanimatedModule();
|
|
145
|
-
requestAnimationFrameCopy = global.requestAnimationFrame;
|
|
146
|
-
global.requestAnimationFrame = requestAnimationFrame;
|
|
147
|
-
global.ReanimatedDataMock = {
|
|
148
|
-
now: () => currentTimestamp
|
|
149
|
-
};
|
|
150
|
-
currentTimestamp = 0;
|
|
151
137
|
jest.useFakeTimers();
|
|
152
138
|
};
|
|
153
139
|
|
|
154
140
|
const afterTest = () => {
|
|
141
|
+
jest.runOnlyPendingTimers();
|
|
155
142
|
jest.useRealTimers();
|
|
156
|
-
global.requestAnimationFrame = requestAnimationFrameCopy;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
const tickTravel = () => {
|
|
160
|
-
currentTimestamp += frameTime;
|
|
161
|
-
jest.advanceTimersByTime(frameTime);
|
|
162
143
|
};
|
|
163
144
|
|
|
164
145
|
export const withReanimatedTimer = animationTest => {
|
|
146
|
+
console.warn('This method is deprecated, you shoulddefine your own before and after test hooks to enable jest.useFakeTimers(). Check out the documentation for details on testing');
|
|
165
147
|
beforeTest();
|
|
166
148
|
animationTest();
|
|
167
149
|
afterTest();
|
|
168
150
|
};
|
|
169
151
|
export const advanceAnimationByTime = function () {
|
|
170
152
|
let time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : frameTime;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
jest.advanceTimersByTime(frameTime);
|
|
153
|
+
console.warn('This method is deprecated, use jest.advanceTimersByTime directly');
|
|
154
|
+
jest.advanceTimersByTime(time);
|
|
155
|
+
jest.runOnlyPendingTimers();
|
|
177
156
|
};
|
|
178
157
|
export const advanceAnimationByFrame = count => {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
jest.advanceTimersByTime(frameTime);
|
|
158
|
+
console.warn('This method is deprecated, use jest.advanceTimersByTime directly');
|
|
159
|
+
jest.advanceTimersByTime(count * frameTime);
|
|
160
|
+
jest.runOnlyPendingTimers();
|
|
184
161
|
};
|
|
185
162
|
export const setUpTests = function () {
|
|
186
163
|
let userConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
@@ -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","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,WAAd,CAAJ,EAAgC;IAC9BD,QAAQ,CAACE,KAAT,CAAeR,KAAf,CAAqBY,OAArB,CAA8BZ,KAAD,IAAW;MACtC,IAAID,eAAe,CAACC,KAAD,CAAnB,EAA4B;QAC1BS,YAAY,GAAG,EACb,GAAGA,YADU;UAEb,GAAGP,0BAA0B,CAACF,KAAD;QAFhB,CAAf;MAID,CALD,MAKO;QACLS,YAAY,GAAG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AAkB3C,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
|
+
{"version":3,"names":["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","beforeTest","jest","useFakeTimers","afterTest","runOnlyPendingTimers","useRealTimers","withReanimatedTimer","animationTest","console","warn","advanceAnimationByTime","time","advanceTimersByTime","advanceAnimationByFrame","count","setUpTests","userConfig","global","expectModule","require","jestGlobals","extend","default","Math","round","toHaveAnimatedStyle","getAnimatedStyle"],"sources":["jestUtils.ts"],"sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\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;\n\nconst beforeTest = () => {\n jest.useFakeTimers();\n};\n\nconst afterTest = () => {\n jest.runOnlyPendingTimers();\n jest.useRealTimers();\n};\n\nexport const withReanimatedTimer = (animationTest) => {\n console.warn(\n 'This method is deprecated, you shoulddefine your own before and after test hooks to enable jest.useFakeTimers(). Check out the documentation for details on testing'\n );\n beforeTest();\n animationTest();\n afterTest();\n};\n\nexport const advanceAnimationByTime = (time = frameTime) => {\n console.warn(\n 'This method is deprecated, use jest.advanceTimersByTime directly'\n );\n jest.advanceTimersByTime(time);\n jest.runOnlyPendingTimers();\n};\n\nexport const advanceAnimationByFrame = (count) => {\n console.warn(\n 'This method is deprecated, use jest.advanceTimersByTime directly'\n );\n jest.advanceTimersByTime(count * frameTime);\n jest.runOnlyPendingTimers();\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;AAYA,IAAIA,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,WAAd,CAAJ,EAAgC;IAC9BD,QAAQ,CAACE,KAAT,CAAeR,KAAf,CAAqBY,OAArB,CAA8BZ,KAAD,IAAW;MACtC,IAAID,eAAe,CAACC,KAAD,CAAnB,EAA4B;QAC1BS,YAAY,GAAG,EACb,GAAGA,YADU;UAEb,GAAGP,0BAA0B,CAACF,KAAD;QAFhB,CAAf;MAID,CALD,MAKO;QACLS,YAAY,GAAG,EACb,GAAGA,YADU;UAEb,GAAGT;QAFU,CAAf;MAID;IACF,CAZD;EAaD,CAdD,MAcO;IACL,IAAID,eAAe,CAACQ,WAAD,CAAnB,EAAkC;MAChCE,YAAY,GAAGP,0BAA0B,CAACK,WAAD,CAAzC;IACD,CAFD,MAEO;MACLE,YAAY,GAAG,EACb,GAAGF,WADU;QAEb,GAAGD,QAAQ,CAACE,KAAT,CAAeP,aAAf,CAA6BG;MAFnB,CAAf;IAID;EACF;;EACD,OAAOK,YAAP;AACD,CA5BD;;AA8BA,MAAMI,UAAU,GAAG,CAACJ,YAAD,EAAeK,WAAf,KAA+B;EAChD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ACA;IACA;IACA;;IACA,IAAI,OAAOxC,MAAP,KAAkB,QAAtB,EAAgC;MAC9B,MAAM0C,WAAW,GAAGD,OAAO,CAAC,eAAD,CAA3B;;MACAzC,MAAM,GAAG0C,WAAW,CAAC1C,MAArB;IACD;;IACD,IAAIA,MAAM,KAAKO,SAAX,IAAwBP,MAAM,CAAC2C,MAAP,KAAkBpC,SAA9C,EAAyD;MACvDP,MAAM,GAAGwC,YAAY,CAACI,OAAtB;IACD;EACF;;EAEDH,OAAO,CAAC,cAAD,CAAP;;EACApB,SAAS,GAAGwB,IAAI,CAACC,KAAL,CAAW,OAAOpE,MAAM,CAACC,GAAzB,CAAZ;EAEAD,MAAM,GAAG,EACP,GAAGA,MADI;IAEP,GAAG4D;EAFI,CAAT;EAKAtC,MAAM,CAAC2C,MAAP,CAAc;IACZI,mBAAmB,CAAC5D,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,MAAMsE,gBAAgB,GAAI7D,QAAD,IAAc;EAC5C,OAAOD,eAAe,CAACC,QAAD,CAAtB;AACD,CAFM"}
|
|
@@ -1,105 +1,39 @@
|
|
|
1
1
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
2
2
|
|
|
3
|
-
import MapperRegistry from './MapperRegistry';
|
|
4
|
-
import Mapper from './Mapper';
|
|
5
|
-
import MutableValue from './MutableValue';
|
|
6
3
|
import { NativeReanimated } from '../NativeReanimated/NativeReanimated';
|
|
7
4
|
import { isJest } from '../PlatformChecker';
|
|
8
5
|
export default class JSReanimated extends NativeReanimated {
|
|
9
6
|
constructor() {
|
|
10
7
|
super(false);
|
|
11
8
|
|
|
12
|
-
_defineProperty(this, "
|
|
13
|
-
|
|
14
|
-
_defineProperty(this, "_renderRequested", false);
|
|
15
|
-
|
|
16
|
-
_defineProperty(this, "_mapperRegistry", new MapperRegistry(this));
|
|
17
|
-
|
|
18
|
-
_defineProperty(this, "_frames", []);
|
|
19
|
-
|
|
20
|
-
_defineProperty(this, "timeProvider", void 0);
|
|
9
|
+
_defineProperty(this, "_valueUnpacker", undefined);
|
|
21
10
|
|
|
22
11
|
if (isJest()) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
12
|
+
// on node < 16 jest have problems mocking performance.now method which
|
|
13
|
+
// results in the tests failing, since date precision isn't that important
|
|
14
|
+
// for tests, we use Date.now instead
|
|
15
|
+
this.getTimestamp = () => Date.now();
|
|
26
16
|
} else {
|
|
27
|
-
this.
|
|
28
|
-
now: () => window.performance.now()
|
|
29
|
-
};
|
|
17
|
+
this.getTimestamp = () => window.performance.now();
|
|
30
18
|
}
|
|
31
19
|
}
|
|
32
20
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
makeShareableClone(value) {
|
|
22
|
+
return {
|
|
23
|
+
__hostObjectShareableJSRef: value
|
|
24
|
+
};
|
|
37
25
|
}
|
|
38
26
|
|
|
39
|
-
|
|
40
|
-
|
|
27
|
+
installCoreFunctions(valueUnpacker) {
|
|
28
|
+
this._valueUnpacker = valueUnpacker;
|
|
41
29
|
}
|
|
42
30
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
requestAnimationFrame(_timestampMs => {
|
|
47
|
-
this._renderRequested = false;
|
|
48
|
-
|
|
49
|
-
this._onRender(this.getTimestamp());
|
|
50
|
-
});
|
|
51
|
-
}
|
|
31
|
+
scheduleOnUI(worklet) {
|
|
32
|
+
// @ts-ignore web implementation has still not been updated after the rewrite, this will be addressed once the web implementation updates are ready
|
|
33
|
+
requestAnimationFrame(worklet);
|
|
52
34
|
}
|
|
53
35
|
|
|
54
|
-
|
|
55
|
-
this._mapperRegistry.execute();
|
|
56
|
-
|
|
57
|
-
const frames = [...this._frames];
|
|
58
|
-
this._frames = [];
|
|
59
|
-
|
|
60
|
-
for (let i = 0, len = frames.length; i < len; ++i) {
|
|
61
|
-
frames[i](timestampMs);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (this._mapperRegistry.needRunOnRender) {
|
|
65
|
-
this._mapperRegistry.execute();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
installCoreFunctions(valueSetter) {
|
|
70
|
-
this._valueSetter = valueSetter;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
makeShareable(value) {
|
|
74
|
-
return value;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
makeMutable(value) {
|
|
78
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
79
|
-
return new MutableValue(value, this._valueSetter);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
makeRemote() {
|
|
83
|
-
let object = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
84
|
-
return object;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
startMapper(mapper) {
|
|
88
|
-
let inputs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
89
|
-
let outputs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
90
|
-
const instance = new Mapper(this, mapper, inputs, outputs);
|
|
91
|
-
|
|
92
|
-
const mapperId = this._mapperRegistry.startMapper(instance);
|
|
93
|
-
|
|
94
|
-
this.maybeRequestRender();
|
|
95
|
-
return mapperId;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
stopMapper(mapperId) {
|
|
99
|
-
this._mapperRegistry.stopMapper(mapperId);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
registerEventHandler(_, __) {
|
|
36
|
+
registerEventHandler(_eventHash, _eventHandler) {
|
|
103
37
|
// noop
|
|
104
38
|
return '';
|
|
105
39
|
}
|
|
@@ -119,19 +53,6 @@ export default class JSReanimated extends NativeReanimated {
|
|
|
119
53
|
unregisterSensor() {// noop
|
|
120
54
|
}
|
|
121
55
|
|
|
122
|
-
jestResetModule() {
|
|
123
|
-
if (isJest()) {
|
|
124
|
-
/**
|
|
125
|
-
* If someone used timers to stop animation before the end,
|
|
126
|
-
* then _renderRequested was set as true
|
|
127
|
-
* and any new update from another test wasn't applied.
|
|
128
|
-
*/
|
|
129
|
-
this._renderRequested = false;
|
|
130
|
-
} else {
|
|
131
|
-
throw Error('This method can be only use in Jest testing.');
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
56
|
subscribeForKeyboardEvents(_) {
|
|
136
57
|
console.warn('[Reanimated] useAnimatedKeyboard is not available on web yet.');
|
|
137
58
|
return -1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["NativeReanimated","isJest","JSReanimated","constructor","undefined","getTimestamp","Date","now","window","performance","makeShareableClone","value","__hostObjectShareableJSRef","installCoreFunctions","valueUnpacker","_valueUnpacker","scheduleOnUI","worklet","requestAnimationFrame","registerEventHandler","_eventHash","_eventHandler","unregisterEventHandler","_","enableLayoutAnimations","console","warn","registerSensor","unregisterSensor","subscribeForKeyboardEvents","unsubscribeFromKeyboardEvents"],"sources":["JSReanimated.ts"],"sourcesContent":["import { NativeReanimated } from '../NativeReanimated/NativeReanimated';\nimport { ShareableRef } from '../commonTypes';\nimport { isJest } from '../PlatformChecker';\n\nexport default class JSReanimated extends NativeReanimated {\n _valueUnpacker?: <T>(value: T) => void = undefined;\n\n constructor() {\n super(false);\n if (isJest()) {\n // on node < 16 jest have problems mocking performance.now method which\n // results in the tests failing, since date precision isn't that important\n // for tests, we use Date.now instead\n this.getTimestamp = () => Date.now();\n } else {\n this.getTimestamp = () => window.performance.now();\n }\n }\n\n makeShareableClone<T>(value: T): ShareableRef<T> {\n return { __hostObjectShareableJSRef: value };\n }\n\n installCoreFunctions(valueUnpacker: <T>(value: T) => T): void {\n this._valueUnpacker = valueUnpacker;\n }\n\n scheduleOnUI<T>(worklet: ShareableRef<T>) {\n // @ts-ignore web implementation has still not been updated after the rewrite, this will be addressed once the web implementation updates are ready\n requestAnimationFrame(worklet);\n }\n\n registerEventHandler<T>(\n _eventHash: string,\n _eventHandler: ShareableRef<T>\n ): string {\n // noop\n return '';\n }\n\n unregisterEventHandler(_: string): void {\n // noop\n }\n\n enableLayoutAnimations() {\n console.warn(\n '[Reanimated] enableLayoutAnimations is not available for WEB yet'\n );\n }\n\n registerSensor(): number {\n console.warn('[Reanimated] useAnimatedSensor is not available on web yet.');\n return -1;\n }\n\n unregisterSensor(): void {\n // noop\n }\n\n subscribeForKeyboardEvents(_: ShareableRef<number>): number {\n console.warn(\n '[Reanimated] useAnimatedKeyboard is not available on web yet.'\n );\n return -1;\n }\n\n unsubscribeFromKeyboardEvents(_: number): void {\n // noop\n }\n}\n"],"mappings":";;AAAA,SAASA,gBAAT,QAAiC,sCAAjC;AAEA,SAASC,MAAT,QAAuB,oBAAvB;AAEA,eAAe,MAAMC,YAAN,SAA2BF,gBAA3B,CAA4C;EAGzDG,WAAW,GAAG;IACZ,MAAM,KAAN;;IADY,wCAF2BC,SAE3B;;IAEZ,IAAIH,MAAM,EAAV,EAAc;MACZ;MACA;MACA;MACA,KAAKI,YAAL,GAAoB,MAAMC,IAAI,CAACC,GAAL,EAA1B;IACD,CALD,MAKO;MACL,KAAKF,YAAL,GAAoB,MAAMG,MAAM,CAACC,WAAP,CAAmBF,GAAnB,EAA1B;IACD;EACF;;EAEDG,kBAAkB,CAAIC,KAAJ,EAA+B;IAC/C,OAAO;MAAEC,0BAA0B,EAAED;IAA9B,CAAP;EACD;;EAEDE,oBAAoB,CAACC,aAAD,EAA0C;IAC5D,KAAKC,cAAL,GAAsBD,aAAtB;EACD;;EAEDE,YAAY,CAAIC,OAAJ,EAA8B;IACxC;IACAC,qBAAqB,CAACD,OAAD,CAArB;EACD;;EAEDE,oBAAoB,CAClBC,UADkB,EAElBC,aAFkB,EAGV;IACR;IACA,OAAO,EAAP;EACD;;EAEDC,sBAAsB,CAACC,CAAD,EAAkB,CACtC;EACD;;EAEDC,sBAAsB,GAAG;IACvBC,OAAO,CAACC,IAAR,CACE,kEADF;EAGD;;EAEDC,cAAc,GAAW;IACvBF,OAAO,CAACC,IAAR,CAAa,6DAAb;IACA,OAAO,CAAC,CAAR;EACD;;EAEDE,gBAAgB,GAAS,CACvB;EACD;;EAEDC,0BAA0B,CAACN,CAAD,EAAkC;IAC1DE,OAAO,CAACC,IAAR,CACE,+DADF;IAGA,OAAO,CAAC,CAAR;EACD;;EAEDI,6BAA6B,CAACP,CAAD,EAAkB,CAC7C;EACD;;AAhEwD"}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import JSReanimated from './JSReanimated';
|
|
2
2
|
const reanimatedJS = new JSReanimated();
|
|
3
|
+
|
|
4
|
+
global._makeShareableClone = c => c;
|
|
5
|
+
|
|
6
|
+
global._scheduleOnJS = setImmediate;
|
|
7
|
+
global._getTimestamp = reanimatedJS.getTimestamp.bind(reanimatedJS);
|
|
3
8
|
export const _updatePropsJS = (updates, viewRef) => {
|
|
4
9
|
if (viewRef._component) {
|
|
5
10
|
const component = viewRef._component;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["JSReanimated","reanimatedJS","_updatePropsJS","updates","viewRef","_component","component","rawStyles","Object","keys","reduce","acc","key","value","index","setNativeProps","props","length","forEach","dashedKey","replace","m","toLowerCase","_touchableNode","setAttribute","console","warn","style","previousStyle","currentStyle"],"sources":["index.ts"],"sourcesContent":["import JSReanimated from './JSReanimated';\nimport { AnimatedStyle, StyleProps } from '../commonTypes';\n\nconst reanimatedJS = new JSReanimated();\n\ninterface JSReanimatedComponent {\n previousStyle: StyleProps;\n setNativeProps: (style: StyleProps) => void;\n props: Record<string, string | number>;\n _touchableNode: {\n setAttribute: (key: string, props: unknown) => void;\n };\n}\n\nexport const _updatePropsJS = (\n updates: StyleProps | AnimatedStyle,\n viewRef: { _component?: JSReanimatedComponent }\n): void => {\n if (viewRef._component) {\n const component = viewRef._component;\n const [rawStyles] = Object.keys(updates).reduce(\n (acc: [StyleProps, AnimatedStyle], key) => {\n const value = updates[key];\n const index = typeof value === 'function' ? 1 : 0;\n acc[index][key] = value;\n return acc;\n },\n [{}, {}]\n );\n\n if (typeof component.setNativeProps === 'function') {\n setNativeProps(component, rawStyles);\n } else if (Object.keys(component.props).length > 0) {\n Object.keys(component.props).forEach((key) => {\n if (!rawStyles[key]) {\n return;\n }\n const dashedKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());\n component._touchableNode.setAttribute(dashedKey, rawStyles[key]);\n });\n } else {\n console.warn('It is not possible to manipulate component');\n }\n }\n};\n\nconst setNativeProps = (\n component: JSReanimatedComponent,\n style: StyleProps\n): void => {\n const previousStyle = component.previousStyle ? component.previousStyle : {};\n const currentStyle = { ...previousStyle, ...style };\n component.previousStyle = currentStyle;\n component.setNativeProps({ style: currentStyle });\n};\n\nexport default reanimatedJS;\n"],"mappings":"AAAA,OAAOA,YAAP,MAAyB,gBAAzB;AAGA,MAAMC,YAAY,GAAG,IAAID,YAAJ,EAArB;AAWA,OAAO,
|
|
1
|
+
{"version":3,"names":["JSReanimated","reanimatedJS","global","_makeShareableClone","c","_scheduleOnJS","setImmediate","_getTimestamp","getTimestamp","bind","_updatePropsJS","updates","viewRef","_component","component","rawStyles","Object","keys","reduce","acc","key","value","index","setNativeProps","props","length","forEach","dashedKey","replace","m","toLowerCase","_touchableNode","setAttribute","console","warn","style","previousStyle","currentStyle"],"sources":["index.ts"],"sourcesContent":["import JSReanimated from './JSReanimated';\nimport { AnimatedStyle, StyleProps } from '../commonTypes';\n\nconst reanimatedJS = new JSReanimated();\n\nglobal._makeShareableClone = (c) => c;\nglobal._scheduleOnJS = setImmediate;\nglobal._getTimestamp = reanimatedJS.getTimestamp.bind(reanimatedJS);\n\ninterface JSReanimatedComponent {\n previousStyle: StyleProps;\n setNativeProps: (style: StyleProps) => void;\n props: Record<string, string | number>;\n _touchableNode: {\n setAttribute: (key: string, props: unknown) => void;\n };\n}\n\nexport const _updatePropsJS = (\n updates: StyleProps | AnimatedStyle,\n viewRef: { _component?: JSReanimatedComponent }\n): void => {\n if (viewRef._component) {\n const component = viewRef._component;\n const [rawStyles] = Object.keys(updates).reduce(\n (acc: [StyleProps, AnimatedStyle], key) => {\n const value = updates[key];\n const index = typeof value === 'function' ? 1 : 0;\n acc[index][key] = value;\n return acc;\n },\n [{}, {}]\n );\n\n if (typeof component.setNativeProps === 'function') {\n setNativeProps(component, rawStyles);\n } else if (Object.keys(component.props).length > 0) {\n Object.keys(component.props).forEach((key) => {\n if (!rawStyles[key]) {\n return;\n }\n const dashedKey = key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase());\n component._touchableNode.setAttribute(dashedKey, rawStyles[key]);\n });\n } else {\n console.warn('It is not possible to manipulate component');\n }\n }\n};\n\nconst setNativeProps = (\n component: JSReanimatedComponent,\n style: StyleProps\n): void => {\n const previousStyle = component.previousStyle ? component.previousStyle : {};\n const currentStyle = { ...previousStyle, ...style };\n component.previousStyle = currentStyle;\n component.setNativeProps({ style: currentStyle });\n};\n\nexport default reanimatedJS;\n"],"mappings":"AAAA,OAAOA,YAAP,MAAyB,gBAAzB;AAGA,MAAMC,YAAY,GAAG,IAAID,YAAJ,EAArB;;AAEAE,MAAM,CAACC,mBAAP,GAA8BC,CAAD,IAAOA,CAApC;;AACAF,MAAM,CAACG,aAAP,GAAuBC,YAAvB;AACAJ,MAAM,CAACK,aAAP,GAAuBN,YAAY,CAACO,YAAb,CAA0BC,IAA1B,CAA+BR,YAA/B,CAAvB;AAWA,OAAO,MAAMS,cAAc,GAAG,CAC5BC,OAD4B,EAE5BC,OAF4B,KAGnB;EACT,IAAIA,OAAO,CAACC,UAAZ,EAAwB;IACtB,MAAMC,SAAS,GAAGF,OAAO,CAACC,UAA1B;IACA,MAAM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oB,GAAGD;EAAvB,CAArB;EACArB,SAAS,CAACsB,aAAV,GAA0BC,YAA1B;EACAvB,SAAS,CAACS,cAAV,CAAyB;IAAEY,KAAK,EAAEE;EAAT,CAAzB;AACD,CARD;;AAUA,eAAepC,YAAf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["commonTypes.ts"],"sourcesContent":["import { EasingFn } from '../../Easing';\nimport { StyleProps } from '../../commonTypes';\n\nexport interface KeyframeProps extends StyleProps {\n easing?: EasingFn;\n [key: string]: any;\n}\n\nexport type LayoutAnimation = {\n initialValues: StyleProps;\n animations: StyleProps;\n callback?: (finished: boolean) => void;\n};\n\nexport type AnimationFunction = (a?: any, b?: any, c?: any) => any; // this is just a temporary mock\n\nexport interface EntryAnimationsValues {\n targetOriginX: number;\n targetOriginY: number;\n targetWidth: number;\n targetHeight: number;\n targetGlobalOriginX: number;\n targetGlobalOriginY: number;\n}\n\nexport interface ExitAnimationsValues {\n currentOriginX: number;\n currentOriginY: number;\n currentWidth: number;\n currentHeight: number;\n currentGlobalOriginX: number;\n currentGlobalOriginY: number;\n}\n\nexport type EntryExitAnimationFunction = (\n targetValues: EntryAnimationsValues | ExitAnimationsValues\n) => LayoutAnimation;\n\nexport type AnimationConfigFunction<T> = (targetValues: T) => LayoutAnimation;\n\nexport interface LayoutAnimationsValues {\n currentOriginX: number;\n currentOriginY: number;\n currentWidth: number;\n currentHeight: number;\n currentGlobalOriginX: number;\n currentGlobalOriginY: number;\n targetOriginX: number;\n targetOriginY: number;\n targetWidth: number;\n targetHeight: number;\n targetGlobalOriginX: number;\n targetGlobalOriginY: number;\n windowWidth: number;\n windowHeight: number;\n}\n\nexport type LayoutAnimationFunction = (\n targetValues: LayoutAnimationsValues\n) => LayoutAnimation;\n\nexport interface ILayoutAnimationBuilder {\n build: () => LayoutAnimationFunction;\n}\n\nexport interface BaseLayoutAnimationConfig {\n duration?: number;\n easing?: EasingFn;\n type?: AnimationFunction;\n damping?: number;\n mass?: number;\n stiffness?: number;\n overshootClamping?: number;\n restDisplacementThreshold?: number;\n restSpeedThreshold?: number;\n}\n\nexport interface BaseBuilderAnimationConfig extends BaseLayoutAnimationConfig {\n rotate?: number | string;\n}\n\nexport type LayoutAnimationAndConfig = [\n AnimationFunction,\n BaseBuilderAnimationConfig\n];\n\nexport interface IEntryExitAnimationBuilder {\n build: () => EntryExitAnimationFunction;\n}\n\nexport interface IEntryAnimationBuilder {\n build: () => AnimationConfigFunction<EntryAnimationsValues>;\n}\n\nexport interface IExitAnimationBuilder {\n build: () => AnimationConfigFunction<ExitAnimationsValues>;\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["commonTypes.ts"],"sourcesContent":["import { EasingFn } from '../../Easing';\nimport { StyleProps } from '../../commonTypes';\n\nexport interface KeyframeProps extends StyleProps {\n easing?: EasingFn;\n [key: string]: any;\n}\n\nexport type LayoutAnimation = {\n initialValues: StyleProps;\n animations: StyleProps;\n callback?: (finished: boolean) => void;\n};\n\nexport type AnimationFunction = (a?: any, b?: any, c?: any) => any; // this is just a temporary mock\n\nexport interface EntryAnimationsValues {\n targetOriginX: number;\n targetOriginY: number;\n targetWidth: number;\n targetHeight: number;\n targetGlobalOriginX: number;\n targetGlobalOriginY: number;\n}\n\nexport interface ExitAnimationsValues {\n currentOriginX: number;\n currentOriginY: number;\n currentWidth: number;\n currentHeight: number;\n currentGlobalOriginX: number;\n currentGlobalOriginY: number;\n}\n\nexport type EntryExitAnimationFunction = (\n targetValues: EntryAnimationsValues | ExitAnimationsValues\n) => LayoutAnimation;\n\nexport type AnimationConfigFunction<T> = (targetValues: T) => LayoutAnimation;\n\nexport interface LayoutAnimationsValues {\n currentOriginX: number;\n currentOriginY: number;\n currentWidth: number;\n currentHeight: number;\n currentGlobalOriginX: number;\n currentGlobalOriginY: number;\n targetOriginX: number;\n targetOriginY: number;\n targetWidth: number;\n targetHeight: number;\n targetGlobalOriginX: number;\n targetGlobalOriginY: number;\n windowWidth: number;\n windowHeight: number;\n}\n\nexport type LayoutAnimationFunction = (\n targetValues: LayoutAnimationsValues\n) => LayoutAnimation;\n\nexport type LayoutAnimationStartFunction = (\n tag: number,\n type: string,\n yogaValues: LayoutAnimationsValues,\n config: LayoutAnimationFunction\n) => void;\n\nexport interface ILayoutAnimationBuilder {\n build: () => LayoutAnimationFunction;\n}\n\nexport interface BaseLayoutAnimationConfig {\n duration?: number;\n easing?: EasingFn;\n type?: AnimationFunction;\n damping?: number;\n mass?: number;\n stiffness?: number;\n overshootClamping?: number;\n restDisplacementThreshold?: number;\n restSpeedThreshold?: number;\n}\n\nexport interface BaseBuilderAnimationConfig extends BaseLayoutAnimationConfig {\n rotate?: number | string;\n}\n\nexport type LayoutAnimationAndConfig = [\n AnimationFunction,\n BaseBuilderAnimationConfig\n];\n\nexport interface IEntryExitAnimationBuilder {\n build: () => EntryExitAnimationFunction;\n}\n\nexport interface IEntryAnimationBuilder {\n build: () => AnimationConfigFunction<EntryAnimationsValues>;\n}\n\nexport interface IExitAnimationBuilder {\n build: () => AnimationConfigFunction<ExitAnimationsValues>;\n}\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BaseAnimationBuilder","ComplexAnimationBuilder","Keyframe"],"sources":["index.ts"],"sourcesContent":["export { BaseAnimationBuilder } from './BaseAnimationBuilder';\nexport { ComplexAnimationBuilder } from './ComplexAnimationBuilder';\nexport { Keyframe } from './Keyframe';\nexport type {\n LayoutAnimation,\n AnimationFunction,\n EntryAnimationsValues,\n ExitAnimationsValues,\n EntryExitAnimationFunction,\n AnimationConfigFunction,\n IEntryAnimationBuilder,\n IExitAnimationBuilder,\n LayoutAnimationsValues,\n LayoutAnimationFunction,\n ILayoutAnimationBuilder,\n BaseLayoutAnimationConfig,\n BaseBuilderAnimationConfig,\n LayoutAnimationAndConfig,\n IEntryExitAnimationBuilder,\n} from './commonTypes';\n"],"mappings":"AAAA,SAASA,oBAAT,QAAqC,wBAArC;AACA,SAASC,uBAAT,QAAwC,2BAAxC;AACA,SAASC,QAAT,QAAyB,YAAzB"}
|
|
1
|
+
{"version":3,"names":["BaseAnimationBuilder","ComplexAnimationBuilder","Keyframe"],"sources":["index.ts"],"sourcesContent":["export { BaseAnimationBuilder } from './BaseAnimationBuilder';\nexport { ComplexAnimationBuilder } from './ComplexAnimationBuilder';\nexport { Keyframe } from './Keyframe';\nexport type {\n LayoutAnimation,\n AnimationFunction,\n EntryAnimationsValues,\n ExitAnimationsValues,\n EntryExitAnimationFunction,\n AnimationConfigFunction,\n IEntryAnimationBuilder,\n IExitAnimationBuilder,\n LayoutAnimationsValues,\n LayoutAnimationFunction,\n LayoutAnimationStartFunction,\n ILayoutAnimationBuilder,\n BaseLayoutAnimationConfig,\n BaseBuilderAnimationConfig,\n LayoutAnimationAndConfig,\n IEntryExitAnimationBuilder,\n} from './commonTypes';\n"],"mappings":"AAAA,SAASA,oBAAT,QAAqC,wBAArC;AACA,SAASC,uBAAT,QAAwC,2BAAxC;AACA,SAASC,QAAT,QAAyB,YAAzB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { runOnUI } from '../core';
|
|
2
|
+
import { withStyleAnimation } from '../animation/styleAnimation';
|
|
3
|
+
import { LogBox } from 'react-native';
|
|
4
|
+
import { makeUIMutable } from '../mutables';
|
|
5
|
+
LogBox.ignoreLogs(['Overriding previous layout animation with']);
|
|
6
|
+
const TAG_OFFSET = 1e9;
|
|
7
|
+
|
|
8
|
+
function startObservingProgress(tag, sharedValue) {
|
|
9
|
+
'worklet';
|
|
10
|
+
|
|
11
|
+
sharedValue.addListener(tag + TAG_OFFSET, () => {
|
|
12
|
+
_notifyAboutProgress(tag, sharedValue.value);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function stopObservingProgress(tag, sharedValue, cancelled, removeView) {
|
|
17
|
+
'worklet';
|
|
18
|
+
|
|
19
|
+
sharedValue.removeListener(tag + TAG_OFFSET);
|
|
20
|
+
|
|
21
|
+
_notifyAboutEnd(tag, cancelled, removeView);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function createLayoutAnimationManager() {
|
|
25
|
+
'worklet';
|
|
26
|
+
|
|
27
|
+
const enteringAnimationForTag = new Map();
|
|
28
|
+
const mutableValuesForTag = new Map();
|
|
29
|
+
return {
|
|
30
|
+
start(tag, type, yogaValues, config) {
|
|
31
|
+
const style = config(yogaValues);
|
|
32
|
+
let currentAnimation = style.animations;
|
|
33
|
+
|
|
34
|
+
if (type === 'entering') {
|
|
35
|
+
enteringAnimationForTag.set(tag, currentAnimation);
|
|
36
|
+
} else if (type === 'layout') {
|
|
37
|
+
// When layout animation is requested, but entering is still running, we merge
|
|
38
|
+
// new layout animation targets into the ongoing animation
|
|
39
|
+
const enteringAnimation = enteringAnimationForTag.get(tag);
|
|
40
|
+
|
|
41
|
+
if (enteringAnimation) {
|
|
42
|
+
currentAnimation = { ...enteringAnimation,
|
|
43
|
+
...style.animations
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let value = mutableValuesForTag.get(tag);
|
|
49
|
+
|
|
50
|
+
if (value === undefined) {
|
|
51
|
+
value = makeUIMutable(style.initialValues);
|
|
52
|
+
mutableValuesForTag.set(tag, value);
|
|
53
|
+
} else {
|
|
54
|
+
stopObservingProgress(tag, value, false, false);
|
|
55
|
+
value._value = style.initialValues;
|
|
56
|
+
} // @ts-ignore The line below started failing because I added types to the method – don't have time to fix it right now
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
const animation = withStyleAnimation(currentAnimation);
|
|
60
|
+
|
|
61
|
+
animation.callback = finished => {
|
|
62
|
+
if (finished) {
|
|
63
|
+
enteringAnimationForTag.delete(tag);
|
|
64
|
+
mutableValuesForTag.delete(tag);
|
|
65
|
+
const shouldRemoveView = type === 'exiting';
|
|
66
|
+
stopObservingProgress(tag, value, finished, shouldRemoveView);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
style.callback && style.callback(finished === undefined ? false : finished);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
startObservingProgress(tag, value);
|
|
73
|
+
value.value = animation;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
runOnUI(() => {
|
|
80
|
+
'worklet';
|
|
81
|
+
|
|
82
|
+
global.LayoutAnimationsManager = createLayoutAnimationManager();
|
|
83
|
+
})();
|
|
84
|
+
//# sourceMappingURL=animationsManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["runOnUI","withStyleAnimation","LogBox","makeUIMutable","ignoreLogs","TAG_OFFSET","startObservingProgress","tag","sharedValue","addListener","_notifyAboutProgress","value","stopObservingProgress","cancelled","removeView","removeListener","_notifyAboutEnd","createLayoutAnimationManager","enteringAnimationForTag","Map","mutableValuesForTag","start","type","yogaValues","config","style","currentAnimation","animations","set","enteringAnimation","get","undefined","initialValues","_value","animation","callback","finished","delete","shouldRemoveView","global","LayoutAnimationsManager"],"sources":["animationsManager.ts"],"sourcesContent":["import { runOnUI } from '../core';\nimport { withStyleAnimation } from '../animation/styleAnimation';\nimport { LogBox } from 'react-native';\nimport { SharedValue } from '../commonTypes';\nimport { makeUIMutable } from '../mutables';\nimport {\n LayoutAnimationFunction,\n LayoutAnimationsValues,\n} from './animationBuilder';\n\nLogBox.ignoreLogs(['Overriding previous layout animation with']);\n\nconst TAG_OFFSET = 1e9;\n\nfunction startObservingProgress(\n tag: number,\n sharedValue: SharedValue<number>\n): void {\n 'worklet';\n sharedValue.addListener(tag + TAG_OFFSET, () => {\n _notifyAboutProgress(tag, sharedValue.value);\n });\n}\n\nfunction stopObservingProgress(\n tag: number,\n sharedValue: SharedValue<number>,\n cancelled: boolean,\n removeView: boolean\n): void {\n 'worklet';\n sharedValue.removeListener(tag + TAG_OFFSET);\n _notifyAboutEnd(tag, cancelled, removeView);\n}\n\nfunction createLayoutAnimationManager() {\n 'worklet';\n const enteringAnimationForTag = new Map();\n const mutableValuesForTag = new Map();\n\n return {\n start(\n tag: number,\n type: string,\n yogaValues: LayoutAnimationsValues,\n config: LayoutAnimationFunction\n ) {\n const style = config(yogaValues);\n let currentAnimation = style.animations;\n\n if (type === 'entering') {\n enteringAnimationForTag.set(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.get(tag);\n if (enteringAnimation) {\n currentAnimation = { ...enteringAnimation, ...style.animations };\n }\n }\n\n let value = mutableValuesForTag.get(tag);\n if (value === undefined) {\n value = makeUIMutable(style.initialValues);\n mutableValuesForTag.set(tag, value);\n } else {\n stopObservingProgress(tag, value, false, false);\n value._value = style.initialValues;\n }\n\n // @ts-ignore The line below started failing because I added types to the method – don't have time to fix it right now\n const animation = withStyleAnimation(currentAnimation);\n\n animation.callback = (finished?: boolean) => {\n if (finished) {\n enteringAnimationForTag.delete(tag);\n mutableValuesForTag.delete(tag);\n const shouldRemoveView = type === 'exiting';\n stopObservingProgress(tag, value, finished, shouldRemoveView);\n }\n style.callback &&\n style.callback(finished === undefined ? false : finished);\n };\n\n startObservingProgress(tag, value);\n value.value = animation;\n },\n };\n}\n\nrunOnUI(() => {\n 'worklet';\n global.LayoutAnimationsManager = createLayoutAnimationManager();\n})();\n"],"mappings":"AAAA,SAASA,OAAT,QAAwB,SAAxB;AACA,SAASC,kBAAT,QAAmC,6BAAnC;AACA,SAASC,MAAT,QAAuB,cAAvB;AAEA,SAASC,aAAT,QAA8B,aAA9B;AAMAD,MAAM,CAACE,UAAP,CAAkB,CAAC,2CAAD,CAAlB;AAEA,MAAMC,UAAU,GAAG,GAAnB;;AAEA,SAASC,sBAAT,CACEC,GADF,EAEEC,WAFF,EAGQ;EACN;;EACAA,WAAW,CAACC,WAAZ,CAAwBF,GAAG,GAAGF,UAA9B,EAA0C,MAAM;IAC9CK,oBAAoB,CAACH,GAAD,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ApB,CAArB;QACAA,KAAK,CAACsB,MAAN,GAAeR,KAAK,CAACO,aAArB;MACD,CAtBD,CAwBA;;;MACA,MAAME,SAAS,GAAGjC,kBAAkB,CAACyB,gBAAD,CAApC;;MAEAQ,SAAS,CAACC,QAAV,GAAsBC,QAAD,IAAwB;QAC3C,IAAIA,QAAJ,EAAc;UACZlB,uBAAuB,CAACmB,MAAxB,CAA+B9B,GAA/B;UACAa,mBAAmB,CAACiB,MAApB,CAA2B9B,GAA3B;UACA,MAAM+B,gBAAgB,GAAGhB,IAAI,KAAK,SAAlC;UACAV,qBAAqB,CAACL,GAAD,EAAMI,KAAN,EAAayB,QAAb,EAAuBE,gBAAvB,CAArB;QACD;;QACDb,KAAK,CAACU,QAAN,IACEV,KAAK,CAACU,QAAN,CAAeC,QAAQ,KAAKL,SAAb,GAAyB,KAAzB,GAAiCK,QAAhD,CADF;MAED,CATD;;MAWA9B,sBAAsB,CAACC,GAAD,EAAMI,KAAN,CAAtB;MACAA,KAAK,CAACA,KAAN,GAAcuB,SAAd;IACD;;EA9CI,CAAP;AAgDD;;AAEDlC,OAAO,CAAC,MAAM;EACZ;;EACAuC,MAAM,CAACC,uBAAP,GAAiCvB,4BAA4B,EAA7D;AACD,CAHM,CAAP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["import './
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["import './animationsManager';\nexport * from './animationBuilder';\nexport * from './defaultAnimations';\nexport * from './defaultTransitions';\n"],"mappings":"AAAA,OAAO,qBAAP;AACA,cAAc,oBAAd;AACA,cAAc,qBAAd;AACA,cAAc,sBAAd"}
|