@fruits-chain/react-native-xiaoshu
Version:
🌈 React Native UI library
50 lines (40 loc) • 1 kB
JavaScript
;
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
});
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]);
};
var _default = useLoop;
exports.default = _default;
//# sourceMappingURL=useLoop.js.map