1- import React , { Component , ReactNode , CSSProperties } from " react" ;
2- import { throttle } from " throttle-debounce" ;
3- import { ThresholdUnits , parseThreshold } from " ./utils/threshold" ;
1+ import React , { Component , ReactNode , CSSProperties } from ' react' ;
2+ import { throttle } from ' throttle-debounce' ;
3+ import { ThresholdUnits , parseThreshold } from ' ./utils/threshold' ;
44
55type Fn = ( ) => any ;
66interface Props {
@@ -37,7 +37,7 @@ export default class InfiniteScroll extends Component<Props, State> {
3737
3838 this . state = {
3939 showLoader : false ,
40- pullToRefreshThresholdBreached : false
40+ pullToRefreshThresholdBreached : false ,
4141 } ;
4242
4343 this . onScrollListener = this . onScrollListener . bind ( this ) ;
@@ -59,13 +59,13 @@ export default class InfiniteScroll extends Component<Props, State> {
5959 private _pullDown : HTMLDivElement | undefined ;
6060
6161 // variables to keep track of pull down behaviour
62- private startY : number = 0 ;
63- private currentY : number = 0 ;
64- private dragging : boolean = false ;
62+ private startY = 0 ;
63+ private currentY = 0 ;
64+ private dragging = false ;
6565
6666 // will be populated in componentDidMount
6767 // based on the height of the pull down element
68- private maxPullDownDistance : number = 0 ;
68+ private maxPullDownDistance = 0 ;
6969
7070 componentDidMount ( ) {
7171 this . _scrollableNode = this . getScrollableTarget ( ) ;
@@ -74,13 +74,13 @@ export default class InfiniteScroll extends Component<Props, State> {
7474 : this . _scrollableNode || window ;
7575
7676 if ( this . el ) {
77- this . el . addEventListener ( " scroll" , e =>
77+ this . el . addEventListener ( ' scroll' , e =>
7878 this . throttledOnScrollListener ( e as MouseEvent )
7979 ) ;
8080 }
8181
8282 if (
83- typeof this . props . initialScrollY === " number" &&
83+ typeof this . props . initialScrollY === ' number' &&
8484 this . el &&
8585 this . el instanceof HTMLElement &&
8686 this . el . scrollHeight > this . props . initialScrollY
@@ -89,13 +89,13 @@ export default class InfiniteScroll extends Component<Props, State> {
8989 }
9090
9191 if ( this . props . pullDownToRefresh && this . el ) {
92- this . el . addEventListener ( " touchstart" , this . onStart ) ;
93- this . el . addEventListener ( " touchmove" , this . onMove ) ;
94- this . el . addEventListener ( " touchend" , this . onEnd ) ;
92+ this . el . addEventListener ( ' touchstart' , this . onStart ) ;
93+ this . el . addEventListener ( ' touchmove' , this . onMove ) ;
94+ this . el . addEventListener ( ' touchend' , this . onEnd ) ;
9595
96- this . el . addEventListener ( " mousedown" , this . onStart ) ;
97- this . el . addEventListener ( " mousemove" , this . onMove ) ;
98- this . el . addEventListener ( " mouseup" , this . onEnd ) ;
96+ this . el . addEventListener ( ' mousedown' , this . onStart ) ;
97+ this . el . addEventListener ( ' mousemove' , this . onMove ) ;
98+ this . el . addEventListener ( ' mouseup' , this . onEnd ) ;
9999
100100 // get BCR of pullDown element to position it above
101101 this . maxPullDownDistance =
@@ -106,7 +106,7 @@ export default class InfiniteScroll extends Component<Props, State> {
106106 0 ;
107107 this . forceUpdate ( ) ;
108108
109- if ( typeof this . props . refreshFunction !== " function" ) {
109+ if ( typeof this . props . refreshFunction !== ' function' ) {
110110 throw new Error (
111111 `Mandatory prop "refreshFunction" missing.
112112 Pull Down To Refresh functionality will not work
@@ -118,18 +118,18 @@ export default class InfiniteScroll extends Component<Props, State> {
118118
119119 componentWillUnmount ( ) {
120120 if ( this . el ) {
121- this . el . removeEventListener ( " scroll" , e =>
121+ this . el . removeEventListener ( ' scroll' , e =>
122122 this . throttledOnScrollListener ( e as MouseEvent )
123123 ) ;
124124
125125 if ( this . props . pullDownToRefresh ) {
126- this . el . removeEventListener ( " touchstart" , this . onStart ) ;
127- this . el . removeEventListener ( " touchmove" , this . onMove ) ;
128- this . el . removeEventListener ( " touchend" , this . onEnd ) ;
126+ this . el . removeEventListener ( ' touchstart' , this . onStart ) ;
127+ this . el . removeEventListener ( ' touchmove' , this . onMove ) ;
128+ this . el . removeEventListener ( ' touchend' , this . onEnd ) ;
129129
130- this . el . removeEventListener ( " mousedown" , this . onStart ) ;
131- this . el . removeEventListener ( " mousemove" , this . onMove ) ;
132- this . el . removeEventListener ( " mouseup" , this . onEnd ) ;
130+ this . el . removeEventListener ( ' mousedown' , this . onStart ) ;
131+ this . el . removeEventListener ( ' mousemove' , this . onMove ) ;
132+ this . el . removeEventListener ( ' mouseup' , this . onEnd ) ;
133133 }
134134 }
135135 }
@@ -146,14 +146,14 @@ export default class InfiniteScroll extends Component<Props, State> {
146146 // update state when new data was sent in
147147 this . setState ( {
148148 showLoader : false ,
149- pullToRefreshThresholdBreached : false
149+ pullToRefreshThresholdBreached : false ,
150150 } ) ;
151151 }
152152
153153 getScrollableTarget ( ) {
154154 if ( this . props . scrollableTarget instanceof HTMLElement )
155155 return this . props . scrollableTarget ;
156- if ( typeof this . props . scrollableTarget === " string" ) {
156+ if ( typeof this . props . scrollableTarget === ' string' ) {
157157 return document . getElementById ( this . props . scrollableTarget ) ;
158158 }
159159 if ( this . props . scrollableTarget === null ) {
@@ -178,7 +178,7 @@ export default class InfiniteScroll extends Component<Props, State> {
178178 this . currentY = this . startY ;
179179
180180 if ( this . _infScroll ) {
181- this . _infScroll . style . willChange = " transform" ;
181+ this . _infScroll . style . willChange = ' transform' ;
182182 this . _infScroll . style . transition = `transform 0.2s cubic-bezier(0,0,0.31,1)` ;
183183 }
184184 } ;
@@ -200,15 +200,15 @@ export default class InfiniteScroll extends Component<Props, State> {
200200 Number ( this . props . pullDownToRefreshThreshold )
201201 ) {
202202 this . setState ( {
203- pullToRefreshThresholdBreached : true
203+ pullToRefreshThresholdBreached : true ,
204204 } ) ;
205205 }
206206
207207 // so you can drag upto 1.5 times of the maxPullDownDistance
208208 if ( this . currentY - this . startY > this . maxPullDownDistance * 1.5 ) return ;
209209
210210 if ( this . _infScroll ) {
211- this . _infScroll . style . overflow = " visible" ;
211+ this . _infScroll . style . overflow = ' visible' ;
212212 this . _infScroll . style . transform = `translate3d(0px, ${ this . currentY -
213213 this . startY } px, 0px)`;
214214 }
@@ -227,9 +227,9 @@ export default class InfiniteScroll extends Component<Props, State> {
227227 requestAnimationFrame ( ( ) => {
228228 // this._infScroll
229229 if ( this . _infScroll ) {
230- this . _infScroll . style . overflow = " auto" ;
231- this . _infScroll . style . transform = " none" ;
232- this . _infScroll . style . willChange = " none" ;
230+ this . _infScroll . style . overflow = ' auto' ;
231+ this . _infScroll . style . transform = ' none' ;
232+ this . _infScroll . style . willChange = ' none' ;
233233 }
234234 } ) ;
235235 } ;
@@ -258,13 +258,13 @@ export default class InfiniteScroll extends Component<Props, State> {
258258 }
259259
260260 onScrollListener ( event : MouseEvent ) {
261- if ( typeof this . props . onScroll === " function" ) {
261+ if ( typeof this . props . onScroll === ' function' ) {
262262 // Execute this callback in next tick so that it does not affect the
263263 // functionality of the library.
264264 setTimeout ( ( ) => this . props . onScroll && this . props . onScroll ( event ) , 0 ) ;
265265 }
266266
267- let target =
267+ const target =
268268 this . props . height || this . _scrollableNode
269269 ? ( event . target as HTMLElement )
270270 : document . documentElement . scrollTop
@@ -275,7 +275,7 @@ export default class InfiniteScroll extends Component<Props, State> {
275275 // prevents multiple triggers.
276276 if ( this . actionTriggered ) return ;
277277
278- let atBottom = this . isElementAtBottom ( target , this . props . scrollThreshold ) ;
278+ const atBottom = this . isElementAtBottom ( target , this . props . scrollThreshold ) ;
279279
280280 // call the `next` function in the props to trigger the next data fetch
281281 if ( atBottom && this . props . hasMore ) {
@@ -289,10 +289,10 @@ export default class InfiniteScroll extends Component<Props, State> {
289289
290290 render ( ) {
291291 const style = {
292- height : this . props . height || " auto" ,
293- overflow : " auto" ,
294- WebkitOverflowScrolling : " touch" ,
295- ...this . props . style
292+ height : this . props . height || ' auto' ,
293+ overflow : ' auto' ,
294+ WebkitOverflowScrolling : ' touch' ,
295+ ...this . props . style ,
296296 } as CSSProperties ;
297297 const hasChildren =
298298 this . props . hasChildren ||
@@ -306,26 +306,26 @@ export default class InfiniteScroll extends Component<Props, State> {
306306 // on drag down as overflow becomes visible
307307 const outerDivStyle =
308308 this . props . pullDownToRefresh && this . props . height
309- ? { overflow : " auto" }
309+ ? { overflow : ' auto' }
310310 : { } ;
311311 return (
312312 < div style = { outerDivStyle } >
313313 < div
314- className = { `infinite-scroll-component ${ this . props . className || "" } ` }
314+ className = { `infinite-scroll-component ${ this . props . className || '' } ` }
315315 ref = { ( infScroll : HTMLDivElement ) => ( this . _infScroll = infScroll ) }
316316 style = { style }
317317 >
318318 { this . props . pullDownToRefresh && (
319319 < div
320- style = { { position : " relative" } }
320+ style = { { position : ' relative' } }
321321 ref = { ( pullDown : HTMLDivElement ) => ( this . _pullDown = pullDown ) }
322322 >
323323 < div
324324 style = { {
325- position : " absolute" ,
325+ position : ' absolute' ,
326326 left : 0 ,
327327 right : 0 ,
328- top : - 1 * this . maxPullDownDistance
328+ top : - 1 * this . maxPullDownDistance ,
329329 } }
330330 >
331331 { this . state . pullToRefreshThresholdBreached
0 commit comments