Skip to content

Commit 0a3e6e0

Browse files
sahrensfacebook-github-bot
authored andcommitted
prettier
Reviewed By: fkgozali Differential Revision: D5210279 fbshipit-source-id: 4b376a09b4bcfb42a2dc48b9903849d58929b7db
1 parent 63f7efc commit 0a3e6e0

19 files changed

+1328
-826
lines changed

Libraries/Lists/FillRateHelper.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* @providesModule FillRateHelper
1010
* @flow
11+
* @format
1112
*/
1213

1314
/* eslint-disable no-console-disallow */
@@ -56,17 +57,15 @@ class FillRateHelper {
5657
_mostlyBlankStartTime = (null: ?number);
5758
_samplesStartTime = (null: ?number);
5859

59-
static addListener(
60-
callback: (FillRateInfo) => void
61-
): {remove: () => void} {
60+
static addListener(callback: FillRateInfo => void): {remove: () => void} {
6261
warning(
6362
_sampleRate !== null,
64-
'Call `FillRateHelper.setSampleRate` before `addListener`.'
63+
'Call `FillRateHelper.setSampleRate` before `addListener`.',
6564
);
6665
_listeners.push(callback);
6766
return {
6867
remove: () => {
69-
_listeners = _listeners.filter((listener) => callback !== listener);
68+
_listeners = _listeners.filter(listener => callback !== listener);
7069
},
7170
};
7271
}
@@ -98,7 +97,8 @@ class FillRateHelper {
9897
}
9998
const start = this._samplesStartTime; // const for flow
10099
if (start == null) {
101-
DEBUG && console.debug('FillRateHelper: bail on deactivate with no start time');
100+
DEBUG &&
101+
console.debug('FillRateHelper: bail on deactivate with no start time');
102102
return;
103103
}
104104
if (this._info.sample_count < _minSampleCount) {
@@ -115,18 +115,21 @@ class FillRateHelper {
115115
const derived = {
116116
avg_blankness: this._info.pixels_blank / this._info.pixels_sampled,
117117
avg_speed: this._info.pixels_scrolled / (total_time_spent / 1000),
118-
avg_speed_when_any_blank: this._info.any_blank_speed_sum / this._info.any_blank_count,
119-
any_blank_per_min: this._info.any_blank_count / (total_time_spent / 1000 / 60),
118+
avg_speed_when_any_blank: this._info.any_blank_speed_sum /
119+
this._info.any_blank_count,
120+
any_blank_per_min: this._info.any_blank_count /
121+
(total_time_spent / 1000 / 60),
120122
any_blank_time_frac: this._info.any_blank_ms / total_time_spent,
121-
mostly_blank_per_min: this._info.mostly_blank_count / (total_time_spent / 1000 / 60),
123+
mostly_blank_per_min: this._info.mostly_blank_count /
124+
(total_time_spent / 1000 / 60),
122125
mostly_blank_time_frac: this._info.mostly_blank_ms / total_time_spent,
123126
};
124127
for (const key in derived) {
125128
derived[key] = Math.round(1000 * derived[key]) / 1000;
126129
}
127130
console.debug('FillRateHelper deactivateAndFlush: ', {derived, info});
128131
}
129-
_listeners.forEach((listener) => listener(info));
132+
_listeners.forEach(listener => listener(info));
130133
this._resetData();
131134
}
132135

@@ -147,7 +150,11 @@ class FillRateHelper {
147150
visibleLength: number,
148151
},
149152
): number {
150-
if (!this._enabled || props.getItemCount(props.data) === 0 || this._samplesStartTime == null) {
153+
if (
154+
!this._enabled ||
155+
props.getItemCount(props.data) === 0 ||
156+
this._samplesStartTime == null
157+
) {
151158
return 0;
152159
}
153160
const {dOffset, offset, velocity, visibleLength} = scrollMetrics;
@@ -180,7 +187,10 @@ class FillRateHelper {
180187
// Only count blankTop if we aren't rendering the first item, otherwise we will count the header
181188
// as blank.
182189
if (firstFrame && first > 0) {
183-
blankTop = Math.min(visibleLength, Math.max(0, firstFrame.offset - offset));
190+
blankTop = Math.min(
191+
visibleLength,
192+
Math.max(0, firstFrame.offset - offset),
193+
);
184194
}
185195
let blankBottom = 0;
186196
let last = state.last;
@@ -193,7 +203,10 @@ class FillRateHelper {
193203
// footer as blank.
194204
if (lastFrame && last < props.getItemCount(props.data) - 1) {
195205
const bottomEdge = lastFrame.offset + lastFrame.length;
196-
blankBottom = Math.min(visibleLength, Math.max(0, offset + visibleLength - bottomEdge));
206+
blankBottom = Math.min(
207+
visibleLength,
208+
Math.max(0, offset + visibleLength - bottomEdge),
209+
);
197210
}
198211
const pixels_blank = Math.round(blankTop + blankBottom);
199212
const blankness = pixels_blank / visibleLength;

Libraries/Lists/FlatList.js

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*
99
* @providesModule FlatList
1010
* @flow
11+
* @format
1112
*/
1213
'use strict';
1314

@@ -109,8 +110,10 @@ type OptionalProps<ItemT> = {
109110
* Remember to include separator length (height or width) in your offset calculation if you
110111
* specify `ItemSeparatorComponent`.
111112
*/
112-
getItemLayout?: (data: ?Array<ItemT>, index: number) =>
113-
{length: number, offset: number, index: number},
113+
getItemLayout?: (
114+
data: ?Array<ItemT>,
115+
index: number,
116+
) => {length: number, offset: number, index: number},
114117
/**
115118
* If true, renders items next to each other horizontally instead of stacked vertically.
116119
*/
@@ -184,7 +187,9 @@ type OptionalProps<ItemT> = {
184187
*/
185188
viewabilityConfig?: ViewabilityConfig,
186189
};
187-
type Props<ItemT> = RequiredProps<ItemT> & OptionalProps<ItemT> & VirtualizedListProps;
190+
type Props<ItemT> = RequiredProps<ItemT> &
191+
OptionalProps<ItemT> &
192+
VirtualizedListProps;
188193

189194
const defaultProps = {
190195
...VirtualizedList.defaultProps,
@@ -295,7 +300,8 @@ type DefaultProps = typeof defaultProps;
295300
* Alternatively, you can provide a custom `keyExtractor` prop.
296301
*
297302
*/
298-
class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, void> {
303+
class FlatList<ItemT>
304+
extends React.PureComponent<DefaultProps, Props<ItemT>, void> {
299305
static defaultProps: DefaultProps = defaultProps;
300306
props: Props<ItemT>;
301307
/**
@@ -314,7 +320,10 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
314320
* `getItemLayout` prop.
315321
*/
316322
scrollToIndex(params: {
317-
animated?: ?boolean, index: number, viewOffset?: number, viewPosition?: number,
323+
animated?: ?boolean,
324+
index: number,
325+
viewOffset?: number,
326+
viewPosition?: number,
318327
}) {
319328
this._listRef.scrollToIndex(params);
320329
}
@@ -325,7 +334,11 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
325334
* Note: cannot scroll to locations outside the render window without specifying the
326335
* `getItemLayout` prop.
327336
*/
328-
scrollToItem(params: {animated?: ?boolean, item: ItemT, viewPosition?: number}) {
337+
scrollToItem(params: {
338+
animated?: ?boolean,
339+
item: ItemT,
340+
viewPosition?: number,
341+
}) {
329342
this._listRef.scrollToItem(params);
330343
}
331344

@@ -379,15 +392,17 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
379392
invariant(
380393
nextProps.numColumns === this.props.numColumns,
381394
'Changing numColumns on the fly is not supported. Change the key prop on FlatList when ' +
382-
'changing the number of columns to force a fresh render of the component.'
395+
'changing the number of columns to force a fresh render of the component.',
383396
);
384397
this._checkProps(nextProps);
385398
}
386399

387400
_hasWarnedLegacy = false;
388401
_listRef: VirtualizedList;
389402

390-
_captureRef = (ref) => { this._listRef = ref; };
403+
_captureRef = ref => {
404+
this._listRef = ref;
405+
};
391406

392407
_checkProps(props: Props<ItemT>) {
393408
const {
@@ -398,20 +413,29 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
398413
numColumns,
399414
columnWrapperStyle,
400415
} = props;
401-
invariant(!getItem && !getItemCount, 'FlatList does not support custom data formats.');
416+
invariant(
417+
!getItem && !getItemCount,
418+
'FlatList does not support custom data formats.',
419+
);
402420
if (numColumns > 1) {
403421
invariant(!horizontal, 'numColumns does not support horizontal.');
404422
} else {
405-
invariant(!columnWrapperStyle, 'columnWrapperStyle not supported for single column lists');
423+
invariant(
424+
!columnWrapperStyle,
425+
'columnWrapperStyle not supported for single column lists',
426+
);
406427
}
407428
if (legacyImplementation) {
408-
invariant(numColumns === 1, 'Legacy list does not support multiple columns.');
429+
invariant(
430+
numColumns === 1,
431+
'Legacy list does not support multiple columns.',
432+
);
409433
// Warning: may not have full feature parity and is meant more for debugging and performance
410434
// comparison.
411435
if (!this._hasWarnedLegacy) {
412436
console.warn(
413437
'FlatList: Using legacyImplementation - some features not supported and performance ' +
414-
'may suffer'
438+
'may suffer',
415439
);
416440
this._hasWarnedLegacy = true;
417441
}
@@ -442,10 +466,12 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
442466
invariant(
443467
Array.isArray(items),
444468
'FlatList: Encountered internal consistency error, expected each item to consist of an ' +
445-
'array with 1-%s columns; instead, received a single item.',
469+
'array with 1-%s columns; instead, received a single item.',
446470
numColumns,
447471
);
448-
return items.map((it, kk) => keyExtractor(it, index * numColumns + kk)).join(':');
472+
return items
473+
.map((it, kk) => keyExtractor(it, index * numColumns + kk))
474+
.join(':');
449475
} else {
450476
return keyExtractor(items, index);
451477
}
@@ -460,16 +486,18 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
460486
});
461487
}
462488

463-
_onViewableItemsChanged = (info) => {
489+
_onViewableItemsChanged = info => {
464490
const {numColumns, onViewableItemsChanged} = this.props;
465491
if (!onViewableItemsChanged) {
466492
return;
467493
}
468494
if (numColumns > 1) {
469495
const changed = [];
470496
const viewableItems = [];
471-
info.viewableItems.forEach((v) => this._pushMultiColumnViewable(viewableItems, v));
472-
info.changed.forEach((v) => this._pushMultiColumnViewable(changed, v));
497+
info.viewableItems.forEach(v =>
498+
this._pushMultiColumnViewable(viewableItems, v),
499+
);
500+
info.changed.forEach(v => this._pushMultiColumnViewable(changed, v));
473501
onViewableItemsChanged({viewableItems, changed});
474502
} else {
475503
onViewableItemsChanged(info);
@@ -480,7 +508,10 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
480508
const {renderItem, numColumns, columnWrapperStyle} = this.props;
481509
if (numColumns > 1) {
482510
const {item, index} = info;
483-
invariant(Array.isArray(item), 'Expected array of items with numColumns > 1');
511+
invariant(
512+
Array.isArray(item),
513+
'Expected array of items with numColumns > 1',
514+
);
484515
return (
485516
<View style={[{flexDirection: 'row'}, columnWrapperStyle]}>
486517
{item.map((it, kk) => {
@@ -500,7 +531,13 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
500531

501532
render() {
502533
if (this.props.legacyImplementation) {
503-
return <MetroListView {...this.props} items={this.props.data} ref={this._captureRef} />;
534+
return (
535+
<MetroListView
536+
{...this.props}
537+
items={this.props.data}
538+
ref={this._captureRef}
539+
/>
540+
);
504541
} else {
505542
return (
506543
<VirtualizedList
@@ -510,7 +547,9 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
510547
getItemCount={this._getItemCount}
511548
keyExtractor={this._keyExtractor}
512549
ref={this._captureRef}
513-
onViewableItemsChanged={this.props.onViewableItemsChanged && this._onViewableItemsChanged}
550+
onViewableItemsChanged={
551+
this.props.onViewableItemsChanged && this._onViewableItemsChanged
552+
}
514553
/>
515554
);
516555
}

0 commit comments

Comments
 (0)