{"version":3,"names":["withStyleAnimation","makeUIMutable","LayoutAnimationType","runOnUIImmediately","TAG_OFFSET","startObservingProgress","tag","sharedValue","animationType","isSharedTransition","SHARED_ELEMENT_TRANSITION","addListener","_notifyAboutProgress","value","stopObservingProgress","removeView","arguments","length","undefined","removeListener","_notifyAboutEnd","createLayoutAnimationManager","currentAnimationForTag","Map","mutableValuesForTag","start","type","yogaValues","config","SHARED_ELEMENT_TRANSITION_PROGRESS","global","ProgressTransitionRegister","onTransitionStart","style","currentAnimation","animations","previousAnimation","get","set","initialValues","_value","animation","callback","finished","delete","shouldRemoveView","EXITING","stop","LayoutAnimationsManager"],"sources":["animationsManager.ts"],"sourcesContent":["'use strict';\nimport { withStyleAnimation } from '../animation/styleAnimation';\nimport type { SharedValue } from '../commonTypes';\nimport { makeUIMutable } from '../mutables';\nimport { LayoutAnimationType } from './animationBuilder';\nimport { runOnUIImmediately } from '../threads';\nimport type {\n SharedTransitionAnimationsValues,\n LayoutAnimation,\n} from './animationBuilder/commonTypes';\n\nconst TAG_OFFSET = 1e9;\n\nfunction startObservingProgress(\n tag: number,\n sharedValue: SharedValue>,\n animationType: LayoutAnimationType\n): void {\n 'worklet';\n const isSharedTransition =\n animationType === LayoutAnimationType.SHARED_ELEMENT_TRANSITION;\n sharedValue.addListener(tag + TAG_OFFSET, () => {\n _notifyAboutProgress(tag, sharedValue.value, isSharedTransition);\n });\n}\n\nfunction stopObservingProgress(\n tag: number,\n sharedValue: SharedValue,\n removeView = false\n): void {\n 'worklet';\n sharedValue.removeListener(tag + TAG_OFFSET);\n _notifyAboutEnd(tag, removeView);\n}\n\nfunction createLayoutAnimationManager() {\n 'worklet';\n const currentAnimationForTag = new Map();\n const mutableValuesForTag = new Map();\n\n return {\n start(\n tag: number,\n type: LayoutAnimationType,\n /**\n * createLayoutAnimationManager creates an animation manager for both Layout animations and Shared Transition Elements animations.\n */\n yogaValues: Partial,\n config: (\n arg: Partial\n ) => LayoutAnimation\n ) {\n if (type === LayoutAnimationType.SHARED_ELEMENT_TRANSITION_PROGRESS) {\n global.ProgressTransitionRegister.onTransitionStart(tag, yogaValues);\n return;\n }\n\n const style = config(yogaValues);\n let currentAnimation = style.animations;\n\n // When layout animation is requested, but a previous one is still running, we merge\n // new layout animation targets into the ongoing animation\n const previousAnimation = currentAnimationForTag.get(tag);\n if (previousAnimation) {\n currentAnimation = { ...previousAnimation, ...style.animations };\n }\n currentAnimationForTag.set(tag, currentAnimation);\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);\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 currentAnimationForTag.delete(tag);\n mutableValuesForTag.delete(tag);\n const shouldRemoveView = type === LayoutAnimationType.EXITING;\n stopObservingProgress(tag, value, shouldRemoveView);\n }\n style.callback &&\n style.callback(finished === undefined ? false : finished);\n };\n\n startObservingProgress(tag, value, type);\n value.value = animation;\n },\n stop(tag: number) {\n const value = mutableValuesForTag.get(tag);\n if (!value) {\n return;\n }\n stopObservingProgress(tag, value);\n },\n };\n}\n\nrunOnUIImmediately(() => {\n 'worklet';\n global.LayoutAnimationsManager = createLayoutAnimationManager();\n})();\n\nexport type LayoutAnimationsManager = ReturnType<\n typeof createLayoutAnimationManager\n>;\n"],"mappings":"AAAA,YAAY;;AACZ,SAASA,kBAAkB,QAAQ,6BAA6B;AAEhE,SAASC,aAAa,QAAQ,aAAa;AAC3C,SAASC,mBAAmB,QAAQ,oBAAoB;AACxD,SAASC,kBAAkB,QAAQ,YAAY;AAM/C,MAAMC,UAAU,GAAG,GAAG;AAEtB,SAASC,sBAAsBA,CAC7BC,GAAW,EACXC,WAAiD,EACjDC,aAAkC,EAC5B;EACN,SAAS;;EACT,MAAMC,kBAAkB,GACtBD,aAAa,KAAK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