UNPKG

react-native-animated-spinkit

Version:
88 lines (71 loc) 2.19 kB
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; } import * as React from 'react'; import { Animated } from 'react-native'; export default class AnimationContainer extends React.Component { constructor(props) { super(props); _defineProperty(this, "animation", void 0); _defineProperty(this, "animatedValuesByKey", {}); _defineProperty(this, "interpolationsByKey", {}); _defineProperty(this, "startAnimation", () => { this.animation.start(); }); _defineProperty(this, "stopAnimation", () => { this.animation.reset(); for (const key in this.animatedValuesByKey) { this.animatedValuesByKey[key].setValue(0); } }); const { initAnimation } = props; const animationInitializersByKey = initAnimation(); const animations = []; for (const key in animationInitializersByKey) { const animationInitializer = animationInitializersByKey[key]; const animationValue = new Animated.Value(0); this.animatedValuesByKey[key] = animationValue; const { animation, values } = animationInitializer(animationValue); animations.push(animation); this.interpolationsByKey[key] = values; } if (animations.length === 1) { this.animation = animations[0]; } else { this.animation = Animated.parallel(animations); } } componentDidMount() { if (this.props.animating) { this.startAnimation(); } } componentDidUpdate(prevProps) { const { animating } = this.props; if (animating !== prevProps.animating) { if (animating) { this.startAnimation(); } else { this.stopAnimation(); } } } componentWillUnmount() { this.animation.stop(); } render() { const { children } = this.props; return children ? children(this.interpolationsByKey) : null; } } _defineProperty(AnimationContainer, "defaultProps", { animating: true }); //# sourceMappingURL=AnimationContainer.js.map