Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Chrome scroll issue #125

Merged
merged 5 commits into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions dist/InfiniteScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ var InfiniteScroll = (function(_Component) {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.detachScrollListener();
this.detachMousewheelListener();
},

// Set a defaut loader for all your `InfiniteScroll` components
Expand All @@ -127,6 +128,21 @@ var InfiniteScroll = (function(_Component) {
this.defaultLoader = loader;
},
},
{
key: 'detachMousewheelListener',
value: function detachMousewheelListener() {
var scrollEl = window;
if (this.props.useWindow === false) {
scrollEl = this.scrollComponent.parentNode;
}

scrollEl.removeEventListener(
'mousewheel',
this.mousewheelListener,
this.props.useCapture,
);
},
},
{
key: 'detachScrollListener',
value: function detachScrollListener() {
Expand Down Expand Up @@ -159,6 +175,11 @@ var InfiniteScroll = (function(_Component) {
scrollEl = this.scrollComponent.parentNode;
}

scrollEl.addEventListener(
'mousewheel',
this.mousewheelListener,
this.props.useCapture,
);
scrollEl.addEventListener(
'scroll',
this.scrollListener,
Expand All @@ -175,6 +196,16 @@ var InfiniteScroll = (function(_Component) {
}
},
},
{
key: 'mousewheelListener',
value: function mousewheelListener(e) {
// Prevents Chrome hangups
// See: https://stackoverflow.com/questions/47524205/random-high-content-download-time-in-chrome/47684257#47684257
if (e.deltaY === 1) {
e.preventDefault();
}
},
},
{
key: 'scrollListener',
value: function scrollListener() {
Expand Down
27 changes: 27 additions & 0 deletions src/InfiniteScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,27 @@ export default class InfiniteScroll extends Component {

componentWillUnmount() {
this.detachScrollListener();
this.detachMousewheelListener();
}

// Set a defaut loader for all your `InfiniteScroll` components
setDefaultLoader(loader) {
this.defaultLoader = loader;
}

detachMousewheelListener() {
let scrollEl = window;
if (this.props.useWindow === false) {
scrollEl = this.scrollComponent.parentNode;
}

scrollEl.removeEventListener(
'mousewheel',
this.mousewheelListener,
this.props.useCapture,
);
}

detachScrollListener() {
let scrollEl = window;
if (this.props.useWindow === false) {
Expand Down Expand Up @@ -83,6 +97,11 @@ export default class InfiniteScroll extends Component {
scrollEl = this.scrollComponent.parentNode;
}

scrollEl.addEventListener(
'mousewheel',
this.mousewheelListener,
this.props.useCapture,
);
scrollEl.addEventListener(
'scroll',
this.scrollListener,
Expand All @@ -99,6 +118,14 @@ export default class InfiniteScroll extends Component {
}
}

mousewheelListener(e) {
// Prevents Chrome hangups
// See: https://stackoverflow.com/questions/47524205/random-high-content-download-time-in-chrome/47684257#47684257
if (e.deltaY === 1) {
e.preventDefault();
}
}

scrollListener() {
const el = this.scrollComponent;
const scrollEl = window;
Expand Down