Fix GradientBlinds scroll drift on mobile

- Added isMobile detection (<= 768px) in GradientBlinds.tsx
- Updated onPointerMove to calculate container-relative coordinates immediately on mobile
- Updated animation loop to skip scroll-based target updates on mobile
- Prevents spotlight from drifting across the background during scroll inertia on mobile devices

Co-authored-by: ragusa-it <196988693+ragusa-it@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot]
2026-01-29 22:09:19 +00:00
parent 0ba794a1d3
commit 7bc42f8d48

View File

@@ -66,6 +66,7 @@ const GradientBlinds: React.FC<GradientBlindsProps> = ({
const mouseTargetRef = useRef<[number, number]>([0, 0]);
// Optimization: store raw pointer position (viewport coords) to decouple event handling from calculation
const pointerPosRef = useRef<{ x: number; y: number } | null>(null);
const isMobileRef = useRef<boolean>(false);
const lastTimeRef = useRef<number>(0);
const firstResizeRef = useRef<boolean>(true);
const rectRef = useRef<DOMRect | null>(null);
@@ -283,6 +284,7 @@ void main() {
const rect = container.getBoundingClientRect();
rectRef.current = rect;
if (typeof window !== 'undefined') {
isMobileRef.current = window.innerWidth <= 768;
scrollPosRef.current = { x: window.scrollX, y: window.scrollY };
}
renderer.setSize(rect.width, rect.height);
@@ -311,7 +313,30 @@ void main() {
ro.observe(container);
const onPointerMove = (e: PointerEvent) => {
pointerPosRef.current = { x: e.clientX, y: e.clientY };
if (isMobileRef.current) {
// On mobile, calculate relative position immediately and store in target.
// This prevents the "ghost drift" effect when scrolling with inertia after lifting finger,
// because we won't be updating the target based on scroll position in the loop.
const scale = (renderer as unknown as { dpr?: number }).dpr || 1;
let x, y;
if (rectRef.current) {
const dx = window.scrollX - scrollPosRef.current.x;
const dy = window.scrollY - scrollPosRef.current.y;
const rectLeft = rectRef.current.left - dx;
const rectTop = rectRef.current.top - dy;
x = (e.clientX - rectLeft) * scale;
y = (rectRef.current.height - (e.clientY - rectTop)) * scale;
} else {
const rect = canvas.getBoundingClientRect();
x = (e.clientX - rect.left) * scale;
y = (rect.height - (e.clientY - rect.top)) * scale;
}
mouseTargetRef.current = [x, y];
pointerPosRef.current = null; // Ensure loop doesn't override
} else {
pointerPosRef.current = { x: e.clientX, y: e.clientY };
}
};
const loop = (t: number) => {