Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.
Open
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
41 changes: 23 additions & 18 deletions src/react-infinite.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ var Infinite = createReactClass({

styles: PropTypes.shape({
scrollableStyle: PropTypes.object
}).isRequired
}).isRequired,

onChangeScrollState: PropTypes.func
},
statics: {
containerHeightScaleFactor(factor) {
Expand Down Expand Up @@ -86,8 +88,6 @@ var Infinite = createReactClass({

getDefaultProps(): ReactInfiniteProvidedDefaultProps {
return {
handleScroll: () => {
},

useWindowAsScrollContainer: false,

Expand Down Expand Up @@ -195,7 +195,7 @@ var Infinite = createReactClass({
utilities.unsubscribeFromScrollListener = () => {
window.removeEventListener('scroll', this.infiniteHandleScroll);
};
utilities.nodeScrollListener = () => {};
utilities.nodeScrollListener = null;
utilities.getScrollTop = () => window.pageYOffset;
utilities.setScrollTop = (top) => {
window.scroll(window.pageXOffset, top);
Expand Down Expand Up @@ -274,10 +274,15 @@ var Infinite = createReactClass({
this.setState(nextInternalState.newState);
},

componentWillUpdate() {
componentWillUpdate(nextProps, nextState) {
if (this.props.displayBottomUpwards) {
this.preservedScrollState = this.utils.getScrollTop() - this.loadingSpinnerHeight;
}
if (typeof nextProps.onChangeScrollState === 'function') {
if (nextState.isScrolling !== this.state.isScrolling) {
return nextProps.onChangeScrollState(nextState.isScrolling);
}
}
},

componentDidUpdate(prevProps: ReactInfiniteProps, prevState: ReactInfiniteState) {
Expand Down Expand Up @@ -332,7 +337,7 @@ var Infinite = createReactClass({
if (this.utils.scrollShouldBeIgnored(e)) {
return;
}
this.computedProps.handleScroll(this.scrollable);
if (typeof this.computedProps.handleScroll === 'function') { this.computedProps.handleScroll(this.scrollable); }
this.handleScroll(this.utils.getScrollTop());
},

Expand Down Expand Up @@ -442,20 +447,20 @@ var Infinite = createReactClass({

// topSpacer and bottomSpacer take up the amount of space that the
// rendered elements would have taken up otherwise
return <div className={this.computedProps.className}
ref={(c) => { this.scrollable = c; }}
style={this.utils.buildScrollableStyle()}
onScroll={this.utils.nodeScrollListener}>
<div ref={(c) => { this.smoothScrollingWrapper = c; }} style={infiniteScrollStyles}>
<div ref={(c) => { this.topSpacer = c; }}
style={this.buildHeightStyle(topSpacerHeight)}/>
{this.computedProps.displayBottomUpwards && loadingSpinner}
return (
<div className={this.computedProps.className}
ref={(c) => { this.scrollable = c; }}
style={this.utils.buildScrollableStyle()}
onScroll={this.utils.nodeScrollListener}>
<div ref={(c) => { this.smoothScrollingWrapper = c; }} style={infiniteScrollStyles}>
<div ref={(c) => { this.topSpacer = c; }} style={this.buildHeightStyle(topSpacerHeight)}/>
{this.computedProps.displayBottomUpwards && loadingSpinner}
{displayables}
{!this.computedProps.displayBottomUpwards && loadingSpinner}
<div ref={(c) => { this.bottomSpacer = c; }}
style={this.buildHeightStyle(bottomSpacerHeight)}/>
{!this.computedProps.displayBottomUpwards && loadingSpinner}
<div ref={(c) => { this.bottomSpacer = c; }} style={this.buildHeightStyle(bottomSpacerHeight)}/>
</div>
</div>
</div>;
);
}
});

Expand Down