react-native-modern-elements
Version:
A modern, customizable UI component library for React Native
43 lines (42 loc) • 1.44 kB
JavaScript
// animationHelper.ts
import { FadeIn, FadeInDown, FadeInLeft, FadeInRight, FadeInUp, SlideInDown, SlideInLeft, SlideInRight, SlideInUp, ZoomIn, } from "react-native-reanimated";
/**
* Optimized: Map animation types to actual Reanimated animations
*/
const animationMap = {
fade: FadeIn,
fadeUp: FadeInUp,
fadeDown: FadeInDown,
fadeLeft: FadeInLeft,
fadeRight: FadeInRight,
zoomIn: ZoomIn,
slideUp: SlideInUp,
slideDown: SlideInDown,
slideLeft: SlideInLeft,
slideRight: SlideInRight,
};
/**
* Returns the corresponding Reanimated entering animation
* Supports optional duration, damping, and stagger delay
*/
export const getAnimation = (type, options = {}) => {
const { index = 0, duration = 500, damping, delays = 80, mass = 0.9, stiffness = 110 } = options;
const delay = index * delays;
const animation = animationMap[type];
if (!animation)
return undefined;
let anim = animation.delay(delay).duration(duration);
// ✅ Apply spring config if any spring option is provided
if (damping !== undefined ||
stiffness !== undefined ||
mass !== undefined) {
anim = anim.springify();
if (damping !== undefined)
anim = anim.damping(damping);
if (stiffness !== undefined)
anim = anim.stiffness(stiffness);
if (mass !== undefined)
anim = anim.mass(mass);
}
return anim;
};