react-native-micro-interactions
Version:
Effortlessly enhance your React Native components with subtle micro-interactions and animations.
46 lines (42 loc) • 1.23 kB
JavaScript
;
import { useRef } from "react";
export function useRunAnimation(runIndividualAnimation, isGroup) {
// Stores all animations initially, then stores the new animations
let groupAnimationSequence = [];
// Stores all the animations
const allGroupAnimationSequence = 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