( direction = "right", duration = 1, animationValue, delay = 0, rootMargin = "-10%" )
| 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 | |
| 96 | export default useAnimation; |
no test coverage detected