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

fix problem which prevented resetting the scroll position with isReverserse=true when scrollContainer has -webkit-overflow-scrolling = auto #218

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,4 @@ You can define a custom `parentNode` element to base the scroll calulations on.
| `threshold` | `Number` | `250` | The distance in pixels before the end of the items that will trigger a call to `loadMore`.|
| `useCapture` | `Boolean` | `false` | Proxy to the `useCapture` option of the added event listeners.|
| `useWindow` | `Boolean` | `true` | Add scroll listeners to the window, or else, the component's `parentNode`.|
| `momentumScrollQuirks` | `Boolean` | `false` | fixes problem which prevents resetting the scroll position after `loadMore` with `isReverse=true` when scrollContainer has `-webkit-overflow-scrolling = auto` ,see [this issue](https://github.com/CassetteRocks/react-infinite-scroller/issues/92)|
16 changes: 13 additions & 3 deletions dist/InfiniteScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,16 @@ var InfiniteScroll = (function(_Component) {
value: function componentDidUpdate() {
if (this.props.isReverse && this.loadMore) {
var parentElement = this.getParentElement(this.scrollComponent);
if (this.props.momentumScrollQuirks) {
parentElement.style['-webkit-overflow-scrolling'] = 'auto';
}
parentElement.scrollTop =
parentElement.scrollHeight -
this.beforeScrollHeight +
this.beforeScrollTop;
if (this.props.momentumScrollQuirks) {
parentElement.style['-webkit-overflow-scrolling'] = 'touch';
}
this.loadMore = false;
}
this.attachScrollListener();
Expand Down Expand Up @@ -358,6 +364,7 @@ var InfiniteScroll = (function(_Component) {
useCapture = renderProps.useCapture,
useWindow = renderProps.useWindow,
getScrollParent = renderProps.getScrollParent,
momentumScrollQuirks = renderProps.momentumScrollQuirks,
props = _objectWithoutProperties(renderProps, [
'children',
'element',
Expand All @@ -371,7 +378,8 @@ var InfiniteScroll = (function(_Component) {
'threshold',
'useCapture',
'useWindow',
'getScrollParent'
'getScrollParent',
'momentumScrollQuirks'
]);

props.ref = function(node) {
Expand Down Expand Up @@ -414,7 +422,8 @@ InfiniteScroll.propTypes = {
getScrollParent: _propTypes2.default.func,
threshold: _propTypes2.default.number,
useCapture: _propTypes2.default.bool,
useWindow: _propTypes2.default.bool
useWindow: _propTypes2.default.bool,
momentumScrollQuirks: _propTypes2.default.bool
};
InfiniteScroll.defaultProps = {
element: 'div',
Expand All @@ -427,7 +436,8 @@ InfiniteScroll.defaultProps = {
isReverse: false,
useCapture: false,
loader: null,
getScrollParent: null
getScrollParent: null,
momentumScrollQuirks: false
};
exports.default = InfiniteScroll;
module.exports = exports['default'];
13 changes: 11 additions & 2 deletions src/InfiniteScroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export default class InfiniteScroll extends Component {
getScrollParent: PropTypes.func,
threshold: PropTypes.number,
useCapture: PropTypes.bool,
useWindow: PropTypes.bool
useWindow: PropTypes.bool,
momentumScrollQuirks: PropTypes.bool
};

static defaultProps = {
Expand All @@ -29,7 +30,8 @@ export default class InfiniteScroll extends Component {
isReverse: false,
useCapture: false,
loader: null,
getScrollParent: null
getScrollParent: null,
momentumScrollQuirks: false
};

constructor(props) {
Expand All @@ -49,10 +51,16 @@ export default class InfiniteScroll extends Component {
componentDidUpdate() {
if (this.props.isReverse && this.loadMore) {
const parentElement = this.getParentElement(this.scrollComponent);
if (this.props.momentumScrollQuirks) {
parentElement.style['-webkit-overflow-scrolling'] = 'auto';
}
parentElement.scrollTop =
parentElement.scrollHeight -
this.beforeScrollHeight +
this.beforeScrollTop;
if (this.props.momentumScrollQuirks) {
parentElement.style['-webkit-overflow-scrolling'] = 'touch';
}
this.loadMore = false;
}
this.attachScrollListener();
Expand Down Expand Up @@ -257,6 +265,7 @@ export default class InfiniteScroll extends Component {
useCapture,
useWindow,
getScrollParent,
momentumScrollQuirks,
...props
} = renderProps;

Expand Down