react-infinite-scroll-component 4.5.2 → 4.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/app/index.js +17 -12
  2. package/lib/index.js +15 -10
  3. package/package.json +1 -1
package/app/index.js CHANGED
@@ -5,17 +5,21 @@ import { ThresholdUnits, parseThreshold } from "./utils/threshold";
5
5
 
6
6
  export default class InfiniteScroll extends Component {
7
7
  constructor(props) {
8
- super();
8
+ super(props);
9
+
10
+ this.lastScrollTop = 0;
11
+ this.actionTriggered = false;
12
+
9
13
  this.state = {
10
14
  showLoader: false,
11
- lastScrollTop: 0,
12
- actionTriggered: false,
13
15
  pullToRefreshThresholdBreached: false
14
16
  };
17
+
15
18
  // variables to keep track of pull down behaviour
16
19
  this.startY = 0;
17
20
  this.currentY = 0;
18
21
  this.dragging = false;
22
+
19
23
  // will be populated in componentDidMount
20
24
  // based on the height of the pull down element
21
25
  this.maxPullDownDistance = 0;
@@ -85,10 +89,10 @@ export default class InfiniteScroll extends Component {
85
89
  // do nothing when dataLength and key are unchanged
86
90
  if (this.props.key === props.key && this.props.dataLength === props.dataLength) return;
87
91
 
92
+ this.actionTriggered = false;
88
93
  // update state when new data was sent in
89
94
  this.setState({
90
95
  showLoader: false,
91
- actionTriggered: false,
92
96
  pullToRefreshThresholdBreached: false
93
97
  });
94
98
  }
@@ -108,7 +112,7 @@ export default class InfiniteScroll extends Component {
108
112
  }
109
113
 
110
114
  onStart(evt) {
111
- if (this.state.lastScrollTop) return;
115
+ if (this.lastScrollTop) return;
112
116
 
113
117
  this.dragging = true;
114
118
  this.startY = evt.pageY || evt.touches[0].pageY;
@@ -194,16 +198,18 @@ export default class InfiniteScroll extends Component {
194
198
 
195
199
  // return immediately if the action has already been triggered,
196
200
  // prevents multiple triggers.
197
- if (this.state.actionTriggered) return;
201
+ if (this.actionTriggered) return;
198
202
 
199
203
  let atBottom = this.isElementAtBottom(target, this.props.scrollThreshold);
200
204
 
201
205
  // call the `next` function in the props to trigger the next data fetch
202
206
  if (atBottom && this.props.hasMore) {
203
- this.setState({ actionTriggered: true, showLoader: true });
207
+ this.actionTriggered = true;
208
+ this.setState({ showLoader: true });
204
209
  this.props.next();
205
210
  }
206
- this.setState({ lastScrollTop: target.scrollTop });
211
+
212
+ this.lastScrollTop = target.scrollTop;
207
213
  }
208
214
 
209
215
  render() {
@@ -243,10 +249,9 @@ export default class InfiniteScroll extends Component {
243
249
  top: -1 * this.maxPullDownDistance
244
250
  }}
245
251
  >
246
- {!this.state.pullToRefreshThresholdBreached &&
247
- this.props.pullDownToRefreshContent}
248
- {this.state.pullToRefreshThresholdBreached &&
249
- this.props.releaseToRefreshContent}
252
+ {this.state.pullToRefreshThresholdBreached
253
+ ? this.props.releaseToRefreshContent
254
+ : this.props.pullDownToRefreshContent}
250
255
  </div>
251
256
  </div>
252
257
  )}
package/lib/index.js CHANGED
@@ -92,17 +92,21 @@ return /******/ (function(modules) { // webpackBootstrap
92
92
  function InfiniteScroll(props) {
93
93
  _classCallCheck(this, InfiniteScroll);
94
94
 
95
- _get(Object.getPrototypeOf(InfiniteScroll.prototype), "constructor", this).call(this);
95
+ _get(Object.getPrototypeOf(InfiniteScroll.prototype), "constructor", this).call(this, props);
96
+
97
+ this.lastScrollTop = 0;
98
+ this.actionTriggered = false;
99
+
96
100
  this.state = {
97
101
  showLoader: false,
98
- lastScrollTop: 0,
99
- actionTriggered: false,
100
102
  pullToRefreshThresholdBreached: false
101
103
  };
104
+
102
105
  // variables to keep track of pull down behaviour
103
106
  this.startY = 0;
104
107
  this.currentY = 0;
105
108
  this.dragging = false;
109
+
106
110
  // will be populated in componentDidMount
107
111
  // based on the height of the pull down element
108
112
  this.maxPullDownDistance = 0;
@@ -165,10 +169,10 @@ return /******/ (function(modules) { // webpackBootstrap
165
169
  // do nothing when dataLength and key are unchanged
166
170
  if (this.props.key === props.key && this.props.dataLength === props.dataLength) return;
167
171
 
172
+ this.actionTriggered = false;
168
173
  // update state when new data was sent in
169
174
  this.setState({
170
175
  showLoader: false,
171
- actionTriggered: false,
172
176
  pullToRefreshThresholdBreached: false
173
177
  });
174
178
  }
@@ -187,7 +191,7 @@ return /******/ (function(modules) { // webpackBootstrap
187
191
  }, {
188
192
  key: "onStart",
189
193
  value: function onStart(evt) {
190
- if (this.state.lastScrollTop) return;
194
+ if (this.lastScrollTop) return;
191
195
 
192
196
  this.dragging = true;
193
197
  this.startY = evt.pageY || evt.touches[0].pageY;
@@ -272,16 +276,18 @@ return /******/ (function(modules) { // webpackBootstrap
272
276
 
273
277
  // return immediately if the action has already been triggered,
274
278
  // prevents multiple triggers.
275
- if (this.state.actionTriggered) return;
279
+ if (this.actionTriggered) return;
276
280
 
277
281
  var atBottom = this.isElementAtBottom(target, this.props.scrollThreshold);
278
282
 
279
283
  // call the `next` function in the props to trigger the next data fetch
280
284
  if (atBottom && this.props.hasMore) {
281
- this.setState({ actionTriggered: true, showLoader: true });
285
+ this.actionTriggered = true;
286
+ this.setState({ showLoader: true });
282
287
  this.props.next();
283
288
  }
284
- this.setState({ lastScrollTop: target.scrollTop });
289
+
290
+ this.lastScrollTop = target.scrollTop;
285
291
  }
286
292
  }, {
287
293
  key: "render",
@@ -328,8 +334,7 @@ return /******/ (function(modules) { // webpackBootstrap
328
334
  top: -1 * this.maxPullDownDistance
329
335
  }
330
336
  },
331
- !this.state.pullToRefreshThresholdBreached && this.props.pullDownToRefreshContent,
332
- this.state.pullToRefreshThresholdBreached && this.props.releaseToRefreshContent
337
+ this.state.pullToRefreshThresholdBreached ? this.props.releaseToRefreshContent : this.props.pullDownToRefreshContent
333
338
  )
334
339
  ),
335
340
  this.props.children,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-infinite-scroll-component",
3
- "version": "4.5.2",
3
+ "version": "4.5.3",
4
4
  "description": "An Infinite Scroll component in react.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {