fix(mobile): improve scroll restoration, media gesture swipe, 5-digit otp, persistent cooldown and modal android back navigation
This commit is contained in:
1 parent
00cfd1a2a0
commit
1d2d141514
16 files changed
+12610
-11527
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
"use client";
|
||||
import { useState, useMemo, useEffect } from "react";
|
||||
import { useState, useMemo, useEffect, useRef } from "react";
|
||||
import { motion, AnimatePresence } from "motion/react";
|
||||
import {
|
||||
ArrowRight,
|
||||
@@ -148,6 +148,18 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
description?: string;
|
||||
} | null>(null);
|
||||
|
||||
const thumbnailContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// Auto-scroll active thumbnail into view when changed via gesture/click
|
||||
useEffect(() => {
|
||||
if (thumbnailContainerRef.current) {
|
||||
const activeEl = thumbnailContainerRef.current.children[activeMediaIndex] as HTMLElement;
|
||||
if (activeEl) {
|
||||
activeEl.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' });
|
||||
}
|
||||
}
|
||||
}, [activeMediaIndex]);
|
||||
|
||||
useEffect(() => {
|
||||
Promise.resolve().then(() => setIsMounted(true));
|
||||
}, []);
|
||||
@@ -442,7 +454,32 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
initial={{ opacity: 0, scale: 0.96 }}
|
||||
animate={{ opacity: 1, scale: 1 }}
|
||||
transition={{ duration: 0.2 }}
|
||||
className="bg-white rounded-2xl sm:rounded-[2.5rem] border border-medical-gray-200 shadow-xl relative group overflow-hidden h-[280px] sm:h-[390px] flex items-center justify-center p-2 sm:p-4 select-none"
|
||||
drag="x"
|
||||
dragConstraints={{ left: 0, right: 0 }}
|
||||
dragElastic={0.2}
|
||||
onDragEnd={(e, info) => {
|
||||
const swipeThreshold = 50;
|
||||
if (info.offset.x > swipeThreshold || info.velocity.x > 300) {
|
||||
// Swipe right -> in RTL, swipe right goes to previous item, or left/right intuitive navigation
|
||||
if (activeMediaIndex > 0) {
|
||||
const newIdx = activeMediaIndex - 1;
|
||||
setActiveMediaIndex(newIdx);
|
||||
if (galleryMedia[newIdx]?.type === 'image') {
|
||||
setActiveImage(galleryMedia[newIdx].url);
|
||||
}
|
||||
}
|
||||
} else if (info.offset.x < -swipeThreshold || info.velocity.x < -300) {
|
||||
// Swipe left -> go to next item
|
||||
if (activeMediaIndex < galleryMedia.length - 1) {
|
||||
const newIdx = activeMediaIndex + 1;
|
||||
setActiveMediaIndex(newIdx);
|
||||
if (galleryMedia[newIdx]?.type === 'image') {
|
||||
setActiveImage(galleryMedia[newIdx].url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
className="bg-white rounded-2xl sm:rounded-[2.5rem] border border-medical-gray-200 shadow-xl relative group overflow-hidden h-[280px] sm:h-[390px] flex items-center justify-center p-2 sm:p-4 select-none touch-pan-y cursor-grab active:cursor-grabbing"
|
||||
>
|
||||
{/* Top Floating Badges */}
|
||||
<div className="absolute top-4 left-4 sm:top-6 sm:left-6 flex flex-col gap-1.5 sm:gap-2 z-10 items-start pointer-events-none">
|
||||
@@ -577,7 +614,10 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
|
||||
{/* Multiple Gallery Media Thumbnails Strip */}
|
||||
{galleryMedia.length > 1 && (
|
||||
<div className="flex items-center gap-2 overflow-x-auto py-2 px-1 sleek-hscroll">
|
||||
<div
|
||||
ref={thumbnailContainerRef}
|
||||
className="flex items-center gap-2 overflow-x-auto py-2 px-1 sleek-hscroll touch-pan-x cursor-grab active:cursor-grabbing select-none"
|
||||
>
|
||||
{galleryMedia.map((item, idx) => {
|
||||
const isSelected = activeMediaIndex === idx;
|
||||
|
||||
@@ -601,12 +641,12 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
src={item.thumbnail || item.url || product.image}
|
||||
alt={`${product.name} - ${idx + 1}`}
|
||||
className="w-full h-full"
|
||||
imgClassName="w-full h-full object-contain"
|
||||
imgClassName="w-full h-full object-contain pointer-events-none"
|
||||
/>
|
||||
|
||||
{/* Video Overlay Badge on thumbnail */}
|
||||
{item.type === 'video' && (
|
||||
<div className="absolute inset-0 bg-black/40 flex items-center justify-center">
|
||||
<div className="absolute inset-0 bg-black/40 flex items-center justify-center pointer-events-none">
|
||||
<div className="w-6 h-6 rounded-full bg-canina-blue text-white flex items-center justify-center shadow-md">
|
||||
<Play className="w-3 h-3 fill-white ml-0.5" />
|
||||
</div>
|
||||
@@ -618,7 +658,7 @@ export default function ProductPage({ productSlug }: { productSlug: string }) {
|
||||
|
||||
{/* Podcast Overlay Badge on thumbnail */}
|
||||
{item.type === 'podcast' && (
|
||||
<div className="absolute inset-0 bg-purple-950/60 flex items-center justify-center">
|
||||
<div className="absolute inset-0 bg-purple-950/60 flex items-center justify-center pointer-events-none">
|
||||
<div className="w-6 h-6 rounded-full bg-purple-600 text-white flex items-center justify-center shadow-md">
|
||||
<Headphones className="w-3.5 h-3.5 text-white" />
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user