Skip to content

Commit 5ace60e

Browse files
LucioChavezFuentesnecolas
authored andcommitted
[fix] VirtualizedList sync from react-native
Fix #2432 Close #2167 Close #2502
1 parent 1c5119b commit 5ace60e

File tree

19 files changed

+2191
-1184
lines changed

19 files changed

+2191
-1184
lines changed

configs/.flowconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
<PROJECT_ROOT>/packages/.*/dist/.*
77
<PROJECT_ROOT>/packages/react-native-web-docs/.*
88
<PROJECT_ROOT>/packages/react-native-web-examples/.*
9-
.*/node_modules/.*/.*.json
109

1110
[include]
1211

12+
[declarations]
13+
.*/node_modules/.*
14+
1315
[libs]
1416

1517
[options]
18+
indexed_access=true
1619
munge_underscores=true

package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react-native-web/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"@babel/runtime": "^7.18.6",
2626
"fbjs": "^3.0.4",
2727
"inline-style-prefixer": "^6.0.1",
28+
"memoize-one": "^6.0.0",
2829
"normalize-css-color": "^1.0.2",
30+
"nullthrows": "^1.1.1",
2931
"postcss-value-parser": "^4.2.0",
3032
"styleq": "^0.1.2"
3133
},

packages/react-native-web/src/vendor/react-native/Batchinator/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import InteractionManager from '../../../exports/InteractionManager';
3737
class Batchinator {
3838
_callback: () => void;
3939
_delay: number;
40-
_taskHandle: ?{cancel: () => void};
40+
_taskHandle: ?{cancel: () => void, ...};
4141
constructor(callback: () => void, delayMS: number) {
4242
this._delay = delayMS;
4343
this._callback = callback;
@@ -48,7 +48,7 @@ class Batchinator {
4848
* By default, if there is a pending task the callback is run immediately. Set the option abort to
4949
* true to not call the callback if it was pending.
5050
*/
51-
dispose(options: {abort: boolean} = {abort: false}) {
51+
dispose(options: {abort: boolean, ...} = {abort: false}) {
5252
if (this._taskHandle) {
5353
this._taskHandle.cancel();
5454
if (!options.abort) {

packages/react-native-web/src/vendor/react-native/FillRateHelper/index.js

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
'use strict';
1212

13+
import type {FrameMetricProps} from '../VirtualizedList/VirtualizedListProps';
14+
1315
export type FillRateInfo = Info;
1416

1517
class Info {
@@ -47,16 +49,17 @@ let _sampleRate = DEBUG ? 1 : null;
4749
* `SceneTracker.getActiveScene` to determine the context of the events.
4850
*/
4951
class FillRateHelper {
50-
_anyBlankStartTime = (null: ?number);
52+
_anyBlankStartTime: ?number = null;
5153
_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+
} {
6063
if (_sampleRate === null) {
6164
console.warn('Call `FillRateHelper.setSampleRate` before `addListener`.');
6265
}
@@ -76,7 +79,9 @@ class FillRateHelper {
7679
_minSampleCount = minSampleCount;
7780
}
7881

79-
constructor(getFrameMetrics: (index: number) => ?FrameMetrics) {
82+
constructor(
83+
getFrameMetrics: (index: number, props: FrameMetricProps) => ?FrameMetrics,
84+
) {
8085
this._getFrameMetrics = getFrameMetrics;
8186
this._enabled = (_sampleRate || 0) > Math.random();
8287
this._resetData();
@@ -123,6 +128,7 @@ class FillRateHelper {
123128
mostly_blank_time_frac: this._info.mostly_blank_ms / total_time_spent,
124129
};
125130
for (const key in derived) {
131+
// $FlowFixMe[prop-missing]
126132
derived[key] = Math.round(1000 * derived[key]) / 1000;
127133
}
128134
console.debug('FillRateHelper deactivateAndFlush: ', {derived, info});
@@ -133,12 +139,11 @@ class FillRateHelper {
133139

134140
computeBlankness(
135141
props: {
136-
data: any,
137-
getItemCount: (data: any) => number,
138-
initialNumToRender: number,
142+
...FrameMetricProps,
143+
initialNumToRender?: ?number,
139144
...
140145
},
141-
state: {
146+
cellsAroundViewport: {
142147
first: number,
143148
last: number,
144149
...
@@ -154,6 +159,7 @@ class FillRateHelper {
154159
if (
155160
!this._enabled ||
156161
props.getItemCount(props.data) === 0 ||
162+
cellsAroundViewport.last < cellsAroundViewport.first ||
157163
this._samplesStartTime == null
158164
) {
159165
return 0;
@@ -179,10 +185,13 @@ class FillRateHelper {
179185
this._mostlyBlankStartTime = null;
180186

181187
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);
186195
first++;
187196
}
188197
// Only count blankTop if we aren't rendering the first item, otherwise we will count the header
@@ -194,10 +203,13 @@ class FillRateHelper {
194203
);
195204
}
196205
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);
201213
last--;
202214
}
203215
// Only count blankBottom if we aren't rendering the last item, otherwise we will count the
@@ -238,4 +250,4 @@ class FillRateHelper {
238250
}
239251
}
240252

241-
export default FillRateHelper;
253+
export default FillRateHelper;

0 commit comments

Comments
 (0)