Skip to content

Commit f2116fd

Browse files
author
Ives van Hoorne
committed
Fix gesture scroll, again
1 parent b2ca1e3 commit f2116fd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

packages/app/src/app/components/Preview/DevTools/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,25 @@ export default class DevTools extends React.PureComponent<Props, State> {
115115
}
116116
}
117117

118+
/**
119+
* This stops the propagation of the mousewheel event so the editor itself cannot
120+
* block it to prevent gesture scrolls. Without this scrolling won't work in the
121+
* console.
122+
*/
123+
mouseWheelHandler = (e: WheelEvent) => {
124+
e.stopPropagation();
125+
};
126+
118127
componentDidMount() {
119128
document.addEventListener('mouseup', this.handleMouseUp, false);
120129
document.addEventListener('mousemove', this.handleMouseMove, false);
121130
document.addEventListener('touchend', this.handleTouchEnd, false);
122131
document.addEventListener('touchmove', this.handleTouchMove, false);
123132

133+
if (this.node) {
134+
this.node.addEventListener('mousewheel', this.mouseWheelHandler);
135+
}
136+
124137
if (this.props.shouldExpandDevTools) {
125138
this.openDevTools();
126139
}
@@ -133,6 +146,10 @@ export default class DevTools extends React.PureComponent<Props, State> {
133146
document.removeEventListener('mousemove', this.handleMouseMove, false);
134147
document.removeEventListener('touchend', this.handleTouchEnd, false);
135148
document.removeEventListener('touchmove', this.handleTouchMove, false);
149+
150+
if (this.node) {
151+
this.node.removeEventListener('mousewheel', this.mouseWheelHandler);
152+
}
136153
}
137154

138155
setHidden = (hidden: boolean) => {

packages/app/src/app/pages/Sandbox/Editor/Content/prevent-gesture-scroll.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
function preventScroll(event) {
22
// We don't want to scroll below zero or above the width and height
33
const maxX = this.scrollWidth - this.offsetWidth;
4+
const maxY = this.scrollHeight - this.offsetHeight;
45

56
// If this event looks like it will scroll beyond the bounds of the element, prevent it and set the scroll to the boundary manually
67
if (
78
this.scrollLeft + event.deltaX < 0 ||
8-
this.scrollLeft + event.deltaX > maxX
9+
this.scrollLeft + event.deltaX > maxX ||
10+
this.scrollTop + event.deltaY < 0 ||
11+
this.scrollTop + event.deltaY > maxY
912
) {
1013
event.preventDefault();
1114

@@ -14,6 +17,7 @@ function preventScroll(event) {
1417
0,
1518
Math.min(maxX, this.scrollLeft + event.deltaX)
1619
);
20+
this.scrollTop = Math.max(0, Math.min(maxY, this.scrollTop + event.deltaY));
1721
}
1822
}
1923

0 commit comments

Comments
 (0)