@fruits-chain/react-native-xiaoshu
Version:
React Native UI library
43 lines (36 loc) • 944 B
JavaScript
import { useEffect } from 'react';
import { Animated } from 'react-native';
const useLoop = (AnimatedValue, initValue, config) => {
useEffect(() => {
let stop = false;
let action;
const loop = () => {
if (stop) {
return;
}
action = 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]);
};
export default useLoop;
//# sourceMappingURL=useLoop.js.map