Skip to content

Commit

Permalink
Fix/touch cancel 441 (#443)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbismut authored Feb 11, 2022
1 parent 9c47ba9 commit 916d178
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/shiny-chefs-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@use-gesture/core': patch
---

fix: make sure the drag gesture is ended when `touchcancel` event is triggered.
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"postinstall": "patch-package",
"dev": "vite --port 4000",
"dev": "vite --port 4000 --host",
"build": "vite build",
"serve": "vite preview"
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/engines/DragEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export class DragEngine extends CoordinatesEngine<'drag'> {
if (!config.pointerCapture) {
this.eventStore.add(this.sharedConfig.window!, device, 'change', this.pointerMove.bind(this))
this.eventStore.add(this.sharedConfig.window!, device, 'end', this.pointerUp.bind(this))
this.eventStore.add(this.sharedConfig.window!, device, 'cancel', this.pointerUp.bind(this))
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function getCurrentTargetTouchList(event: TouchEvent) {
}

function getTouchList(event: TouchEvent) {
return event.type === 'touchend' ? event.changedTouches : event.targetTouches
return event.type === 'touchend' || event.type === 'touchcancel' ? event.changedTouches : event.targetTouches
}

function getValueEvent<EventType extends TouchEvent | PointerEvent>(
Expand Down

0 comments on commit 916d178

Please sign in to comment.