UNPKG

@fruits-chain/react-native-xiaoshu

Version:
38 lines (36 loc) 1 kB
"use strict"; 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 }); // Animated.loop 暂时没找到每次动画结束后如何重置初始值,暂时采用这个方案 // 这个方案的问题在于很多动画一起就会变得卡顿 const loop = () => { if (stop) { return; } AnimatedValue.setValue(initValue); action.start(({ finished }) => { if (finished) { loop(); } }); }; loop(); return () => { stop = true; action.stop(); }; }, [AnimatedValue, initValue, config.duration, config.toValue, config.easing]); }; export default useLoop; //# sourceMappingURL=useLoop.js.map