MCPcopy Create free account
hub / github.com/api-platform/website / useAnimation

Function useAnimation

pwa/hooks/con/useAnimation.tsx:65–94  ·  view source on GitHub ↗
(
  direction = "right",
  duration = 1,
  animationValue,
  delay = 0,
  rootMargin = "-10%"
)

Source from the content-addressed store, hash-verified

63 delay?: number,
64 rootMargin?: string
65) => React.RefObject<HTMLDivElement> = (
66 direction = "right",
67 duration = 1,
68 animationValue,
69 delay = 0,
70 rootMargin = "-10%"
71) => {
72 const ref = useRef(null);
73 const [isMobile, setIsMobile] = useState(false);
74 const intersection = useIntersection(ref, {
75 root: null,
76 rootMargin,
77 });
78
79 useEffect(() => {
80 if (typeof window !== undefined) {
81 setIsMobile("ontouchstart" in document.documentElement);
82 }
83 }, [setIsMobile]);
84 if (isMobile) return ref; // no animation on mobile device
85 if (
86 intersection &&
87 ref.current &&
88 ("bottom" !== direction || 0 < intersection.boundingClientRect.y) // avoid intersection box issue
89 ) {
90 if (intersection.isIntersecting) fadeIn(ref.current, duration, delay);
91 else fadeOut(ref.current, direction, duration, animationValue);
92 }
93 return ref;
94};
95
96export default useAnimation;

Callers 7

ContactCardFunction · 0.85
AnimatedPictureImageFunction · 0.85
ReviewItemFunction · 0.85
ListPointFunction · 0.85
FeatureItemFunction · 0.85
CodeBlockFunction · 0.85
StepContentFunction · 0.85

Calls 3

useIntersectionFunction · 0.85
fadeInFunction · 0.85
fadeOutFunction · 0.85

Tested by

no test coverage detected