Permalink
Browse files

Rename flow type Viewable -> ViewToken

Summary: `Viewable` is a weird name - I think `ViewToken` is more clear? Also easier to grep for.

Reviewed By: yungsters, bvaughn

Differential Revision: D4600762

fbshipit-source-id: dbfa5eec1b91166c4889dcb6b87d7832090be9e9
  • Loading branch information...
sahrens authored and facebook-github-bot committed Feb 28, 2017
1 parent dc30203 commit a10dbdaaf6873b126ae5b565377748ff24962e6a
@@ -40,7 +40,7 @@ const VirtualizedList = require('VirtualizedList');
const invariant = require('invariant');
import type {StyleObj} from 'StyleSheetTypes';
import type {ViewabilityConfig, Viewable} from 'ViewabilityHelper';
import type {ViewabilityConfig, ViewToken} from 'ViewabilityHelper';
import type {Props as VirtualizedListProps} from 'VirtualizedList';
type Item = any;
@@ -111,7 +111,7 @@ type OptionalProps<ItemT> = {
* Called when the viewability of rows changes, as defined by the
* `viewablePercentThreshold` prop.
*/
onViewableItemsChanged?: ?({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
onViewableItemsChanged?: ?({viewableItems: Array<ViewToken>, changed: Array<ViewToken>}) => void,
legacyImplementation?: ?boolean,
/**
* Set this true while waiting for new data from a refresh.
@@ -281,7 +281,7 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
}
};
_pushMultiColumnViewable(arr: Array<Viewable>, v: Viewable): void {
_pushMultiColumnViewable(arr: Array<ViewToken>, v: ViewToken): void {
const {numColumns, keyExtractor} = this.props;
v.item.forEach((item, ii) => {
invariant(v.index != null, 'Missing index!');
@@ -36,7 +36,7 @@ const MetroListView = require('MetroListView');
const React = require('React');
const VirtualizedSectionList = require('VirtualizedSectionList');
import type {Viewable} from 'ViewabilityHelper';
import type {ViewToken} from 'ViewabilityHelper';
import type {Props as VirtualizedSectionListProps} from 'VirtualizedSectionList';
type Item = any;
@@ -54,7 +54,7 @@ type SectionBase<SectionItemT> = {
// TODO: support more optional/override props
// FooterComponent?: ?ReactClass<*>,
// HeaderComponent?: ?ReactClass<*>,
// onViewableItemsChanged?: ({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
// onViewableItemsChanged?: ({viewableItems: Array<ViewToken>, changed: Array<ViewToken>}) => void,
// TODO: support recursive sections
// SectionHeaderComponent?: ?ReactClass<{section: SectionBase<*>}>,
@@ -107,7 +107,7 @@ type OptionalProps<SectionT: SectionBase<*>> = {
* Called when the viewability of rows changes, as defined by the
* `viewablePercentThreshold` prop.
*/
onViewableItemsChanged?: ?({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
onViewableItemsChanged?: ?({viewableItems: Array<ViewToken>, changed: Array<ViewToken>}) => void,
/**
* Set this true while waiting for new data from a refresh.
*/
@@ -13,7 +13,7 @@
const invariant = require('invariant');
export type Viewable = {item: any, key: string, index: ?number, isViewable: boolean, section?: any};
export type ViewToken = {item: any, key: string, index: ?number, isViewable: boolean, section?: any};
export type ViewabilityConfig = {|
/**
@@ -68,7 +68,7 @@ class ViewabilityHelper {
_lastUpdateTime: number = 0;
_timers: Set<number> = new Set();
_viewableIndices: Array<number> = [];
_viewableItems: Map<string, Viewable> = new Map();
_viewableItems: Map<string, ViewToken> = new Map();
constructor(config: ViewabilityConfig = {viewAreaCoveragePercentThreshold: 0}) {
invariant(
@@ -140,8 +140,8 @@ class ViewabilityHelper {
scrollOffset: number,
viewportHeight: number,
getFrameMetrics: (index: number) => ?{length: number, offset: number},
createViewable: (index: number, isViewable: boolean) => Viewable,
onViewableItemsChanged: ({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
createViewToken: (index: number, isViewable: boolean) => ViewToken,
onViewableItemsChanged: ({viewableItems: Array<ViewToken>, changed: Array<ViewToken>}) => void,
renderRange?: {first: number, last: number}, // Optional optimization to reduce the scan size
): void {
const updateTime = Date.now();
@@ -186,29 +186,29 @@ class ViewabilityHelper {
const handle = setTimeout(
() => {
this._timers.delete(handle);
this._onUpdateSync(viewableIndices, onViewableItemsChanged, createViewable);
this._onUpdateSync(viewableIndices, onViewableItemsChanged, createViewToken);
},
this._config.minViewTime,
);
this._timers.add(handle);
} else {
this._onUpdateSync(viewableIndices, onViewableItemsChanged, createViewable);
this._onUpdateSync(viewableIndices, onViewableItemsChanged, createViewToken);
}
}
recordInteraction() {
this._hasInteracted = true;
}
_onUpdateSync(viewableIndicesToCheck, onViewableItemsChanged, createViewable) {
_onUpdateSync(viewableIndicesToCheck, onViewableItemsChanged, createViewToken) {
// Filter out indices that have gone out of view since this call was scheduled.
viewableIndicesToCheck = viewableIndicesToCheck.filter(
(ii) => this._viewableIndices.includes(ii)
);
const prevItems = this._viewableItems;
const nextItems = new Map(
viewableIndicesToCheck.map(ii => {
const viewable = createViewable(ii, true);
const viewable = createViewToken(ii, true);
return [viewable.key, viewable];
})
);
@@ -44,7 +44,7 @@ const invariant = require('fbjs/lib/invariant');
const {computeWindowedRenderLimits} = require('VirtualizeUtils');
import type {ViewabilityConfig, Viewable} from 'ViewabilityHelper';
import type {ViewabilityConfig, ViewToken} from 'ViewabilityHelper';
type Item = any;
type ItemComponentType = ReactClass<{item: Item, index: number}>;
@@ -105,7 +105,7 @@ type OptionalProps = {
* Called when the viewability of rows changes, as defined by the
* `viewablePercentThreshold` prop.
*/
onViewableItemsChanged?: ?({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
onViewableItemsChanged?: ?({viewableItems: Array<ViewToken>, changed: Array<ViewToken>}) => void,
/**
* Set this true while waiting for new data from a refresh.
*/
@@ -572,7 +572,7 @@ class VirtualizedList extends React.PureComponent<OptionalProps, Props, *> {
});
};
_createViewable = (index: number, isViewable: boolean): Viewable => {
_createViewToken = (index: number, isViewable: boolean): ViewToken => {
const {data, getItem, keyExtractor} = this.props;
const item = getItem(data, index);
invariant(item, 'Missing item for index ' + index);
@@ -619,7 +619,7 @@ class VirtualizedList extends React.PureComponent<OptionalProps, Props, *> {
this._scrollMetrics.offset,
this._scrollMetrics.visibleLength,
this._getFrameMetrics,
this._createViewable,
this._createViewToken,
onViewableItemsChanged,
this.state,
);
@@ -39,7 +39,7 @@ const VirtualizedList = require('VirtualizedList');
const invariant = require('invariant');
const warning = require('warning');
import type {Viewable} from 'ViewabilityHelper';
import type {ViewToken} from 'ViewabilityHelper';
import type {Props as VirtualizedListProps} from 'VirtualizedList';
type Item = any;
@@ -58,7 +58,7 @@ type SectionBase = {
// TODO: support more optional/override props
// FooterComponent?: ?ReactClass<*>,
// HeaderComponent?: ?ReactClass<*>,
// onViewableItemsChanged?: ({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
// onViewableItemsChanged?: ({viewableItems: Array<ViewToken>, changed: Array<ViewToken>}) => void,
// TODO: support recursive sections
// SectionHeaderComponent?: ?ReactClass<{section: SectionBase}>,
@@ -108,7 +108,7 @@ type OptionalProps<SectionT: SectionBase> = {
* Called when the viewability of rows changes, as defined by the
* `viewablePercentThreshold` prop.
*/
onViewableItemsChanged?: ?({viewableItems: Array<Viewable>, changed: Array<Viewable>}) => void,
onViewableItemsChanged?: ?({viewableItems: Array<ViewToken>, changed: Array<ViewToken>}) => void,
/**
* Set this true while waiting for new data from a refresh.
*/
@@ -184,8 +184,8 @@ class VirtualizedSectionList<SectionT: SectionBase>
}
}
_convertViewable = (viewable: Viewable): ?Viewable => {
invariant(viewable.index != null, 'Received a broken Viewable');
_convertViewable = (viewable: ViewToken): ?ViewToken => {
invariant(viewable.index != null, 'Received a broken ViewToken');
const info = this._subExtractor(viewable.index);
if (!info) {
return null;
@@ -200,7 +200,7 @@ class VirtualizedSectionList<SectionT: SectionBase>
};
_onViewableItemsChanged = (
{viewableItems, changed}: {viewableItems: Array<Viewable>, changed: Array<Viewable>}
{viewableItems, changed}: {viewableItems: Array<ViewToken>, changed: Array<ViewToken>}
) => {
if (this.props.onViewableItemsChanged) {
this.props.onViewableItemsChanged({
@@ -18,7 +18,7 @@ function getFrameMetrics(index: number) {
const frame = rowFrames[data[index].key];
return {length: frame.height, offset: frame.y};
}
function createViewable(index: number, isViewable: boolean) {
function createViewToken(index: number, isViewable: boolean) {
return {key: data[index].key, isViewable};
}
@@ -161,7 +161,7 @@ describe('onUpdate', function() {
0,
200,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
expect(onViewableItemsChanged.mock.calls.length).toBe(1);
@@ -174,7 +174,7 @@ describe('onUpdate', function() {
0,
200,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
expect(onViewableItemsChanged.mock.calls.length).toBe(1); // nothing changed!
@@ -183,7 +183,7 @@ describe('onUpdate', function() {
100,
200,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
expect(onViewableItemsChanged.mock.calls.length).toBe(2);
@@ -209,7 +209,7 @@ describe('onUpdate', function() {
0,
200,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
expect(onViewableItemsChanged.mock.calls.length).toBe(1);
@@ -222,7 +222,7 @@ describe('onUpdate', function() {
100,
200,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
expect(onViewableItemsChanged.mock.calls.length).toBe(2);
@@ -236,7 +236,7 @@ describe('onUpdate', function() {
200,
200,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
expect(onViewableItemsChanged.mock.calls.length).toBe(3);
@@ -262,7 +262,7 @@ describe('onUpdate', function() {
0,
200,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
expect(onViewableItemsChanged).not.toBeCalled();
@@ -292,15 +292,15 @@ describe('onUpdate', function() {
0,
200,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
helper.onUpdate(
data.length,
300, // scroll past item 'a'
200,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
@@ -335,7 +335,7 @@ describe('onUpdate', function() {
0,
100,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
expect(onViewableItemsChanged).not.toBeCalled();
@@ -344,7 +344,7 @@ describe('onUpdate', function() {
10, // not far enough to meet minimumOffset
100,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
expect(onViewableItemsChanged).not.toBeCalled();
@@ -353,7 +353,7 @@ describe('onUpdate', function() {
20,
100,
getFrameMetrics,
createViewable,
createViewToken,
onViewableItemsChanged,
);
expect(onViewableItemsChanged.mock.calls.length).toBe(1);

0 comments on commit a10dbda

Please sign in to comment.