From f4499206a7deb295c05b638261e436a2e2b1ce0c Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:14:25 +0330 Subject: [PATCH] Import source: cshare-app/src/hooks/useLenis Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- cshare-app/src/hooks/useLenis.js | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 cshare-app/src/hooks/useLenis.js diff --git a/cshare-app/src/hooks/useLenis.js b/cshare-app/src/hooks/useLenis.js new file mode 100644 index 0000000..76a241d --- /dev/null +++ b/cshare-app/src/hooks/useLenis.js @@ -0,0 +1,37 @@ +import { useEffect } from 'react'; +import { useLocation } from 'react-router-dom'; +import Lenis from 'lenis'; + +let lenis = null; + +export function useLenis() { + const { pathname } = useLocation(); + + useEffect(() => { + lenis = new Lenis({ + duration: 1.2, + easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), + smoothWheel: true, + wheelMultiplier: 1, + touchMultiplier: 1.5, + }); + + function raf(time) { + lenis.raf(time); + requestAnimationFrame(raf); + } + + const rafId = requestAnimationFrame(raf); + + return () => { + cancelAnimationFrame(rafId); + lenis.destroy(); + lenis = null; + }; + }, []); + + // Scroll to top on route change + useEffect(() => { + if (lenis) lenis.scrollTo(0, { immediate: true }); + }, [pathname]); +}