|
1 | 1 | import React, { Component } from "react"; |
2 | 2 | import PropTypes from "prop-types"; |
3 | | -import throttle from './utils/throttle'; |
| 3 | +import throttle from "./utils/throttle"; |
| 4 | +import { ThresholdUnits, parseThreshold } from "./utils/threshold"; |
4 | 5 |
|
5 | 6 | export default class InfiniteScroll extends Component { |
6 | 7 | constructor(props) { |
@@ -161,8 +162,16 @@ export default class InfiniteScroll extends Component { |
161 | 162 | ? window.screen.availHeight |
162 | 163 | : target.clientHeight; |
163 | 164 |
|
| 165 | + const threshold = parseThreshold(scrollThreshold); |
| 166 | + |
| 167 | + if (threshold.unit === ThresholdUnits.Pixel) { |
| 168 | + return ( |
| 169 | + target.scrollTop + clientHeight >= target.scrollHeight - threshold.value |
| 170 | + ); |
| 171 | + } |
| 172 | + |
164 | 173 | return ( |
165 | | - target.scrollTop + clientHeight >= scrollThreshold * target.scrollHeight |
| 174 | + target.scrollTop + clientHeight >= threshold.value / 100 * target.scrollHeight |
166 | 175 | ); |
167 | 176 | } |
168 | 177 |
|
@@ -263,7 +272,7 @@ InfiniteScroll.propTypes = { |
263 | 272 | hasMore: PropTypes.bool, |
264 | 273 | children: PropTypes.node, |
265 | 274 | loader: PropTypes.node.isRequired, |
266 | | - scrollThreshold: PropTypes.number, |
| 275 | + scrollThreshold: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), |
267 | 276 | endMessage: PropTypes.node, |
268 | 277 | style: PropTypes.object, |
269 | 278 | height: PropTypes.number, |
|
0 commit comments