fix(mobile): drag the image lightbox without re-rendering per move
Each pointermove in the mobile image drag-to-dismiss called setState and re-rendered the lightbox. The drag now writes the image transform and the backdrop and chrome opacity directly to the DOM. React state holds only idle and settling, so a gesture costs two React commits and a tap costs none.
- The settle styles set every property the drag writes, so the settle commit replaces them. A drag that ends without a settle (reduced motion, disabled mid-drag) clears them.
LightboxChromeButtongains awrapperRefprop so the hook can reach the chrome wrappers.
Tests: new cases in media-lightbox.test.tsx check that moves cause no React commit and that an unrelated re-render mid-drag keeps the dragged position; existing cases now also check that the backdrop and chrome have no leftover inline styles after a snap-back and under reduced motion. Ran the file in Chromium and WebKit locally.
Written by Claude.
![View with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v3-3x.png)
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Need help on this PR? Tag @codesmith-bot with what you need.
Summary by Sourcery
Improve mobile image lightbox dragging by applying gesture presentation directly to the DOM while limiting React updates to gesture settling.
Bug Fixes:
- Prevent mobile image drag-to-dismiss interactions from triggering React re-renders on every pointer move.
- Ensure drag-applied inline styles are cleared after snap-back, reduced-motion completion, or interrupted gestures.
Enhancements:
- Preserve the dragged image position and visual state across unrelated lightbox re-renders.
Tests:
- Add coverage for render-free pointer moves, position preservation during re-renders, and cleanup of drag styles across settle paths.
Summary by CodeRabbit
- Bug Fixes
- Improved the mobile image lightbox drag-to-dismiss experience. The image, backdrop, and controls now move together smoothly during a drag, with consistent animations when the gesture ends or is canceled.
- Improved handling of reduced-motion settings during lightbox transitions.
- Made drag interactions more responsive and stable, including when the lightbox updates while a drag is in progress.