Skip to content

Commit

Permalink
auto load more when scroll to bottom
Browse files Browse the repository at this point in the history
  • Loading branch information
姜坤 authored and 姜坤 committed Nov 26, 2016
1 parent 88e0b63 commit 621f2b2
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/react-touch-loader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export default React.createClass({
},
getDefaultProps () {
return {
distanceToRefresh: 60
distanceToRefresh: 60,
autoLoadMore: 1
};
},
setInitialTouch(touch) {
Expand Down Expand Up @@ -92,25 +93,37 @@ export default React.createClass({
});

// trigger refresh action
this.props.onRefresh(function(){
this.props.onRefresh(() => {
// resove
this.setState({
loaderState: STATS.refreshed,
pullHeight: 0
});
}.bind(this), function(){
}, () => {
// reject
this.setState(endState);// reset
}.bind(this));
});
}else this.setState(endState);// reset
},

loadMore(){
this.setState({ loaderState: STATS.loading });
this.props.onLoadMore(function(){
this.props.onLoadMore(() => {
// resolve
this.setState({loaderState: STATS.init});
}.bind(this));
});
},
onScroll(e) {
if(
this.props.autoLoadMore &&
this.props.hasMore &&
this.state.loaderState != STATS.loading
) {
let panel = e.currentTarget;
let scrollBottom = panel.scrollHeight - panel.clientHeight - panel.scrollTop;

if(scrollBottom < 5) this.loadMore();
}
},

componentWillReceiveProps(nextProps) {
Expand Down Expand Up @@ -158,6 +171,7 @@ export default React.createClass({
return (
<div ref="panel"
className={`tloader state-${loaderState} ${className}${progressClassName}`}
onScroll={this.onScroll}
onTouchStart={this.touchStart}
onTouchMove={this.touchMove}
onTouchEnd={this.touchEnd}
Expand Down

0 comments on commit 621f2b2

Please sign in to comment.