UNPKG

react-native-reanimated

Version:

More powerful alternative to Animated library for React Native.

100 lines (73 loc) 3 kB
"use strict"; var _styleAnimation = require("../animation/styleAnimation"); var _mutables = require("../mutables"); var _animationBuilder = require("./animationBuilder"); var _threads = require("../threads"); const TAG_OFFSET = 1e9; function startObservingProgress(tag, sharedValue, animationType) { 'worklet'; const isSharedTransition = animationType === _animationBuilder.LayoutAnimationType.SHARED_ELEMENT_TRANSITION; sharedValue.addListener(tag + TAG_OFFSET, () => { _notifyAboutProgress(tag, sharedValue.value, isSharedTransition); }); } function stopObservingProgress(tag, sharedValue, cancelled, removeView) { 'worklet'; sharedValue.removeListener(tag + TAG_OFFSET); _notifyAboutEnd(tag, cancelled, removeView); } function createLayoutAnimationManager() { 'worklet'; const enteringAnimationForTag = new Map(); const mutableValuesForTag = new Map(); return { start(tag, type, yogaValues, config) { const style = config(yogaValues); let currentAnimation = style.animations; if (type === _animationBuilder.LayoutAnimationType.ENTERING) { enteringAnimationForTag.set(tag, currentAnimation); } else if (type === _animationBuilder.LayoutAnimationType.LAYOUT) { // When layout animation is requested, but entering is still running, we merge // new layout animation targets into the ongoing animation const enteringAnimation = enteringAnimationForTag.get(tag); if (enteringAnimation) { currentAnimation = { ...enteringAnimation, ...style.animations }; } } let value = mutableValuesForTag.get(tag); if (value === undefined) { value = (0, _mutables.makeUIMutable)(style.initialValues); mutableValuesForTag.set(tag, value); } else { stopObservingProgress(tag, value, false, false); value._value = style.initialValues; } // @ts-ignore The line below started failing because I added types to the method – don't have time to fix it right now const animation = (0, _styleAnimation.withStyleAnimation)(currentAnimation); animation.callback = finished => { if (finished) { enteringAnimationForTag.delete(tag); mutableValuesForTag.delete(tag); const shouldRemoveView = type === _animationBuilder.LayoutAnimationType.EXITING; stopObservingProgress(tag, value, finished, shouldRemoveView); } style.callback && style.callback(finished === undefined ? false : finished); }; startObservingProgress(tag, value, type); value.value = animation; }, stop(tag) { const value = mutableValuesForTag.get(tag); if (!value) { return; } stopObservingProgress(tag, value, true, true); } }; } (0, _threads.runOnUIImmediately)(() => { 'worklet'; global.LayoutAnimationsManager = createLayoutAnimationManager(); })(); //# sourceMappingURL=animationsManager.js.map