Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: reset touch state when iPad Safari loses focus
  • Loading branch information
jtydhr88 committed Dec 3, 2025
commit 5093faa05bc6d0a93ed2a4552210c0fc209c7c73
23 changes: 23 additions & 0 deletions src/extensions/core/simpleTouchSupport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ app.registerExtension({
}
)

// Reset touch state when page loses visibility (e.g., switching apps on iPad)
// This prevents touchCount from getting stuck when touchend events are missed
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
touchCount = 0
touchZooming = false
touchTime = null
lastTouch = null
lastScale = null
touchDist = null
}
})

// Also handle touchcancel which fires when touch is interrupted
app.canvasEl.parentElement?.addEventListener('touchcancel', () => {
touchCount = 0
touchZooming = false
touchTime = null
lastTouch = null
lastScale = null
touchDist = null
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we require the same cleanup, can we extract a method to make sure they stay in sync?

Also, not for this PR, but we might want to find a way to make sure we're cleaning up all the listeners we're adding. It's been a source of memory leaks.

})

app.canvasEl.parentElement?.addEventListener(
'touchmove',
(e) => {
Expand Down