Skip to content

Commit b7441b9

Browse files
authored
Fixes #522 - Resize without page scrolling on mobile (#640)
* Fix resizing on mobile * Revert fast-memoize upgrade * Fix `removeEventListener`
1 parent 5a25a38 commit b7441b9

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/index.tsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,10 @@ export class Resizable extends React.PureComponent<ResizableProps, State> {
460460
this.window.addEventListener('mouseup', this.onMouseUp);
461461
this.window.addEventListener('mousemove', this.onMouseMove);
462462
this.window.addEventListener('mouseleave', this.onMouseUp);
463-
this.window.addEventListener('touchmove', this.onMouseMove);
463+
this.window.addEventListener('touchmove', this.onMouseMove, {
464+
capture: true,
465+
passive: false,
466+
});
464467
this.window.addEventListener('touchend', this.onMouseUp);
465468
}
466469
}
@@ -470,7 +473,7 @@ export class Resizable extends React.PureComponent<ResizableProps, State> {
470473
this.window.removeEventListener('mouseup', this.onMouseUp);
471474
this.window.removeEventListener('mousemove', this.onMouseMove);
472475
this.window.removeEventListener('mouseleave', this.onMouseUp);
473-
this.window.removeEventListener('touchmove', this.onMouseMove);
476+
this.window.removeEventListener('touchmove', this.onMouseMove, true);
474477
this.window.removeEventListener('touchend', this.onMouseUp);
475478
}
476479
}
@@ -727,6 +730,14 @@ export class Resizable extends React.PureComponent<ResizableProps, State> {
727730
if (!this.state.isResizing || !this.resizable || !this.window) {
728731
return;
729732
}
733+
if (event instanceof TouchEvent) {
734+
try {
735+
event.preventDefault();
736+
event.stopPropagation();
737+
} catch (e) {
738+
// Ignore on fail
739+
}
740+
}
730741
let { maxWidth, maxHeight, minWidth, minHeight } = this.props;
731742
const clientX = event instanceof this.window.MouseEvent ? event.clientX : event.touches[0].clientX;
732743
const clientY = event instanceof this.window.MouseEvent ? event.clientY : event.touches[0].clientY;

0 commit comments

Comments
 (0)