UNPKG

@fruits-chain/react-native-xiaoshu

Version:
40 lines (34 loc) • 840 B
import { useEffect } from 'react'; import { Animated } from 'react-native'; const useLoop = (AnimatedValue, initValue, config) => { useEffect(() => { let stop = false; const action = Animated.timing(AnimatedValue, { toValue: config.toValue, duration: config.duration, easing: config.easing, useNativeDriver: true }); const loop = () => { if (stop) { return; } AnimatedValue.setValue(initValue); action.start(_ref => { let { finished } = _ref; if (finished) { loop(); } }); }; loop(); return () => { stop = true; action.stop(); }; }, [AnimatedValue, initValue, config.duration, config.toValue, config.easing]); }; export default useLoop; //# sourceMappingURL=useLoop.js.map