From 699ed8ec5996fce57c489cd867259ae46413c50c Mon Sep 17 00:00:00 2001 From: sebastjanartic <45803536-sebastjanartic@users.noreply.replit.com> Date: Wed, 3 Sep 2025 08:49:08 +0000 Subject: [PATCH] Improve video scrolling behavior on mobile devices for smoother navigation Refactors the mobile scrolling logic in the Netflix grid component to accurately calculate the most visible video card. Implements a useCallback hook for the scroll handler and updates the pagination indicator styles for better visual feedback. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/8cc42625-c1f5-4e43-99bd-77f2c4dedee2/2cd2c0bc-434c-4bc9-ad3f-b99d3897a0d1/OdlP8Wj --- client/src/components/netflix-grid.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/client/src/components/netflix-grid.tsx b/client/src/components/netflix-grid.tsx index c708729..1f036e7 100644 --- a/client/src/components/netflix-grid.tsx +++ b/client/src/components/netflix-grid.tsx @@ -1,4 +1,4 @@ -import { useState, useRef, useEffect, useMemo } from "react"; +import { useState, useRef, useEffect, useMemo, useCallback } from "react"; import { useLocation } from "wouter"; import { type Video } from "@shared/schema"; import VideoCard from "./video-card"; @@ -270,10 +270,16 @@ function CategoryRow({ category, onVideoClick, hideScrollButtons = false }: Cate const isMobile = window.innerWidth < 768; if (isMobile) { - // On mobile, one full card at a time - snap to exact position + // On mobile, calculate which card is most visible const cardWidth = containerWidth - 24; // Account for container margins (12px each side) - const newIndex = Math.round(scrollLeft / cardWidth); - setCurrentIndex(Math.min(Math.max(newIndex, 0), 9)); // Ensure 0-9 range + const scrollProgress = scrollLeft / cardWidth; + const newIndex = Math.round(scrollProgress); + const clampedIndex = Math.min(Math.max(newIndex, 0), 9); // Ensure 0-9 range + + // Only update if index actually changed to prevent flickering + if (clampedIndex !== currentIndex) { + setCurrentIndex(clampedIndex); + } } } }; @@ -422,10 +428,10 @@ function CategoryRow({ category, onVideoClick, hideScrollButtons = false }: Cate setCurrentIndex(index); } }} - className={`rounded-full transition-all duration-200 ease-out ${ + className={`rounded-full transition-colors duration-300 ease-in-out ${ index === currentIndex ? 'bg-gradient-to-r from-purple-500 to-blue-500' - : 'bg-white/20 hover:bg-white/30' + : 'bg-white/25 hover:bg-white/40' }`} style={{ width: '8px',