react-native-micro-interactions
Version:
Effortlessly enhance your React Native components with subtle micro-interactions and animations.
50 lines (46 loc) • 1.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useRunAnimation = useRunAnimation;
var _react = require("react");
function useRunAnimation(runIndividualAnimation, isGroup) {
// Stores all animations initially, then stores the new animations
let groupAnimationSequence = [];
// Stores all the animations
const allGroupAnimationSequence = (0, _react.useRef)([]);
function addAnimation(fn) {
groupAnimationSequence.push(fn);
allGroupAnimationSequence.current.push(fn);
}
// Run all the animations, not just the new ones
function runCurrentAnimation() {
if (isGroup) {
groupAnimationSequence.forEach((fn, index) => {
setTimeout(() => {
fn();
}, 200 * index); // Delay each animation by 200ms
});
} else {
runIndividualAnimation();
}
}
// Runs all animations for the first time and then only runs the new animations
function runAnimation() {
if (isGroup) {
allGroupAnimationSequence.current.forEach((fn, index) => {
setTimeout(() => {
fn();
}, 200 * index); // Delay each animation by 200ms
});
} else {
runIndividualAnimation();
}
}
return {
addAnimation,
runCurrentAnimation,
runAnimation
};
}
//# sourceMappingURL=useRunAnimation.js.map