10
10
11
11
'use strict' ;
12
12
13
+ import type { FrameMetricProps } from '../VirtualizedList/VirtualizedListProps' ;
14
+
13
15
export type FillRateInfo = Info ;
14
16
15
17
class Info {
@@ -47,16 +49,17 @@ let _sampleRate = DEBUG ? 1 : null;
47
49
* `SceneTracker.getActiveScene` to determine the context of the events.
48
50
*/
49
51
class FillRateHelper {
50
- _anyBlankStartTime = ( null : ?number ) ;
52
+ _anyBlankStartTime : ?number = null ;
51
53
_enabled = false ;
52
- _getFrameMetrics : ( index : number ) => ?FrameMetrics ;
53
- _info = new Info ( ) ;
54
- _mostlyBlankStartTime = ( null : ?number ) ;
55
- _samplesStartTime = ( null : ?number ) ;
56
-
57
- static addListener (
58
- callback : FillRateInfo => void ,
59
- ) : { remove: ( ) => void , ...} {
54
+ _getFrameMetrics : ( index : number , props : FrameMetricProps ) => ?FrameMetrics ;
55
+ _info : Info = new Info ( ) ;
56
+ _mostlyBlankStartTime : ?number = null ;
57
+ _samplesStartTime : ?number = null ;
58
+
59
+ static addListener ( callback : FillRateInfo => void ) : {
60
+ remove : ( ) => void ,
61
+ ...
62
+ } {
60
63
if ( _sampleRate === null ) {
61
64
console . warn ( 'Call `FillRateHelper.setSampleRate` before `addListener`.' ) ;
62
65
}
@@ -76,7 +79,9 @@ class FillRateHelper {
76
79
_minSampleCount = minSampleCount ;
77
80
}
78
81
79
- constructor ( getFrameMetrics : ( index : number ) = > ?FrameMetrics ) {
82
+ constructor (
83
+ getFrameMetrics : ( index : number , props : FrameMetricProps ) => ?FrameMetrics ,
84
+ ) {
80
85
this . _getFrameMetrics = getFrameMetrics ;
81
86
this . _enabled = ( _sampleRate || 0 ) > Math . random ( ) ;
82
87
this . _resetData ( ) ;
@@ -123,6 +128,7 @@ class FillRateHelper {
123
128
mostly_blank_time_frac : this . _info . mostly_blank_ms / total_time_spent ,
124
129
} ;
125
130
for ( const key in derived ) {
131
+ // $FlowFixMe[prop-missing]
126
132
derived [ key ] = Math . round ( 1000 * derived [ key ] ) / 1000 ;
127
133
}
128
134
console . debug ( 'FillRateHelper deactivateAndFlush: ' , { derived, info} ) ;
@@ -133,12 +139,11 @@ class FillRateHelper {
133
139
134
140
computeBlankness (
135
141
props : {
136
- data : any ,
137
- getItemCount : ( data : any ) => number ,
138
- initialNumToRender : number ,
142
+ ...FrameMetricProps ,
143
+ initialNumToRender ?: ?number ,
139
144
...
140
145
} ,
141
- state : {
146
+ cellsAroundViewport : {
142
147
first : number ,
143
148
last : number ,
144
149
...
@@ -154,6 +159,7 @@ class FillRateHelper {
154
159
if (
155
160
! this . _enabled ||
156
161
props . getItemCount ( props . data ) === 0 ||
162
+ cellsAroundViewport . last < cellsAroundViewport . first ||
157
163
this . _samplesStartTime == null
158
164
) {
159
165
return 0 ;
@@ -179,10 +185,13 @@ class FillRateHelper {
179
185
this . _mostlyBlankStartTime = null ;
180
186
181
187
let blankTop = 0 ;
182
- let first = state . first ;
183
- let firstFrame = this . _getFrameMetrics ( first ) ;
184
- while ( first <= state . last && ( ! firstFrame || ! firstFrame . inLayout ) ) {
185
- firstFrame = this . _getFrameMetrics ( first ) ;
188
+ let first = cellsAroundViewport . first ;
189
+ let firstFrame = this . _getFrameMetrics ( first , props ) ;
190
+ while (
191
+ first <= cellsAroundViewport . last &&
192
+ ( ! firstFrame || ! firstFrame . inLayout )
193
+ ) {
194
+ firstFrame = this . _getFrameMetrics ( first , props ) ;
186
195
first ++ ;
187
196
}
188
197
// Only count blankTop if we aren't rendering the first item, otherwise we will count the header
@@ -194,10 +203,13 @@ class FillRateHelper {
194
203
) ;
195
204
}
196
205
let blankBottom = 0 ;
197
- let last = state . last ;
198
- let lastFrame = this . _getFrameMetrics ( last ) ;
199
- while ( last >= state . first && ( ! lastFrame || ! lastFrame . inLayout ) ) {
200
- lastFrame = this . _getFrameMetrics ( last ) ;
206
+ let last = cellsAroundViewport . last ;
207
+ let lastFrame = this . _getFrameMetrics ( last , props ) ;
208
+ while (
209
+ last >= cellsAroundViewport . first &&
210
+ ( ! lastFrame || ! lastFrame . inLayout )
211
+ ) {
212
+ lastFrame = this . _getFrameMetrics ( last , props ) ;
201
213
last -- ;
202
214
}
203
215
// Only count blankBottom if we aren't rendering the last item, otherwise we will count the
@@ -238,4 +250,4 @@ class FillRateHelper {
238
250
}
239
251
}
240
252
241
- export default FillRateHelper ;
253
+ export default FillRateHelper ;
0 commit comments