Skip to content

Commit

Permalink
Rename FrameMetrics to CellMetrics
Browse files Browse the repository at this point in the history
Summary:
These functions describe how to get the metrics of a specific cell. "Frame" here seems non-descriptive and redundant to the "Metrics" part. Renaming this before a larger refactor.

Changelog: [Internal]

Differential Revision: D46427058

fbshipit-source-id: 84be31198d43be060f86f8866e07dbffde4a3455
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Jun 8, 2023
1 parent 108309e commit e195e65
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 140 deletions.
20 changes: 10 additions & 10 deletions packages/virtualized-lists/Lists/FillRateHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import type {FrameMetricProps} from './VirtualizedListProps';
import type {CellMetricProps} from './VirtualizedListProps';

export type FillRateInfo = Info;

Expand All @@ -27,7 +27,7 @@ class Info {
sample_count: number = 0;
}

type FrameMetrics = {
type CellMetrics = {
inLayout?: boolean,
length: number,
offset: number,
Expand All @@ -51,7 +51,7 @@ let _sampleRate = DEBUG ? 1 : null;
class FillRateHelper {
_anyBlankStartTime: ?number = null;
_enabled = false;
_getFrameMetrics: (index: number, props: FrameMetricProps) => ?FrameMetrics;
_getCellMetrics: (index: number, props: CellMetricProps) => ?CellMetrics;
_info: Info = new Info();
_mostlyBlankStartTime: ?number = null;
_samplesStartTime: ?number = null;
Expand Down Expand Up @@ -80,9 +80,9 @@ class FillRateHelper {
}

constructor(
getFrameMetrics: (index: number, props: FrameMetricProps) => ?FrameMetrics,
getCellMetrics: (index: number, props: CellMetricProps) => ?CellMetrics,
) {
this._getFrameMetrics = getFrameMetrics;
this._getCellMetrics = getCellMetrics;
this._enabled = (_sampleRate || 0) > Math.random();
this._resetData();
}
Expand Down Expand Up @@ -139,7 +139,7 @@ class FillRateHelper {

computeBlankness(
props: {
...FrameMetricProps,
...CellMetricProps,
initialNumToRender?: ?number,
...
},
Expand Down Expand Up @@ -186,12 +186,12 @@ class FillRateHelper {

let blankTop = 0;
let first = cellsAroundViewport.first;
let firstFrame = this._getFrameMetrics(first, props);
let firstFrame = this._getCellMetrics(first, props);
while (
first <= cellsAroundViewport.last &&
(!firstFrame || !firstFrame.inLayout)
) {
firstFrame = this._getFrameMetrics(first, props);
firstFrame = this._getCellMetrics(first, props);
first++;
}
// Only count blankTop if we aren't rendering the first item, otherwise we will count the header
Expand All @@ -204,12 +204,12 @@ class FillRateHelper {
}
let blankBottom = 0;
let last = cellsAroundViewport.last;
let lastFrame = this._getFrameMetrics(last, props);
let lastFrame = this._getCellMetrics(last, props);
while (
last >= cellsAroundViewport.first &&
(!lastFrame || !lastFrame.inLayout)
) {
lastFrame = this._getFrameMetrics(last, props);
lastFrame = this._getCellMetrics(last, props);
last--;
}
// Only count blankBottom if we aren't rendering the last item, otherwise we will count the
Expand Down
26 changes: 13 additions & 13 deletions packages/virtualized-lists/Lists/ViewabilityHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import type {FrameMetricProps} from './VirtualizedListProps';
import type {CellMetricProps} from './VirtualizedListProps';

const invariant = require('invariant');

Expand Down Expand Up @@ -101,12 +101,12 @@ class ViewabilityHelper {
* Determines which items are viewable based on the current metrics and config.
*/
computeViewableItems(
props: FrameMetricProps,
props: CellMetricProps,
scrollOffset: number,
viewportHeight: number,
getFrameMetrics: (
getCellMetrics: (
index: number,
props: FrameMetricProps,
props: CellMetricProps,
) => ?{
length: number,
offset: number,
Expand Down Expand Up @@ -146,7 +146,7 @@ class ViewabilityHelper {
return [];
}
for (let idx = first; idx <= last; idx++) {
const metrics = getFrameMetrics(idx, props);
const metrics = getCellMetrics(idx, props);
if (!metrics) {
continue;
}
Expand Down Expand Up @@ -178,12 +178,12 @@ class ViewabilityHelper {
* `onViewableItemsChanged` as appropriate.
*/
onUpdate(
props: FrameMetricProps,
props: CellMetricProps,
scrollOffset: number,
viewportHeight: number,
getFrameMetrics: (
getCellMetrics: (
index: number,
props: FrameMetricProps,
props: CellMetricProps,
) => ?{
length: number,
offset: number,
Expand All @@ -192,7 +192,7 @@ class ViewabilityHelper {
createViewToken: (
index: number,
isViewable: boolean,
props: FrameMetricProps,
props: CellMetricProps,
) => ViewToken,
onViewableItemsChanged: ({
viewableItems: Array<ViewToken>,
Expand All @@ -210,7 +210,7 @@ class ViewabilityHelper {
if (
(this._config.waitForInteraction && !this._hasInteracted) ||
itemCount === 0 ||
!getFrameMetrics(0, props)
!getCellMetrics(0, props)
) {
return;
}
Expand All @@ -220,7 +220,7 @@ class ViewabilityHelper {
props,
scrollOffset,
viewportHeight,
getFrameMetrics,
getCellMetrics,
renderRange,
);
}
Expand Down Expand Up @@ -275,7 +275,7 @@ class ViewabilityHelper {
}

_onUpdateSync(
props: FrameMetricProps,
props: CellMetricProps,
viewableIndicesToCheck: Array<number>,
onViewableItemsChanged: ({
changed: Array<ViewToken>,
Expand All @@ -285,7 +285,7 @@ class ViewabilityHelper {
createViewToken: (
index: number,
isViewable: boolean,
props: FrameMetricProps,
props: CellMetricProps,
) => ViewToken,
) {
// Filter out indices that have gone out of view since this call was scheduled.
Expand Down
20 changes: 10 additions & 10 deletions packages/virtualized-lists/Lists/VirtualizeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

'use strict';

import type {FrameMetricProps} from './VirtualizedListProps';
import type {CellMetricProps} from './VirtualizedListProps';

/**
* Used to find the indices of the frames that overlap the given offsets. Useful for finding the
Expand All @@ -19,10 +19,10 @@ import type {FrameMetricProps} from './VirtualizedListProps';
*/
export function elementsThatOverlapOffsets(
offsets: Array<number>,
props: FrameMetricProps,
getFrameMetrics: (
props: CellMetricProps,
getCellMetrics: (
index: number,
props: FrameMetricProps,
props: CellMetricProps,
) => {
length: number,
offset: number,
Expand All @@ -40,7 +40,7 @@ export function elementsThatOverlapOffsets(
while (left <= right) {
// eslint-disable-next-line no-bitwise
const mid = left + ((right - left) >>> 1);
const frame = getFrameMetrics(mid, props);
const frame = getCellMetrics(mid, props);
const scaledOffsetStart = frame.offset * zoomScale;
const scaledOffsetEnd = (frame.offset + frame.length) * zoomScale;

Expand Down Expand Up @@ -99,16 +99,16 @@ export function newRangeCount(
* biased in the direction of scroll.
*/
export function computeWindowedRenderLimits(
props: FrameMetricProps,
props: CellMetricProps,
maxToRenderPerBatch: number,
windowSize: number,
prev: {
first: number,
last: number,
},
getFrameMetricsApprox: (
getCellMetricsApprox: (
index: number,
props: FrameMetricProps,
props: CellMetricProps,
) => {
length: number,
offset: number,
Expand Down Expand Up @@ -152,7 +152,7 @@ export function computeWindowedRenderLimits(
const overscanEnd = Math.max(0, visibleEnd + leadFactor * overscanLength);

const lastItemOffset =
getFrameMetricsApprox(itemCount - 1, props).offset * zoomScale;
getCellMetricsApprox(itemCount - 1, props).offset * zoomScale;
if (lastItemOffset < overscanBegin) {
// Entire list is before our overscan window
return {
Expand All @@ -165,7 +165,7 @@ export function computeWindowedRenderLimits(
let [overscanFirst, first, last, overscanLast] = elementsThatOverlapOffsets(
[overscanBegin, visibleBegin, visibleEnd, overscanEnd],
props,
getFrameMetricsApprox,
getCellMetricsApprox,
zoomScale,
);
overscanFirst = overscanFirst == null ? 0 : overscanFirst;
Expand Down
Loading

0 comments on commit e195e65

Please sign in to comment.