Skip to content

fix: two-finger pinch zoom and pan on touch screens#6

Merged
RohitRajendran merged 2 commits intomainfrom
fix-mobile-touchevents
Mar 22, 2026
Merged

fix: two-finger pinch zoom and pan on touch screens#6
RohitRajendran merged 2 commits intomainfrom
fix-mobile-touchevents

Conversation

@RohitRajendran
Copy link
Copy Markdown
Owner

Summary

  • Native TouchEvent listeners on the canvas container now handle two-finger pinch-to-zoom and pan on iPad/touch screens
  • The previous onWheel handler only covered trackpad pinch (which fires wheel events); actual touch screens were unhandled
  • touch-action: none on the canvas div prevents browser-native scroll/zoom from conflicting
  • Pointer handlers bail out early when a two-finger gesture is active, preventing accidental wall/box placement

Technical details

  • touchstart (2 fingers): captures initial zoom, pan, finger distance, and midpoint; clears any in-progress single-finger action
  • touchmove (2 fingers): computes new zoom from pinch ratio and keeps the pinch midpoint anchored in world space (same math as the existing trackpad zoom handler)
  • touchend: clears gesture state with a 50 ms delay so the finger-lift isn't misread as a tap
  • Added data-zoom/data-pan-x/data-pan-y attributes to the canvas div for test observability

Test plan

  • touch-action: none is applied to the canvas container
  • Two-finger pinch-out increases zoom
  • Two-finger pinch-in decreases zoom
  • Two-finger translate (same radius) pans the canvas
  • Two-finger gesture does not create a wall segment while wall tool is active

Handle native TouchEvents for two-finger gestures so pinch-to-zoom and
two-finger pan work on actual touch screens. The previous wheel-based
handler only covered trackpad gestures. Guards on pointer handlers
prevent accidental drawing actions during touch navigation.

- Add touch event listeners (touchstart/move/end) with pinch-zoom math
  that mirrors the existing trackpad zoom (midpoint anchored in world space)
- Add touch-action:none on the canvas div to suppress browser native gestures
- Expose data-zoom/pan-x/pan-y attributes for test observability
- Add E2E tests covering pinch-in, pinch-out, pan, and no accidental wall placement
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 22, 2026

Deploy Preview for snapdraftfloorplans ready!

Name Link
🔨 Latest commit 203f7b9
🔍 Latest deploy log https://app.netlify.com/projects/snapdraftfloorplans/deploys/69c05847706c5b000878d26c
😎 Deploy Preview https://deploy-preview-6--snapdraftfloorplans.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Root cause: Konva repaints its hit canvas asynchronously via
requestAnimationFrame after React commits. Clicking within that frame
window caused the hit test to read the old hit canvas (no elements),
landing on the stage background instead of the restored box.

The fix adds a data-element-count attribute to the canvas div (set during
React's render phase, synchronized with Konva node creation) and waits
for both: the attribute to reflect the restored count, then one
requestAnimationFrame to let Konva finish painting the hit canvas.

This was a pre-existing failure on main (present since commit 64df94f).
@RohitRajendran RohitRajendran merged commit fdc56ef into main Mar 22, 2026
6 checks passed
@RohitRajendran RohitRajendran deleted the fix-mobile-touchevents branch March 22, 2026 21:09
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