Skip to content

Fixed mobile lightbox gallery on PDP#151

Merged
damianlegawiec merged 1 commit into
mainfrom
fix/pdp-mobile-gallery-lightbox
May 14, 2026
Merged

Fixed mobile lightbox gallery on PDP#151
damianlegawiec merged 1 commit into
mainfrom
fix/pdp-mobile-gallery-lightbox

Conversation

@damianlegawiec
Copy link
Copy Markdown
Member

@damianlegawiec damianlegawiec commented May 14, 2026

  • close button works
  • swipe gestures work

Summary by CodeRabbit

  • New Features
    • Product image galleries now support swipe gestures on mobile devices to navigate between images
    • Fullscreen image viewer supports swipe-based navigation with improved touch event handling
    • Enhanced mobile interactions to prevent accidental dismissal while swiping through images

Review Change Stack

* close button works
* swipe gestures work
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
storefront Ready Ready Preview, Comment May 14, 2026 2:31pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Walkthrough

This PR adds swipe gesture navigation to media browsing components. MediaGallery detects horizontal swipes on the main image to navigate gallery items while suppressing lightbox opening. MediaLightbox adds swipe navigation within the modal and prevents unintended closes after touch-based interactions through refined backdrop event handling.

Changes

Swipe Navigation for Media Components

Layer / File(s) Summary
MediaGallery swipe support
src/components/products/MediaGallery.tsx
Import touch handling utilities and swipe pixel thresholds; move index clamping earlier; implement handleTouchStart/handleTouchEnd to detect horizontal swipes and update selectedIndex while suppressing click-based lightbox opening; add touch handlers to main image button and touch-pan-y class.
MediaLightbox swipe and backdrop handling
src/components/products/MediaLightbox.tsx
Define swipe navigation thresholds; introduce refs to track touch start coordinates and backdrop pointerdown target; implement handleTouchStart/handleTouchEnd to detect and navigate on swipes while suppressing synthetic click dismissals; rework backdrop to use conditional onPointerDown/onClick handlers tied to target matching; adjust navigation button padding and set image to pointer-events-none with object-contain.

Sequence Diagrams

sequenceDiagram
  participant User
  participant MediaGallery
  participant State
  User->>MediaGallery: touchstart
  MediaGallery->>State: recordStartCoordinates
  User->>MediaGallery: touchend (horizontal swipe)
  MediaGallery->>State: calculateDelta
  State->>State: updateSelectedIndex
  State->>State: setSuppressClick
  MediaGallery->>User: navigate image (no lightbox)
Loading
sequenceDiagram
  participant User
  participant MediaLightbox
  participant State
  User->>MediaLightbox: touchstart on backdrop
  MediaLightbox->>State: recordBackdropTarget
  MediaLightbox->>State: recordTouchStart
  User->>MediaLightbox: touchend (swipe detected)
  State->>State: navigatePrevOrNext
  MediaLightbox->>MediaLightbox: suppressSyntheticClick
  User->>MediaLightbox: click on backdrop
  MediaLightbox->>MediaLightbox: checkBackdropTarget
  MediaLightbox->>User: close only if backdrop click was direct
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

A gallery of swipes, left and right, 🐰
Touch-pan gestures dancing in the light,
No stray clicks when the user's hand takes flight,
The lightbox knows which target steals the sight,
Mobile magic blooming oh-so-bright! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fixed mobile lightbox gallery on PDP' accurately describes the main changes: enabling swipe gestures and close button functionality in the mobile lightbox on the product detail page.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pdp-mobile-gallery-lightbox

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/components/products/MediaLightbox.tsx (1)

58-89: 💤 Low value

Consider extracting the swipe state machine into a shared hook.

This block is essentially identical to the one just added in MediaGallery.tsx (same SWIPE_THRESHOLD_PX/SWIPE_MAX_VERTICAL_PX, same start/end refs, same dx/dy filter). A small useSwipe({ onSwipeLeft, onSwipeRight }) hook in @/hooks would centralize the thresholds and the touchstart/changedTouches edge cases (!touch guards, clearing touchStartRef even on invalid swipes), and it would keep both consumers in sync if you later tune thresholds or add onSwipeStart/onSwipeEnd callbacks (the latter is already needed here to clear pressedOnBackdropRef).

Not blocking — the current implementation reads correctly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/products/MediaLightbox.tsx` around lines 58 - 89, Extract the
duplicated swipe logic in handleTouchStart and handleTouchEnd (which use
SWIPE_THRESHOLD_PX, SWIPE_MAX_VERTICAL_PX, touchStartRef, pressedOnBackdropRef
and call goNext/goPrev) into a shared hook like useSwipe({ onSwipeLeft,
onSwipeRight, onSwipeEnd? }) in `@/hooks`; move the touchstart/touchend guards
(!touch, clearing touchStartRef on end regardless of validity), the dx/dy
threshold checks, and the synthetic-backdrop suppression (clearing
pressedOnBackdropRef) into the hook, return handlers (e.g., onTouchStart,
onTouchEnd) for MediaLightbox and MediaGallery to call so both consumers use the
same thresholds and behavior and can add optional onSwipeStart/onSwipeEnd
callbacks later.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/components/products/MediaLightbox.tsx`:
- Around line 58-89: Extract the duplicated swipe logic in handleTouchStart and
handleTouchEnd (which use SWIPE_THRESHOLD_PX, SWIPE_MAX_VERTICAL_PX,
touchStartRef, pressedOnBackdropRef and call goNext/goPrev) into a shared hook
like useSwipe({ onSwipeLeft, onSwipeRight, onSwipeEnd? }) in `@/hooks`; move the
touchstart/touchend guards (!touch, clearing touchStartRef on end regardless of
validity), the dx/dy threshold checks, and the synthetic-backdrop suppression
(clearing pressedOnBackdropRef) into the hook, return handlers (e.g.,
onTouchStart, onTouchEnd) for MediaLightbox and MediaGallery to call so both
consumers use the same thresholds and behavior and can add optional
onSwipeStart/onSwipeEnd callbacks later.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c4f8f216-5c23-4784-9407-a27c34b27d74

📥 Commits

Reviewing files that changed from the base of the PR and between 86faa79 and 5115764.

📒 Files selected for processing (2)
  • src/components/products/MediaGallery.tsx
  • src/components/products/MediaLightbox.tsx

@damianlegawiec damianlegawiec merged commit e3dc738 into main May 14, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant