react-infinite-scroll-component 4.4.0 → 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.
package/README.md CHANGED
@@ -71,6 +71,7 @@ name | type | description
71
71
  **scrollThreshold** | number | string | A threshold value defining when `InfiniteScroll` will call `next`. Default value is `0.8`. It means the `next` will be called when user comes below 80% of the total height. If you pass threshold in pixels (`scrollThreshold="200px"`), `next` will be called once you scroll at least (100% - scrollThreshold) pixels down.
72
72
  **onScroll** | function | a function that will listen to the scroll event on the scrolling container. Note that the scroll event is throttled, so you may not receive as many events as you would expect.
73
73
  **endMessage** | node | this message is shown to the user when he has seen all the records which means he's at the bottom and `hasMore` is `false`
74
+ **className** | string | add any custom class you want
74
75
  **style** | object | any style which you want to override
75
76
  **height** | number | optional, give only if you want to have a fixed height scrolling content
76
77
  **scrollableTarget** | node or string | optional, reference to a (parent) DOM element that is already providing overflow scrollbars to the `InfiniteScroll` component. *You should provide the `id` of the DOM node preferably.*
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;
@@ -150,9 +154,12 @@ export default class InfiniteScroll extends Component {
150
154
  }
151
155
 
152
156
  requestAnimationFrame(() => {
153
- this._infScroll.style.overflow = "auto";
154
- this._infScroll.style.transform = "none";
155
- this._infScroll.style.willChange = "none";
157
+ // this._infScroll
158
+ if (this._infScroll) {
159
+ this._infScroll.style.overflow = "auto";
160
+ this._infScroll.style.transform = "none";
161
+ this._infScroll.style.willChange = "none";
162
+ }
156
163
  });
157
164
  }
158
165
 
@@ -191,16 +198,18 @@ export default class InfiniteScroll extends Component {
191
198
 
192
199
  // return immediately if the action has already been triggered,
193
200
  // prevents multiple triggers.
194
- if (this.state.actionTriggered) return;
201
+ if (this.actionTriggered) return;
195
202
 
196
203
  let atBottom = this.isElementAtBottom(target, this.props.scrollThreshold);
197
204
 
198
205
  // call the `next` function in the props to trigger the next data fetch
199
206
  if (atBottom && this.props.hasMore) {
200
- this.setState({ actionTriggered: true, showLoader: true });
207
+ this.actionTriggered = true;
208
+ this.setState({ showLoader: true });
201
209
  this.props.next();
202
210
  }
203
- this.setState({ lastScrollTop: target.scrollTop });
211
+
212
+ this.lastScrollTop = target.scrollTop;
204
213
  }
205
214
 
206
215
  render() {
@@ -223,7 +232,7 @@ export default class InfiniteScroll extends Component {
223
232
  return (
224
233
  <div style={outerDivStyle}>
225
234
  <div
226
- className="infinite-scroll-component"
235
+ className={`infinite-scroll-component ${this.props.className || ''}`}
227
236
  ref={infScroll => (this._infScroll = infScroll)}
228
237
  style={style}
229
238
  >
@@ -240,10 +249,9 @@ export default class InfiniteScroll extends Component {
240
249
  top: -1 * this.maxPullDownDistance
241
250
  }}
242
251
  >
243
- {!this.state.pullToRefreshThresholdBreached &&
244
- this.props.pullDownToRefreshContent}
245
- {this.state.pullToRefreshThresholdBreached &&
246
- this.props.releaseToRefreshContent}
252
+ {this.state.pullToRefreshThresholdBreached
253
+ ? this.props.releaseToRefreshContent
254
+ : this.props.pullDownToRefreshContent}
247
255
  </div>
248
256
  </div>
249
257
  )}
@@ -17,14 +17,14 @@ export function parseThreshold(scrollThreshold) {
17
17
  }
18
18
 
19
19
  if (typeof scrollThreshold === "string") {
20
- if (scrollThreshold.match(/^(\d*(.\d+)?)px$/)) {
20
+ if (scrollThreshold.match(/^(\d*(\.\d+)?)px$/)) {
21
21
  return {
22
22
  unit: ThresholdUnits.Pixel,
23
23
  value: parseFloat(scrollThreshold),
24
24
  };
25
25
  }
26
26
 
27
- if (scrollThreshold.match(/^(\d*(.\d+)?)%$/)) {
27
+ if (scrollThreshold.match(/^(\d*(\.\d+)?)%$/)) {
28
28
  return {
29
29
  unit: ThresholdUnits.Percent,
30
30
  value: parseFloat(scrollThreshold),
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;
@@ -232,9 +236,12 @@ return /******/ (function(modules) { // webpackBootstrap
232
236
  }
233
237
 
234
238
  requestAnimationFrame(function () {
235
- _this._infScroll.style.overflow = "auto";
236
- _this._infScroll.style.transform = "none";
237
- _this._infScroll.style.willChange = "none";
239
+ // this._infScroll
240
+ if (_this._infScroll) {
241
+ _this._infScroll.style.overflow = "auto";
242
+ _this._infScroll.style.transform = "none";
243
+ _this._infScroll.style.willChange = "none";
244
+ }
238
245
  });
239
246
  }
240
247
  }, {
@@ -269,16 +276,18 @@ return /******/ (function(modules) { // webpackBootstrap
269
276
 
270
277
  // return immediately if the action has already been triggered,
271
278
  // prevents multiple triggers.
272
- if (this.state.actionTriggered) return;
279
+ if (this.actionTriggered) return;
273
280
 
274
281
  var atBottom = this.isElementAtBottom(target, this.props.scrollThreshold);
275
282
 
276
283
  // call the `next` function in the props to trigger the next data fetch
277
284
  if (atBottom && this.props.hasMore) {
278
- this.setState({ actionTriggered: true, showLoader: true });
285
+ this.actionTriggered = true;
286
+ this.setState({ showLoader: true });
279
287
  this.props.next();
280
288
  }
281
- this.setState({ lastScrollTop: target.scrollTop });
289
+
290
+ this.lastScrollTop = target.scrollTop;
282
291
  }
283
292
  }, {
284
293
  key: "render",
@@ -301,7 +310,7 @@ return /******/ (function(modules) { // webpackBootstrap
301
310
  _react2["default"].createElement(
302
311
  "div",
303
312
  {
304
- className: "infinite-scroll-component",
313
+ className: "infinite-scroll-component " + (this.props.className || ''),
305
314
  ref: function (infScroll) {
306
315
  return _this3._infScroll = infScroll;
307
316
  },
@@ -325,8 +334,7 @@ return /******/ (function(modules) { // webpackBootstrap
325
334
  top: -1 * this.maxPullDownDistance
326
335
  }
327
336
  },
328
- !this.state.pullToRefreshThresholdBreached && this.props.pullDownToRefreshContent,
329
- this.state.pullToRefreshThresholdBreached && this.props.releaseToRefreshContent
337
+ this.state.pullToRefreshThresholdBreached ? this.props.releaseToRefreshContent : this.props.pullDownToRefreshContent
330
338
  )
331
339
  ),
332
340
  this.props.children,
@@ -410,14 +418,14 @@ return /******/ (function(modules) { // webpackBootstrap
410
418
  }
411
419
 
412
420
  if (typeof scrollThreshold === "string") {
413
- if (scrollThreshold.match(/^(\d*(.\d+)?)px$/)) {
421
+ if (scrollThreshold.match(/^(\d*(\.\d+)?)px$/)) {
414
422
  return {
415
423
  unit: ThresholdUnits.Pixel,
416
424
  value: parseFloat(scrollThreshold)
417
425
  };
418
426
  }
419
427
 
420
- if (scrollThreshold.match(/^(\d*(.\d+)?)%$/)) {
428
+ if (scrollThreshold.match(/^(\d*(\.\d+)?)%$/)) {
421
429
  return {
422
430
  unit: ThresholdUnits.Percent,
423
431
  value: parseFloat(scrollThreshold)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-infinite-scroll-component",
3
- "version": "4.4.0",
3
+ "version": "4.5.3",
4
4
  "description": "An Infinite Scroll component in react.",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {