Skip to content

Commit 73328b3

Browse files
krnldechrvadala
authored andcommitted
Migrate onWheel event to be non-passive, which fixes #141 (#158)
* Migrate onWheel event to be non-passive, which fixes #141 * cleanup * Convert onWheel to a real method instead of arrow-function instrance property.
1 parent 8c70a33 commit 73328b3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/viewer.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export default class ReactSVGPanZoom extends React.Component {
8282
defaultValue
8383
}
8484
this.autoPanLoop = this.autoPanLoop.bind(this);
85+
this.onWheel = this.onWheel.bind(this);
8586

8687
if (process.env.NODE_ENV !== 'production') {
8788
printMigrationTipsRelatedToProps(props)
@@ -145,10 +146,12 @@ export default class ReactSVGPanZoom extends React.Component {
145146
componentDidMount() {
146147
this.autoPanIsRunning = true;
147148
requestAnimationFrame(this.autoPanLoop);
149+
this.ViewerDOM.addEventListener('wheel', this.onWheel, false);
148150
}
149151

150152
componentWillUnmount() {
151153
this.autoPanIsRunning = false;
154+
this.ViewerDOM.removeEventListener('wheel', this.onWheel);
152155
}
153156

154157
/** ReactSVGPanZoom handlers **/
@@ -257,6 +260,11 @@ export default class ReactSVGPanZoom extends React.Component {
257260
}
258261
}
259262

263+
onWheel(event) {
264+
let nextValue = onWheel(event, this.ViewerDOM, this.getTool(), this.getValue(), this.props);
265+
if (this.getValue() !== nextValue) this.setValue(nextValue);
266+
}
267+
260268
/** React renderer **/
261269
render() {
262270
let {props, state: {pointerX, pointerY}} = this;
@@ -330,11 +338,6 @@ export default class ReactSVGPanZoom extends React.Component {
330338
this.handleViewerEvent(event);
331339
}}
332340

333-
onWheel={event => {
334-
let nextValue = onWheel(event, this.ViewerDOM, this.getTool(), this.getValue(), this.props);
335-
if (this.getValue() !== nextValue) this.setValue(nextValue);
336-
}}
337-
338341
onMouseEnter={event => {
339342
if (detectTouch()) return;
340343
let nextValue = onMouseEnterOrLeave(event, this.ViewerDOM, this.getTool(), this.getValue(), this.props);

0 commit comments

Comments
 (0)