forked from external-repos/squoosh
Fix pinch zoom on iOS (#1133)
This commit is contained in:
28
package-lock.json
generated
28
package-lock.json
generated
@@ -32,7 +32,7 @@
|
||||
"lodash.camelcase": "^4.3.0",
|
||||
"mime-types": "^2.1.28",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"pointer-tracker": "^2.4.0",
|
||||
"pointer-tracker": "^2.5.2",
|
||||
"postcss": "^7.0.35",
|
||||
"postcss-modules": "^3.2.2",
|
||||
"postcss-nested": "^4.2.3",
|
||||
@@ -48,6 +48,20 @@
|
||||
"which": "^2.0.2"
|
||||
}
|
||||
},
|
||||
"../pointer-tracker": {
|
||||
"version": "2.5.0",
|
||||
"extraneous": true,
|
||||
"license": "Apache-2.0",
|
||||
"devDependencies": {
|
||||
"husky": "^4.2.5",
|
||||
"lint-staged": "^10.2.11",
|
||||
"prettier": "^2.0.5",
|
||||
"rollup": "^2.23.1",
|
||||
"rollup-plugin-terser": "^7.0.0",
|
||||
"rollup-plugin-typescript2": "^0.27.2",
|
||||
"typescript": "^3.9.7"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/code-frame": {
|
||||
"version": "7.10.4",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.10.4.tgz",
|
||||
@@ -3871,9 +3885,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/pointer-tracker": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/pointer-tracker/-/pointer-tracker-2.4.0.tgz",
|
||||
"integrity": "sha512-pWI2tpaM/XNtc9mUTv42Rmjf6mkHvE8LT5DDEq0G7baPNhxNM9E3CepubPplSoSLk9E5bwQrAMyDcPVmJyTW4g==",
|
||||
"version": "2.5.2",
|
||||
"resolved": "https://registry.npmjs.org/pointer-tracker/-/pointer-tracker-2.5.2.tgz",
|
||||
"integrity": "sha512-0OZXqAwKo2W7L8ViSpCMDyPj/U40w8zPS/0tfrszz3rcfGTdtQlWDCwKbMRG2YGn7zLxv2kUAIjklAwBgyHHfA==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/postcss": {
|
||||
@@ -11946,9 +11960,9 @@
|
||||
}
|
||||
},
|
||||
"pointer-tracker": {
|
||||
"version": "2.4.0",
|
||||
"resolved": "https://registry.npmjs.org/pointer-tracker/-/pointer-tracker-2.4.0.tgz",
|
||||
"integrity": "sha512-pWI2tpaM/XNtc9mUTv42Rmjf6mkHvE8LT5DDEq0G7baPNhxNM9E3CepubPplSoSLk9E5bwQrAMyDcPVmJyTW4g==",
|
||||
"version": "2.5.2",
|
||||
"resolved": "https://registry.npmjs.org/pointer-tracker/-/pointer-tracker-2.5.2.tgz",
|
||||
"integrity": "sha512-0OZXqAwKo2W7L8ViSpCMDyPj/U40w8zPS/0tfrszz3rcfGTdtQlWDCwKbMRG2YGn7zLxv2kUAIjklAwBgyHHfA==",
|
||||
"dev": true
|
||||
},
|
||||
"postcss": {
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
"lodash.camelcase": "^4.3.0",
|
||||
"mime-types": "^2.1.28",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"pointer-tracker": "^2.4.0",
|
||||
"pointer-tracker": "^2.5.2",
|
||||
"postcss": "^7.0.35",
|
||||
"postcss-modules": "^3.2.2",
|
||||
"postcss-nested": "^4.2.3",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import PointerTracker, { Pointer } from 'pointer-tracker';
|
||||
import 'add-css:./styles.css';
|
||||
import { isSafari } from 'client/lazy-app/util';
|
||||
|
||||
interface Point {
|
||||
clientX: number;
|
||||
@@ -105,14 +106,23 @@ export default class PinchZoom extends HTMLElement {
|
||||
const pointerTracker: PointerTracker = new PointerTracker(this, {
|
||||
start: (pointer, event) => {
|
||||
// We only want to track 2 pointers at most
|
||||
if (pointerTracker.currentPointers.length === 2 || !this._positioningEl)
|
||||
if (
|
||||
pointerTracker.currentPointers.length === 2 ||
|
||||
!this._positioningEl
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
event.preventDefault();
|
||||
return true;
|
||||
},
|
||||
move: (previousPointers) => {
|
||||
this._onPointerMove(previousPointers, pointerTracker.currentPointers);
|
||||
},
|
||||
// Unfortunately Safari on iOS has a bug where pointer event capturing
|
||||
// doesn't work in some cases, and we hit those cases due to our event
|
||||
// retargeting in pinch-zoom.
|
||||
// https://bugs.webkit.org/show_bug.cgi?id=220196
|
||||
avoidPointerEvents: isSafari,
|
||||
});
|
||||
|
||||
this.addEventListener('wheel', (event) => this._onWheel(event));
|
||||
|
||||
@@ -5,7 +5,7 @@ import './custom-els/PinchZoom';
|
||||
import './custom-els/TwoUp';
|
||||
import * as style from './style.css';
|
||||
import 'add-css:./style.css';
|
||||
import { shallowEqual } from '../../util';
|
||||
import { isSafari, shallowEqual } from '../../util';
|
||||
import {
|
||||
ToggleBackgroundIcon,
|
||||
AddIcon,
|
||||
@@ -19,7 +19,6 @@ import { cleanSet } from '../../util/clean-modify';
|
||||
import type { SourceImage } from '../../Compress';
|
||||
import { linkRef } from 'shared/prerendered-app/util';
|
||||
import { drawDataToCanvas } from 'client/lazy-app/util/canvas';
|
||||
|
||||
interface Props {
|
||||
source?: SourceImage;
|
||||
preprocessorState?: PreprocessorState;
|
||||
@@ -275,7 +274,11 @@ export default class Output extends Component<Props, State> {
|
||||
onTouchStartCapture={this.onRetargetableEvent}
|
||||
onTouchEndCapture={this.onRetargetableEvent}
|
||||
onTouchMoveCapture={this.onRetargetableEvent}
|
||||
onPointerDownCapture={this.onRetargetableEvent}
|
||||
onPointerDownCapture={
|
||||
// We avoid pointer events in our PinchZoom due to a Safari bug.
|
||||
// That means we also need to avoid them here too, else we end up preventing the fallback mouse events.
|
||||
isSafari ? undefined : this.onRetargetableEvent
|
||||
}
|
||||
onMouseDownCapture={this.onRetargetableEvent}
|
||||
onWheelCapture={this.onRetargetableEvent}
|
||||
>
|
||||
|
||||
@@ -295,3 +295,7 @@ export async function abortable<T>(
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
export const isSafari =
|
||||
/Safari\//.test(navigator.userAgent) &&
|
||||
!/Chrom(e|ium)\//.test(navigator.userAgent);
|
||||
|
||||
Reference in New Issue
Block a user