Skip to content

Commit 28e60e7

Browse files
authored
fix: bind blockEvent method to this (#791)
* fix: bind blockEvent method to this * fix: remove console.log
1 parent b8e5954 commit 28e60e7

1 file changed

Lines changed: 17 additions & 16 deletions

File tree

src/index.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export default class Carousel extends React.Component {
8383
this.getOffsetDeltas = this.getOffsetDeltas.bind(this);
8484
this.getTargetLeft = this.getTargetLeft.bind(this);
8585
this.getTouchEvents = this.getTouchEvents.bind(this);
86+
this.blockEvent = this.blockEvent.bind(this);
8687
this.goToSlide = this.goToSlide.bind(this);
8788
this.handleFocus = this.handleFocus.bind(this);
8889
this.handleBlur = this.handleBlur.bind(this);
@@ -281,30 +282,30 @@ export default class Carousel extends React.Component {
281282
}
282283
}
283284

284-
getLockScrollEvents() {
285-
const blockEvent = (e) => {
286-
if (this.state.dragging) {
287-
const direction = swipeDirection(
288-
this.touchObject.startX,
289-
e.touches[0].pageX,
290-
this.touchObject.startY,
291-
e.touches[0].pageY,
292-
this.props.vertical
293-
);
294-
if (direction !== 0) {
295-
e.preventDefault();
296-
}
285+
blockEvent(e) {
286+
if (this.state.dragging) {
287+
const direction = swipeDirection(
288+
this.touchObject.startX,
289+
e.touches[0].pageX,
290+
this.touchObject.startY,
291+
e.touches[0].pageY,
292+
this.props.vertical
293+
);
294+
if (direction !== 0) {
295+
e.preventDefault();
297296
}
298-
};
297+
}
298+
}
299299

300+
getLockScrollEvents() {
300301
const lockTouchScroll = () => {
301-
document.addEventListener('touchmove', blockEvent, {
302+
document.addEventListener('touchmove', this.blockEvent, {
302303
passive: false
303304
});
304305
};
305306

306307
const unlockTouchScroll = () => {
307-
document.removeEventListener('touchmove', blockEvent, {
308+
document.removeEventListener('touchmove', this.blockEvent, {
308309
passive: false
309310
});
310311
};

0 commit comments

Comments
 (0)