File tree Expand file tree Collapse file tree 4 files changed +71
-15
lines changed Expand file tree Collapse file tree 4 files changed +71
-15
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import type {
13
13
OverscanIndicesGetter ,
14
14
Alignment
15
15
} from "./types" ;
16
+ import type { AnimationTimeoutId } from "../utils/requestAnimationTimeout" ;
16
17
17
18
import React from "react" ;
18
19
import cn from "classnames" ;
@@ -301,7 +302,7 @@ export default class Grid extends React.PureComponent {
301
302
_rowStartIndex : number ;
302
303
_rowStopIndex : number ;
303
304
304
- _disablePointerEventsTimeoutId : ?number ;
305
+ _disablePointerEventsTimeoutId : ?AnimationTimeoutId ;
305
306
306
307
constructor ( props : Props ) {
307
308
super ( props ) ;
Original file line number Diff line number Diff line change 7
7
cancelAnimationTimeout
8
8
} from "../utils/requestAnimationTimeout" ;
9
9
10
+ import type { AnimationTimeoutId } from "../utils/requestAnimationTimeout" ;
11
+
10
12
const emptyObject = { } ;
11
13
12
14
/**
@@ -58,6 +60,7 @@ export default class Masonry extends PureComponent {
58
60
tabIndex : 0
59
61
} ;
60
62
63
+ _debounceResetIsScrollingId : AnimationTimeoutId ;
61
64
_invalidateOnUpdateStartIndex : ?number = null ;
62
65
_invalidateOnUpdateStopIndex : ?number = null ;
63
66
_positionCache : PositionCache = new PositionCache ( ) ;
Original file line number Diff line number Diff line change
1
+ /** @flow */
2
+
3
+ type Callback = ( timestamp : number ) => void ;
4
+ type CancelAnimationFrame = ( requestId : number ) => void ;
5
+ type ClearTimeout = ( timeoutId ? : any ) => void ;
6
+ type RequestAnimationFrame = ( callback : Callback ) => number ;
7
+
8
+ // Properly handle server-side rendering.
9
+ let win ;
10
+ if ( typeof window !== "undefined" ) {
11
+ win = window ;
12
+ } else if ( typeof self !== "undefined" ) {
13
+ win = self ;
14
+ } else {
15
+ win = this ;
16
+ }
17
+
18
+ // requestAnimationFrame() shim by Paul Irish
19
+ // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
20
+ const request =
21
+ win . requestAnimationFrame ||
22
+ win . webkitRequestAnimationFrame ||
23
+ win . mozRequestAnimationFrame ||
24
+ win . oRequestAnimationFrame ||
25
+ win . msRequestAnimationFrame ||
26
+ function ( callback : Callback ) : RequestAnimationFrame {
27
+ return ( win : any ) . setTimeout ( callback , 1000 / 60 ) ;
28
+ } ;
29
+
30
+ const cancel =
31
+ win . cancelAnimationFrame ||
32
+ win . webkitCancelAnimationFrame ||
33
+ win . mozCancelAnimationFrame ||
34
+ win . oCancelAnimationFrame ||
35
+ win . msCancelAnimationFrame ||
36
+ function ( id : number ) {
37
+ ( win : any ) . clearTimeout ( id ) ;
38
+ } ;
39
+
40
+ export const raf : RequestAnimationFrame = ( request : any ) ;
41
+ export const caf : CancelAnimationFrame = ( cancel : any ) ;
Original file line number Diff line number Diff line change 1
- export function cancelAnimationTimeout ( frame ) {
2
- window . cancelAnimationFrame ( frame . id ) ;
3
- }
1
+ /** @flow */
2
+
3
+ import { caf , raf } from "./animationFrame" ;
4
+
5
+ export type AnimationTimeoutId = {
6
+ id : number
7
+ } ;
8
+
9
+ export const cancelAnimationTimeout = ( frame : AnimationTimeoutId ) =>
10
+ caf ( frame . id ) ;
4
11
5
12
/**
6
- * Recursively calls requestAnimationFrame until a specified delay has been met
7
- * or exceeded. When the delay time has been reached the function you're timing
8
- * out will be called.
13
+ * Recursively calls requestAnimationFrame until a specified delay has been met or exceeded.
14
+ * When the delay time has been reached the function you're timing out will be called.
9
15
*
10
16
* Credit: Joe Lambert (https://gist.github.com/joelambert/1002116#file-requesttimeout-js)
11
17
*/
12
- export function requestAnimationTimeout ( func , delay ) {
18
+ export const requestAnimationTimeout = (
19
+ callback : Function ,
20
+ delay : number
21
+ ) : AnimationTimeoutId => {
13
22
const start = Date . now ( ) ;
14
- const frame = new Object ( ) ;
15
23
16
- function timeout ( ) {
24
+ const timeout = ( ) => {
17
25
if ( Date . now ( ) - start >= delay ) {
18
- func . call ( ) ;
26
+ callback . call ( ) ;
19
27
} else {
20
- frame . id = window . requestAnimationFrame ( timeout ) ;
28
+ frame . id = raf ( timeout ) ;
21
29
}
22
- }
30
+ } ;
31
+
32
+ const frame : AnimationTimeoutId = {
33
+ id : raf ( timeout )
34
+ } ;
23
35
24
- frame . id = window . requestAnimationFrame ( timeout ) ;
25
36
return frame ;
26
- }
37
+ } ;
You can’t perform that action at this time.
0 commit comments