fix(ui): drag slider only via arrows handle on phones and make whole trendy bento card clickable
This commit is contained in:
@@ -82,32 +82,32 @@ export function Cinematic3DComparison({
|
||||
};
|
||||
}, [autoSlide, isDragging, updatePosition]);
|
||||
|
||||
// Unified Pointer Handlers (Works with mouse on desktop + touches/pens on mobile/iOS/tablets)
|
||||
// Unified Pointer Handlers on the Slider Arrows Handle
|
||||
const handlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (e.button !== 0 && e.pointerType === 'mouse') return;
|
||||
e.stopPropagation();
|
||||
|
||||
isPointerDownRef.current = true;
|
||||
setIsDragging(true);
|
||||
|
||||
// Capture pointer so fast drags outside the element bounds never lose tracking
|
||||
try {
|
||||
e.currentTarget.setPointerCapture(e.pointerId);
|
||||
} catch {
|
||||
// Fallback
|
||||
}
|
||||
|
||||
// Cache rect on pointer down to eliminate layout thrashing during drag
|
||||
const rect = e.currentTarget.getBoundingClientRect();
|
||||
cachedRectRef.current = { left: rect.left, width: rect.width };
|
||||
|
||||
// Instantly update to pointer position
|
||||
const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width));
|
||||
const percent = (x / rect.width) * 100;
|
||||
updatePosition(percent);
|
||||
if (containerRef.current) {
|
||||
const rect = containerRef.current.getBoundingClientRect();
|
||||
cachedRectRef.current = { left: rect.left, width: rect.width };
|
||||
const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width));
|
||||
const percent = (x / rect.width) * 100;
|
||||
updatePosition(percent);
|
||||
}
|
||||
};
|
||||
|
||||
const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (!isPointerDownRef.current) return;
|
||||
e.stopPropagation();
|
||||
|
||||
const clientX = e.clientX;
|
||||
if (rafIdRef.current) {
|
||||
@@ -131,6 +131,7 @@ export function Cinematic3DComparison({
|
||||
|
||||
const handlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (!isPointerDownRef.current) return;
|
||||
e.stopPropagation();
|
||||
isPointerDownRef.current = false;
|
||||
cachedRectRef.current = null;
|
||||
setIsDragging(false);
|
||||
@@ -163,24 +164,13 @@ export function Cinematic3DComparison({
|
||||
|
||||
return (
|
||||
<div className={`w-full perspective-1400 select-none ${className}`}>
|
||||
{/* 3D Kinetic Tilt Stage with Locked Touch-Action for Flawless Mobile Swiping */}
|
||||
{/* 3D Kinetic Tilt Stage - Allows smooth page scrolling when touching anywhere except the arrows handle */}
|
||||
<div
|
||||
ref={containerRef}
|
||||
onPointerDown={handlePointerDown}
|
||||
onPointerMove={handlePointerMove}
|
||||
onPointerUp={handlePointerUp}
|
||||
onPointerCancel={handlePointerUp}
|
||||
onKeyDown={handleKeyDown}
|
||||
role="slider"
|
||||
aria-label="Before and after comparison"
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
aria-valuenow={50}
|
||||
tabIndex={0}
|
||||
className={`relative w-full ${aspectRatio} rounded-2xl sm:rounded-3xl overflow-hidden cursor-ew-resize preserve-3d transition-transform duration-150 ease-out shadow-cinematic-3d hover:shadow-cinematic-hover border border-slate-900/[0.08] bg-slate-950 touch-none`}
|
||||
className={`relative w-full ${aspectRatio} rounded-2xl sm:rounded-3xl overflow-hidden preserve-3d transition-transform duration-150 ease-out shadow-cinematic-3d hover:shadow-cinematic-hover border border-slate-900/[0.08] bg-slate-950`}
|
||||
style={{
|
||||
'--split': '50%',
|
||||
touchAction: 'none', // Strictly prevents iOS/Android touch scrolling conflict on the slider
|
||||
touchAction: 'pan-y', // Allows mobile vertical scrolling across the image and line
|
||||
} as React.CSSProperties}
|
||||
>
|
||||
{/* Layer 1: After Image (Full Reconstructed Neural Result) */}
|
||||
@@ -208,7 +198,7 @@ export function Cinematic3DComparison({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Layer 3: Illuminated Holographic Laser Split Line */}
|
||||
{/* Layer 3: Illuminated Holographic Laser Split Line (pointer-events-none so it doesn't block scrolling) */}
|
||||
<div
|
||||
className="absolute top-0 bottom-0 w-[2px] bg-gradient-to-b from-blue-400 via-white to-amber-300 z-20 pointer-events-none -translate-x-1/2"
|
||||
style={{ left: 'var(--split)' }}
|
||||
@@ -216,10 +206,24 @@ export function Cinematic3DComparison({
|
||||
{/* Vertical Caustic Glow Beam */}
|
||||
<div className="absolute -top-4 -bottom-4 -left-1.5 w-3.5 bg-gradient-to-r from-blue-500/20 via-white/40 to-amber-400/20 blur-[3px]" />
|
||||
|
||||
{/* 3D Tactile Center Control Handle with generous touch-target area */}
|
||||
{/* 3D Tactile Center Control Handle with Arrows - Dedicated Drag Trigger with Pointer Capture */}
|
||||
<div
|
||||
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-10 h-10 sm:w-11 sm:h-11 rounded-full bg-white/95 backdrop-blur-md border border-slate-900/10 shadow-2xl flex items-center justify-center cursor-ew-resize hover:scale-110 active:scale-95 transition-transform duration-150 preserve-3d before:absolute before:-inset-3 before:content-['']"
|
||||
style={{ transform: 'translateZ(28px)' }}
|
||||
onPointerDown={handlePointerDown}
|
||||
onPointerMove={handlePointerMove}
|
||||
onPointerUp={handlePointerUp}
|
||||
onPointerCancel={handlePointerUp}
|
||||
onKeyDown={handleKeyDown}
|
||||
role="slider"
|
||||
aria-label="Before and after comparison slider"
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
aria-valuenow={50}
|
||||
tabIndex={0}
|
||||
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-10 h-10 sm:w-11 sm:h-11 rounded-full bg-white/95 backdrop-blur-md border border-slate-900/10 shadow-2xl flex items-center justify-center cursor-ew-resize hover:scale-110 active:scale-95 transition-transform duration-150 preserve-3d before:absolute before:-inset-3 before:content-[''] pointer-events-auto touch-none"
|
||||
style={{
|
||||
transform: 'translateZ(28px)',
|
||||
touchAction: 'none', // Strictly locks drag on the arrow handle only
|
||||
}}
|
||||
>
|
||||
{/* Outer Metallic Ring */}
|
||||
<div className="absolute inset-0 rounded-full border border-blue-600/30 shadow-[0_0_12px_rgba(37,99,235,0.3)]" />
|
||||
|
||||
Reference in New Issue
Block a user