Skip to content

Commit

Permalink
Add missing class annotations and lock xplat/js
Browse files Browse the repository at this point in the history
Reviewed By: SamChou19815

Differential Revision: D38374141

fbshipit-source-id: 967291a5c1a29f39b7272726c8b41bc74d1be043
  • Loading branch information
pieterv authored and facebook-github-bot committed Aug 4, 2022
1 parent c687dd3 commit 0ccbe5f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
}
}

// $FlowFixMe[missing-local-annot]
componentDidUpdate(prevProps: Props<ItemT>) {
invariant(
prevProps.numColumns === this.props.numColumns,
Expand Down Expand Up @@ -463,6 +464,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
this._listRef = ref;
};

// $FlowFixMe[missing-local-annot]
_checkProps(props: Props<ItemT>) {
const {
// $FlowFixMe[prop-missing] this prop doesn't exist, is only used for an invariant
Expand Down Expand Up @@ -494,6 +496,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
);
}

// $FlowFixMe[missing-local-annot]
_getItem = (data: Array<ItemT>, index: number) => {
const numColumns = numColumnsOrDefault(this.props.numColumns);
if (numColumns > 1) {
Expand All @@ -520,6 +523,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
}
};

// $FlowFixMe[missing-local-annot]
_keyExtractor = (items: ItemT | Array<ItemT>, index: number) => {
const numColumns = numColumnsOrDefault(this.props.numColumns);
const keyExtractor = this.props.keyExtractor ?? defaultKeyExtractor;
Expand Down Expand Up @@ -561,6 +565,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
changed: Array<ViewToken>,
...
}) => void,
// $FlowFixMe[missing-local-annot]
) {
return (info: {
viewableItems: Array<ViewToken>,
Expand Down Expand Up @@ -590,6 +595,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
columnWrapperStyle: ?ViewStyleProp,
numColumns: ?number,
extraData: ?any,
// $FlowFixMe[missing-local-annot]
) => {
const cols = numColumnsOrDefault(numColumns);

Expand Down Expand Up @@ -651,6 +657,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
};
};

// $FlowFixMe[missing-local-annot]
_memoizedRenderer = memoizeOne(this._renderer);

render(): React.Node {
Expand Down
15 changes: 13 additions & 2 deletions Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
viewOffset?: number,
viewPosition?: number,
...
}) {
}): $FlowFixMe {
const {
data,
horizontal,
Expand Down Expand Up @@ -369,6 +369,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
};
}

// $FlowFixMe[missing-local-annot]
_getScrollMetrics = () => {
return this._scrollMetrics;
};
Expand All @@ -377,6 +378,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
return this._hasMore;
}

// $FlowFixMe[missing-local-annot]
_getOutermostParentListRef = () => {
if (this._isNestedWithSameOrientation()) {
return this.context.getOutermostParentListRef();
Expand Down Expand Up @@ -631,6 +633,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
_getSpacerKey = (isVertical: boolean): string =>
isVertical ? 'height' : 'width';

// $FlowFixMe[missing-local-annot]
_keyExtractor(item: Item, index: number) {
if (this.props.keyExtractor != null) {
return this.props.keyExtractor(item, index);
Expand Down Expand Up @@ -985,6 +988,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
> = new Map();
_offsetFromParentVirtualizedList: number = 0;
_prevParentOffset: number = 0;
// $FlowFixMe[missing-local-annot]
_scrollMetrics = {
contentLength: 0,
dOffset: 0,
Expand Down Expand Up @@ -1016,6 +1020,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
);
}

// $FlowFixMe[missing-local-annot]
_getCellsInItemCount = (props: Props) => {
const {getCellsInItemCount, data} = props;
if (getCellsInItemCount) {
Expand Down Expand Up @@ -1231,6 +1236,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
this._headerLength = this._selectLength(e.nativeEvent.layout);
};

// $FlowFixMe[missing-local-annot]
_renderDebugOverlay() {
const normalize =
this._scrollMetrics.visibleLength /
Expand Down Expand Up @@ -1376,7 +1382,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
visibleLength: number,
offset: number,
...
}) => {
}): $FlowFixMe => {
// Offset of the top of the nested list relative to the top of its parent's viewport
const offset = metrics.offset - this._offsetFromParentVirtualizedList;
// Child's visible length is the same as its parent's
Expand Down Expand Up @@ -1653,6 +1659,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
});
};

// $FlowFixMe[missing-local-annot]
_createViewToken = (index: number, isViewable: boolean) => {
const {data, getItem} = this.props;
const item = getItem(data, index);
Expand Down Expand Up @@ -1770,6 +1777,7 @@ class CellRenderer extends React.Component<
CellRendererProps,
CellRendererState,
> {
// $FlowFixMe[missing-local-annot]
state = {
separatorProps: {
highlighted: false,
Expand All @@ -1791,6 +1799,7 @@ class CellRenderer extends React.Component<

// TODO: consider factoring separator stuff out of VirtualizedList into FlatList since it's not
// reused by SectionList and we can keep VirtualizedList simpler.
// $FlowFixMe[missing-local-annot]
_separators = {
highlight: () => {
const {cellKey, prevCellKey} = this.props;
Expand Down Expand Up @@ -1837,6 +1846,7 @@ class CellRenderer extends React.Component<
ListItemComponent: any,
item: any,
index: any,
// $FlowFixMe[missing-local-annot]
) {
if (renderItem && ListItemComponent) {
console.warn(
Expand Down Expand Up @@ -1882,6 +1892,7 @@ class CellRenderer extends React.Component<
);
}

// $FlowFixMe[missing-local-annot]
render() {
const {
CellRendererComponent,
Expand Down
15 changes: 13 additions & 2 deletions Libraries/Lists/VirtualizedList_EXPERIMENTAL.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
viewOffset?: number,
viewPosition?: number,
...
}) {
}): $FlowFixMe {
const {
data,
horizontal,
Expand Down Expand Up @@ -389,6 +389,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
};
}

// $FlowFixMe[missing-local-annot]
_getScrollMetrics = () => {
return this._scrollMetrics;
};
Expand All @@ -397,6 +398,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
return this._hasMore;
}

// $FlowFixMe[missing-local-annot]
_getOutermostParentListRef = () => {
if (this._isNestedWithSameOrientation()) {
return this.context.getOutermostParentListRef();
Expand Down Expand Up @@ -849,6 +851,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
keyExtractor?: ?(item: Item, index: number) => string,
...
},
// $FlowFixMe[missing-local-annot]
) {
if (props.keyExtractor != null) {
return props.keyExtractor(item, index);
Expand Down Expand Up @@ -1180,6 +1183,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
> = new Map();
_offsetFromParentVirtualizedList: number = 0;
_prevParentOffset: number = 0;
// $FlowFixMe[missing-local-annot]
_scrollMetrics = {
contentLength: 0,
dOffset: 0,
Expand Down Expand Up @@ -1211,6 +1215,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
);
}

// $FlowFixMe[missing-local-annot]
_getCellsInItemCount = (props: Props) => {
const {getCellsInItemCount, data} = props;
if (getCellsInItemCount) {
Expand Down Expand Up @@ -1442,6 +1447,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
this._headerLength = this._selectLength(e.nativeEvent.layout);
};

// $FlowFixMe[missing-local-annot]
_renderDebugOverlay() {
const normalize =
this._scrollMetrics.visibleLength /
Expand Down Expand Up @@ -1593,7 +1599,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
visibleLength: number,
offset: number,
...
}) => {
}): $FlowFixMe => {
// Offset of the top of the nested list relative to the top of its parent's viewport
const offset = metrics.offset - this._offsetFromParentVirtualizedList;
// Child's visible length is the same as its parent's
Expand Down Expand Up @@ -1797,6 +1803,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
index: number,
isViewable: boolean,
props: FrameMetricProps,
// $FlowFixMe[missing-local-annot]
) => {
const {data, getItem} = props;
const item = getItem(data, index);
Expand Down Expand Up @@ -1986,6 +1993,7 @@ class CellRenderer extends React.Component<
CellRendererProps,
CellRendererState,
> {
// $FlowFixMe[missing-local-annot]
state = {
separatorProps: {
highlighted: false,
Expand All @@ -2007,6 +2015,7 @@ class CellRenderer extends React.Component<

// TODO: consider factoring separator stuff out of VirtualizedList into FlatList since it's not
// reused by SectionList and we can keep VirtualizedList simpler.
// $FlowFixMe[missing-local-annot]
_separators = {
highlight: () => {
const {cellKey, prevCellKey} = this.props;
Expand Down Expand Up @@ -2053,6 +2062,7 @@ class CellRenderer extends React.Component<
ListItemComponent: any,
item: any,
index: any,
// $FlowFixMe[missing-local-annot]
) {
if (renderItem && ListItemComponent) {
console.warn(
Expand Down Expand Up @@ -2098,6 +2108,7 @@ class CellRenderer extends React.Component<
);
}

// $FlowFixMe[missing-local-annot]
render() {
const {
CellRendererComponent,
Expand Down
3 changes: 2 additions & 1 deletion Libraries/Lists/VirtualizedSectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class VirtualizedSectionList<
return null;
}

// $FlowFixMe[missing-local-annot]
_keyExtractor = (item: Item, index: number) => {
const info = this._subExtractor(index);
return (info && info.key) || String(index);
Expand Down Expand Up @@ -340,7 +341,7 @@ class VirtualizedSectionList<
};

_renderItem =
(listItemCount: number) =>
(listItemCount: number): $FlowFixMe =>
// eslint-disable-next-line react/no-unstable-nested-components
({
item,
Expand Down
7 changes: 7 additions & 0 deletions packages/rn-tester/js/examples/FlatList/FlatList-basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,14 @@ class FlatListExample extends React.PureComponent<Props, State> {
this._listRef.scrollToIndex({viewPosition: 0.5, index: Number(text)});
};

// $FlowFixMe[missing-local-annot]
_scrollPos = new Animated.Value(0);
// $FlowFixMe[missing-local-annot]
_scrollSinkX = Animated.event(
[{nativeEvent: {contentOffset: {x: this._scrollPos}}}],
{useNativeDriver: true},
);
// $FlowFixMe[missing-local-annot]
_scrollSinkY = Animated.event(
[{nativeEvent: {contentOffset: {y: this._scrollPos}}}],
{useNativeDriver: true},
Expand Down Expand Up @@ -271,6 +274,7 @@ class FlatListExample extends React.PureComponent<Props, State> {
) => {
this._listRef = ref;
};
// $FlowFixMe[missing-local-annot]
_getItemLayout = (data: any, index: number) => {
return getItemLayout(data, index, this.state.horizontal);
};
Expand All @@ -282,13 +286,16 @@ class FlatListExample extends React.PureComponent<Props, State> {
data: state.data.concat(genItemData(100, state.data.length)),
}));
};
// $FlowFixMe[missing-local-annot]
_onPressCallback = () => {
const {onPressDisabled} = this.state;
const warning = () => console.log('onPress disabled');
const onPressAction = onPressDisabled ? warning : this._pressItem;
return onPressAction;
};
// $FlowFixMe[missing-local-annot]
_onRefresh = () => Alert.alert('onRefresh: nothing to refresh :P');
// $FlowFixMe[missing-local-annot]
_renderItemComponent = () => {
const flatListPropKey = this.state.useFlatListItemComponent
? 'ListItemComponent'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class MultiColumnExample extends React.PureComponent<
item: Item,
accessibilityCollectionItem: AccessibilityCollectionItem,
...
}) => {
}): $FlowFixMe => {
return (
<View
importantForAccessibility="yes"
Expand Down

0 comments on commit 0ccbe5f

Please sign in to comment.