Skip to content

Commit

Permalink
Fixes #522 - Resize without page scrolling on mobile (#640)
Browse files Browse the repository at this point in the history
* Fix resizing on mobile

* Revert fast-memoize upgrade

* Fix `removeEventListener`
  • Loading branch information
Voakie authored Jul 6, 2020
1 parent 5a25a38 commit b7441b9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,10 @@ export class Resizable extends React.PureComponent<ResizableProps, State> {
this.window.addEventListener('mouseup', this.onMouseUp);
this.window.addEventListener('mousemove', this.onMouseMove);
this.window.addEventListener('mouseleave', this.onMouseUp);
this.window.addEventListener('touchmove', this.onMouseMove);
this.window.addEventListener('touchmove', this.onMouseMove, {
capture: true,
passive: false,
});
this.window.addEventListener('touchend', this.onMouseUp);
}
}
Expand All @@ -470,7 +473,7 @@ export class Resizable extends React.PureComponent<ResizableProps, State> {
this.window.removeEventListener('mouseup', this.onMouseUp);
this.window.removeEventListener('mousemove', this.onMouseMove);
this.window.removeEventListener('mouseleave', this.onMouseUp);
this.window.removeEventListener('touchmove', this.onMouseMove);
this.window.removeEventListener('touchmove', this.onMouseMove, true);
this.window.removeEventListener('touchend', this.onMouseUp);
}
}
Expand Down Expand Up @@ -727,6 +730,14 @@ export class Resizable extends React.PureComponent<ResizableProps, State> {
if (!this.state.isResizing || !this.resizable || !this.window) {
return;
}
if (event instanceof TouchEvent) {
try {
event.preventDefault();
event.stopPropagation();
} catch (e) {
// Ignore on fail
}
}
let { maxWidth, maxHeight, minWidth, minHeight } = this.props;
const clientX = event instanceof this.window.MouseEvent ? event.clientX : event.touches[0].clientX;
const clientY = event instanceof this.window.MouseEvent ? event.clientY : event.touches[0].clientY;
Expand Down

0 comments on commit b7441b9

Please sign in to comment.