Skip to content

Commit 24339fc

Browse files
authored
Merge pull request #3853 from outofambit/bugfix/safari-touch-event-duplication
fix mobile safari for touch event duplication
2 parents 18ef917 + 1984883 commit 24339fc

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/events/mouse.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,12 +629,17 @@ p5.prototype._onmousedown = function(e) {
629629
this._setProperty('mouseIsPressed', true);
630630
this._setMouseButton(e);
631631
this._updateNextMouseCoords(e);
632+
632633
if (typeof context.mousePressed === 'function') {
633634
executeDefault = context.mousePressed(e);
634635
if (executeDefault === false) {
635636
e.preventDefault();
636637
}
637-
} else if (typeof context.touchStarted === 'function') {
638+
// only safari needs this manual fallback for consistency
639+
} else if (
640+
navigator.userAgent.toLowerCase().includes('safari') &&
641+
typeof context.touchStarted === 'function'
642+
) {
638643
executeDefault = context.touchStarted(e);
639644
if (executeDefault === false) {
640645
e.preventDefault();

src/events/touch.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,17 @@ p5.prototype._ontouchstart = function(e) {
133133
this._updateTouchCoords(e);
134134
this._updateNextMouseCoords(e);
135135
this._updateMouseCoords(); // reset pmouseXY at the start of each touch event
136+
136137
if (typeof context.touchStarted === 'function') {
137138
executeDefault = context.touchStarted(e);
138139
if (executeDefault === false) {
139140
e.preventDefault();
140141
}
141-
} else if (typeof context.mousePressed === 'function') {
142+
// only safari needs this manual fallback for consistency
143+
} else if (
144+
navigator.userAgent.toLowerCase().includes('safari') &&
145+
typeof context.touchStarted === 'function'
146+
) {
142147
executeDefault = context.mousePressed(e);
143148
if (executeDefault === false) {
144149
e.preventDefault();

0 commit comments

Comments
 (0)