From f579b263b482665a072298167d317e34e7d0ba99 Mon Sep 17 00:00:00 2001 From: vshnosngh Date: Thu, 5 Nov 2026 12:45:11 +0530 Subject: [PATCH] perf(animation): optimize text animations for mobile phones with snappy word-level staggering and instant 120fps physics --- src/components/magicui/text-animate.tsx | 131 +++++++++++++----- src/components/sections/FaqSection.tsx | 4 +- src/components/sections/HeroSection.tsx | 8 +- .../sections/HowItWorks3DSection.tsx | 4 +- .../sections/RecommendedAppsSection.tsx | 4 +- .../sections/ReviewsMarqueeSection.tsx | 4 +- .../sections/ShiftableToolsGridSection.tsx | 4 +- .../sections/TrendyBentoSection.tsx | 4 +- 8 files changed, 110 insertions(+), 53 deletions(-) diff --git a/src/components/magicui/text-animate.tsx b/src/components/magicui/text-animate.tsx index 41b8a5a..6e19bcc 100644 --- a/src/components/magicui/text-animate.tsx +++ b/src/components/magicui/text-animate.tsx @@ -1,6 +1,6 @@ 'use client'; -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { motion, Variants } from 'framer-motion'; export type AnimationType = @@ -27,41 +27,13 @@ interface TextAnimateProps { animation?: AnimationType; } -const defaultItemVariants: Record = { - fadeIn: { - hidden: { opacity: 0 }, - show: { opacity: 1, transition: { duration: 0.5, ease: [0.16, 1, 0.3, 1] } }, - }, - blurIn: { - hidden: { opacity: 0, filter: 'blur(8px)', y: 8 }, - show: { opacity: 1, filter: 'blur(0px)', y: 0, transition: { duration: 0.6, ease: [0.16, 1, 0.3, 1] } }, - }, - slideUp: { - hidden: { y: 24, opacity: 0 }, - show: { y: 0, opacity: 1, transition: { duration: 0.5, ease: [0.16, 1, 0.3, 1] } }, - }, - slideDown: { - hidden: { y: -24, opacity: 0 }, - show: { y: 0, opacity: 1, transition: { duration: 0.5, ease: [0.16, 1, 0.3, 1] } }, - }, - slideLeft: { - hidden: { x: 24, opacity: 0 }, - show: { x: 0, opacity: 1, transition: { duration: 0.5, ease: [0.16, 1, 0.3, 1] } }, - }, - slideRight: { - hidden: { x: -24, opacity: 0 }, - show: { x: 0, opacity: 1, transition: { duration: 0.5, ease: [0.16, 1, 0.3, 1] } }, - }, - scaleUp: { - hidden: { scale: 0.85, opacity: 0 }, - show: { scale: 1, opacity: 1, transition: { duration: 0.5, ease: [0.16, 1, 0.3, 1] } }, - }, -}; +// Ultra-smooth Apple-grade exponential easing +const easeOutApple = [0.16, 1, 0.3, 1]; export function TextAnimate({ children, delay = 0, - duration = 0.4, + duration, className = '', as: Component = 'span', by = 'word', @@ -73,14 +45,99 @@ export function TextAnimate({ return {children}; } - const itemVariant = defaultItemVariants[animation] || defaultItemVariants.slideLeft; + // Detect mobile device to ensure ultra-smooth 60-120fps animations with zero multi-second lag + const [isMobile, setIsMobile] = useState(false); + + useEffect(() => { + if (typeof window === 'undefined') return; + const checkMobile = () => { + setIsMobile( + window.innerWidth < 768 || + (window.matchMedia && window.matchMedia('(pointer: coarse)').matches) + ); + }; + checkMobile(); + window.addEventListener('resize', checkMobile, { passive: true }); + return () => window.removeEventListener('resize', checkMobile); + }, []); + + // On phones, character-by-character animations cause CPU thrashing and take 2-3 seconds. + // Grouping into words on mobile gives instant, silky 120fps motion. + const activeBy = isMobile ? 'word' : by; + const activeDuration = duration ?? (isMobile ? 0.26 : 0.34); + const activeDelay = isMobile ? Math.min(delay * 0.4, 0.08) : delay; + const activeStagger = isMobile + ? 0.018 + : (activeBy === 'character' ? 0.010 : 0.03); + const offset = isMobile ? 10 : 16; + + const itemVariants: Record = { + fadeIn: { + hidden: { opacity: 0 }, + show: { + opacity: 1, + transition: { duration: activeDuration, ease: easeOutApple } + }, + }, + blurIn: { + hidden: { opacity: 0, filter: isMobile ? 'none' : 'blur(5px)', y: offset }, + show: { + opacity: 1, + filter: 'blur(0px)', + y: 0, + transition: { duration: activeDuration, ease: easeOutApple } + }, + }, + slideUp: { + hidden: { y: offset, opacity: 0 }, + show: { + y: 0, + opacity: 1, + transition: { duration: activeDuration, ease: easeOutApple } + }, + }, + slideDown: { + hidden: { y: -offset, opacity: 0 }, + show: { + y: 0, + opacity: 1, + transition: { duration: activeDuration, ease: easeOutApple } + }, + }, + slideLeft: { + hidden: { x: offset, opacity: 0 }, + show: { + x: 0, + opacity: 1, + transition: { duration: activeDuration, ease: easeOutApple } + }, + }, + slideRight: { + hidden: { x: -offset, opacity: 0 }, + show: { + x: 0, + opacity: 1, + transition: { duration: activeDuration, ease: easeOutApple } + }, + }, + scaleUp: { + hidden: { scale: 0.94, opacity: 0 }, + show: { + scale: 1, + opacity: 1, + transition: { duration: activeDuration, ease: easeOutApple } + }, + }, + }; + + const itemVariant = itemVariants[animation] || itemVariants.slideLeft; const containerVariants: Variants = { hidden: {}, show: { transition: { - staggerChildren: by === 'character' ? 0.015 : 0.05, - delayChildren: delay, + staggerChildren: activeStagger, + delayChildren: activeDelay, }, }, }; @@ -95,13 +152,13 @@ export function TextAnimate({ initial="hidden" whileInView={startOnView ? 'show' : undefined} animate={!startOnView ? 'show' : undefined} - viewport={{ once, margin: '-20px' }} + viewport={{ once, margin: '20px' }} className={`inline ${className}`} > {words.map((word, wIdx) => ( - {by === 'character' ? ( + {activeBy === 'character' ? ( Array.from(word).map((char, cIdx) => (

- + {resolvedTitle}

- + Everything you need to know about our browser trial and privacy guarantees.

diff --git a/src/components/sections/HeroSection.tsx b/src/components/sections/HeroSection.tsx index 4e9d20a..aa0d510 100644 --- a/src/components/sections/HeroSection.tsx +++ b/src/components/sections/HeroSection.tsx @@ -317,12 +317,12 @@ export function HeroSection({ {/* Grand Headline: Masterpiece Proportions, Zero Awkward Wraps */}

- + Imagine. Transform. - - + + Create the Impossible. @@ -330,7 +330,7 @@ export function HeroSection({ {/* Inspiring, Refined Editorial Subtitle */}

- + Turn ordinary moments into extraordinary visual art. Instant, effortless, and private photo magic right in your browser.

diff --git a/src/components/sections/HowItWorks3DSection.tsx b/src/components/sections/HowItWorks3DSection.tsx index a13445b..cf5b14e 100644 --- a/src/components/sections/HowItWorks3DSection.tsx +++ b/src/components/sections/HowItWorks3DSection.tsx @@ -46,13 +46,13 @@ export function HowItWorks3DSection({

- + {title}

- + {subtitle}

diff --git a/src/components/sections/RecommendedAppsSection.tsx b/src/components/sections/RecommendedAppsSection.tsx index 889e48b..8f305a6 100644 --- a/src/components/sections/RecommendedAppsSection.tsx +++ b/src/components/sections/RecommendedAppsSection.tsx @@ -96,13 +96,13 @@ export function RecommendedAppsSection({

- + {title}

- + {subtitle}

diff --git a/src/components/sections/ReviewsMarqueeSection.tsx b/src/components/sections/ReviewsMarqueeSection.tsx index 731313a..2fafb42 100644 --- a/src/components/sections/ReviewsMarqueeSection.tsx +++ b/src/components/sections/ReviewsMarqueeSection.tsx @@ -112,13 +112,13 @@ export function ReviewsMarqueeSection({

- + {title}

- + {subtitle}

diff --git a/src/components/sections/ShiftableToolsGridSection.tsx b/src/components/sections/ShiftableToolsGridSection.tsx index 5835a78..61a6890 100644 --- a/src/components/sections/ShiftableToolsGridSection.tsx +++ b/src/components/sections/ShiftableToolsGridSection.tsx @@ -122,13 +122,13 @@ export function ShiftableToolsGridSection({

- + {title}

- + {subtitle}

diff --git a/src/components/sections/TrendyBentoSection.tsx b/src/components/sections/TrendyBentoSection.tsx index d0d0eef..9ab9f15 100644 --- a/src/components/sections/TrendyBentoSection.tsx +++ b/src/components/sections/TrendyBentoSection.tsx @@ -207,13 +207,13 @@ export function TrendyBentoSection({

- + {title}

- + {subtitle}