Skip to content

Commit

Permalink
Removed touchStarted/Ended
Browse files Browse the repository at this point in the history
  • Loading branch information
diyaayay committed Nov 18, 2024
1 parent c6d40b8 commit 0b078e9
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 167 deletions.
2 changes: 1 addition & 1 deletion src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class p5 {
pointerdown: null,
pointerup: null,
pointermove: null,
pointercancle:null,
pointercancel:null,
dragend: null,
dragover: null,
click: null,
Expand Down
19 changes: 2 additions & 17 deletions src/events/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1071,12 +1071,7 @@ function mouse(p5, fn){
if (executeDefault === false) {
e.preventDefault();
}
} else if (typeof context.touchMoved === 'function') {
executeDefault = context.touchMoved(e);
if (executeDefault === false) {
e.preventDefault();
}
}
}
}
};

Expand Down Expand Up @@ -1237,12 +1232,7 @@ function mouse(p5, fn){
if (executeDefault === false) {
e.preventDefault();
}
} else if (typeof context.touchStarted === 'function') {
executeDefault = context.touchStarted(e);
if (executeDefault === false) {
e.preventDefault();
}
}
}
};

/**
Expand Down Expand Up @@ -1401,11 +1391,6 @@ function mouse(p5, fn){
if (executeDefault === false) {
e.preventDefault();
}
} else if (typeof context.touchEnded === 'function') {
executeDefault = context.touchEnded(e);
if (executeDefault === false) {
e.preventDefault();
}
}
};

Expand Down
26 changes: 1 addition & 25 deletions src/events/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,10 @@ function touch(p5, fn){
* </div>
*/
fn._ontouchstart = function(e) {
const context = this._isGlobal ? window : this;
let executeDefault;
this.mouseIsPressed = true;
this._updateTouchCoords(e);
this._updateNextMouseCoords(e);
this._updateMouseCoords(); // reset pmouseXY at the start of each touch event

if (typeof context.touchStarted === 'function') {
executeDefault = context.touchStarted(e);
if (executeDefault === false) {
e.preventDefault();
}
this._touchstart = true;
}
};

/**
Expand Down Expand Up @@ -451,12 +441,7 @@ function touch(p5, fn){
let executeDefault;
this._updateTouchCoords(e);
this._updateNextMouseCoords(e);
if (typeof context.touchMoved === 'function') {
executeDefault = context.touchMoved(e);
if (executeDefault === false) {
e.preventDefault();
}
} else if (typeof context.mouseDragged === 'function') {
if (typeof context.mouseDragged === 'function') {
executeDefault = context.mouseDragged(e);
if (executeDefault === false) {
e.preventDefault();
Expand Down Expand Up @@ -622,15 +607,6 @@ function touch(p5, fn){
this.mouseIsPressed = false;
this._updateTouchCoords(e);
this._updateNextMouseCoords(e);
const context = this._isGlobal ? window : this;
let executeDefault;
if (typeof context.touchEnded === 'function') {
executeDefault = context.touchEnded(e);
if (executeDefault === false) {
e.preventDefault();
}
this._touchend = true;
}
};
}

Expand Down
124 changes: 0 additions & 124 deletions test/unit/events/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,128 +56,4 @@ suite('Touch Events', function() {
assert.strictEqual(myp5.touches[0].id, 35);
});
});

suite('touchStarted', function() {
test('touchStarted should be fired when a touch is registered', function() {
let count = 0;
myp5.touchStarted = function() {
count += 1;
};
window.dispatchEvent(new TouchEvent('touchstart'));
assert.strictEqual(count, 1);
});

test('should be fired when a touch starts over the element', function() {
let count = 0;
let div = myp5.createDiv();
let divTouchStarted = function() {
count += 1;
};
div.touchStarted(divTouchStarted);
div.elt.dispatchEvent(new TouchEvent('touchstart'));
assert.strictEqual(count, 1);
});

// NOTE: Required review of parallel sketches test method
test('touchStarted functions on multiple instances must run once', async function() {
let sketchFn = function(sketch, resolve, reject) {
let count = 0;
sketch.touchStarted = function() {
count += 1;
};

sketch.finish = function() {
resolve(count);
};
};
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
await sketches.setup; //wait for all sketches to setup
window.dispatchEvent(new TouchEvent('touchstart'));
sketches.end(); //resolve all sketches by calling their finish functions
let counts = await sketches.result;
assert.deepEqual(counts, [1, 1]);
});
});

suite('touchMoved', function() {
test('touchMoved should be fired when a touchmove is registered', function() {
let count = 0;
myp5.touchMoved = function() {
count += 1;
};
window.dispatchEvent(touchEvent2);
assert.strictEqual(count, 1);
});

test('should be fired when a touchmove is registered over the element', function() {
let count = 0;
let div = myp5.createDiv();
let divTouchMoved = function() {
count += 1;
};
div.touchMoved(divTouchMoved);
div.elt.dispatchEvent(touchEvent2);
assert.strictEqual(count, 1);
});

test('touchMoved functions on multiple instances must run once', async function() {
let sketchFn = function(sketch, resolve, reject) {
let count = 0;
sketch.touchMoved = function() {
count += 1;
};

sketch.finish = function() {
resolve(count);
};
};
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
await sketches.setup; //wait for all sketches to setup
window.dispatchEvent(touchEvent2);
sketches.end(); //resolve all sketches by calling their finish functions
let counts = await sketches.result;
assert.deepEqual(counts, [1, 1]);
});
});

suite('touchEnded', function() {
test('touchEnded must run when a touch is registered', function() {
let count = 0;
myp5.touchEnded = function() {
count += 1;
};
window.dispatchEvent(new TouchEvent('touchend'));
assert.strictEqual(count, 1);
});

test('should be fired when a touch starts over the element', function() {
let count = 0;
let div = myp5.createDiv();
let divTouchEnded = function() {
count += 1;
};
div.touchEnded(divTouchEnded);
div.elt.dispatchEvent(new TouchEvent('touchend'));
assert.strictEqual(count, 1);
});

test('touchEnded functions on multiple instances must run once', async function() {
let sketchFn = function(sketch, resolve, reject) {
let count = 0;
sketch.touchEnded = function() {
count += 1;
};

sketch.finish = function() {
resolve(count);
};
};
let sketches = parallelSketches([sketchFn, sketchFn]); //create two sketches
await sketches.setup; //wait for all sketches to setup
window.dispatchEvent(new TouchEvent('touchend'));
sketches.end(); //resolve all sketches by calling their finish functions
let counts = await sketches.result;
assert.deepEqual(counts, [1, 1]);
});
});
});

0 comments on commit 0b078e9

Please sign in to comment.