UNPKG

@fruits-chain/react-native-xiaoshu

Version:
42 lines (40 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = require("react"); var _reactNative = require("react-native"); const useLoop = (AnimatedValue, initValue, config) => { (0, _react.useEffect)(() => { let stop = false; const action = _reactNative.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]); }; var _default = exports.default = useLoop; //# sourceMappingURL=useLoop.js.map