Skip to content

Commit

Permalink
issue #982 - a ux improvement on skipping rotation while pinching on …
Browse files Browse the repository at this point in the history
…mobile devices
  • Loading branch information
samuelwang48 committed Jan 26, 2022
1 parent 046e57b commit d020b31
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/web/src/most-gestures/drags.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
const { merge } = require('most')

let isPinching = false;

if (typeof window !== "undefined") {
window.addEventListener('pinchStarted', (e) => {
//console.log("received pinch started");
isPinching = true;
});

window.addEventListener('pinchEnded', (e) => {
//console.log("received pinch ended");
isPinching = false;
});
}

// based on http://jsfiddle.net/mattpodwysocki/pfCqq/
const mouseDrags = (mouseDowns$, mouseUps, mouseMoves, settings) => {
const { pixelRatio } = settings
Expand Down Expand Up @@ -47,6 +61,7 @@ const touchDrags = (touchStarts$, touchEnds$, touchMoves$, settings) => {
let prevY = startY

return touchMoves$
.takeWhile((e) => isPinching === false)
.map((e) => {
const curX = e.touches[0].pageX * pixelRatio
const curY = e.touches[0].pageY * pixelRatio
Expand Down
23 changes: 22 additions & 1 deletion packages/web/src/most-gestures/zooms.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
const { merge } = require('most')

if (typeof CustomEvent !== "undefined") {
const pinchStarted = new CustomEvent('pinchStarted', {
detail: true
});

const pinchEnded = new CustomEvent('pinchEnded', {
detail: true
});
}

const pinchZooms = ({ touchStarts$, touchMoves$, touchEnds$ }, settings) => {
const { pixelRatio, pinchThreshold } = settings
// generic custom gesture handling
Expand All @@ -18,6 +28,12 @@ const pinchZooms = ({ touchStarts$, touchMoves$, touchEnds$ }, settings) => {
return touchMoves$
.tap((e) => e.preventDefault())
.filter((t) => t.touches.length === 2)
.tap((e) => {
//console.log("pinch started");
if (typeof pinchStarted !== "undefined") {
window.dispatchEvent(pinchStarted);
}
})
.map((e) => {
const curX1 = e.touches[0].pageX * pixelRatio
const curY1 = e.touches[0].pageY * pixelRatio
Expand All @@ -43,7 +59,12 @@ const pinchZooms = ({ touchStarts$, touchMoves$, touchEnds$ }, settings) => {
const scale = e > 0 ? Math.sqrt(e) : -Math.sqrt(Math.abs(e))
return scale
}) */
.takeUntil(touchEnds$)
.takeUntil(touchEnds$.tap((e) => {
//console.log("pinch ended");
if (typeof pinchStarted !== "undefined") {
window.dispatchEvent(pinchEnded);
}
}))
})
}

Expand Down

0 comments on commit d020b31

Please sign in to comment.