UNPKG

@fruits-chain/react-native-xiaoshu

Version:
52 lines (42 loc) 1.1 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; let action; const loop = () => { if (stop) { return; } action = _reactNative.Animated.timing(AnimatedValue, { toValue: config.toValue, duration: config.duration, easing: config.easing, useNativeDriver: true }); AnimatedValue.setValue(initValue); action.start(_ref => { let { finished } = _ref; if (finished) { loop(); } }); }; loop(); return () => { var _action; stop = true; (_action = action) === null || _action === void 0 ? void 0 : _action.stop(); }; }, [AnimatedValue, initValue, config.duration, config.toValue, config.easing]); }; var _default = useLoop; exports.default = _default; //# sourceMappingURL=useLoop.js.map