Skip to content

Commit

Permalink
Fix $FlowFixMe in Flatlist
Browse files Browse the repository at this point in the history
Summary:
$FlowFixMe suppressed type validation on _listRef. Add appropriate typing to let Flow succeed when $FlowFixMe is removed.

Not sure what this project's philosophy around ref types is. In some places I've seen them annotated as any rather than trying to get a more granular type to match. I'm open to suggestions.

`yarn flow`

[INTERNAL] [ENHANCEMENT] [FlatList.js] - Remove $FlowFixMe from FlatList
Closes facebook#16882

Differential Revision: D6386479

Pulled By: hramos

fbshipit-source-id: bed14f2c7071525cb46425ab14214771de0277f3
  • Loading branch information
cdlewis authored and bowerman0 committed Dec 5, 2017
1 parent 22a9541 commit 316b270
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const MetroListView = require('MetroListView'); // Used as a fallback legacy opt
const React = require('React');
const View = require('View');
const VirtualizedList = require('VirtualizedList');
const ListView = require('ListView');

const invariant = require('fbjs/lib/invariant');

Expand Down Expand Up @@ -326,7 +327,9 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
* Scrolls to the end of the content. May be janky without `getItemLayout` prop.
*/
scrollToEnd(params?: ?{animated?: ?boolean}) {
this._listRef.scrollToEnd(params);
if (this._listRef) {
this._listRef.scrollToEnd(params);
}
}

/**
Expand All @@ -343,7 +346,9 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
viewOffset?: number,
viewPosition?: number,
}) {
this._listRef.scrollToIndex(params);
if (this._listRef) {
this._listRef.scrollToIndex(params);
}
}

/**
Expand All @@ -357,7 +362,9 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
item: ItemT,
viewPosition?: number,
}) {
this._listRef.scrollToItem(params);
if (this._listRef) {
this._listRef.scrollToItem(params);
}
}

/**
Expand All @@ -366,7 +373,9 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
* Check out [scrollToOffset](docs/virtualizedlist.html#scrolltooffset) of VirtualizedList
*/
scrollToOffset(params: {animated?: ?boolean, offset: number}) {
this._listRef.scrollToOffset(params);
if (this._listRef) {
this._listRef.scrollToOffset(params);
}
}

/**
Expand All @@ -375,7 +384,9 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
* taps on items or by navigation actions.
*/
recordInteraction() {
this._listRef.recordInteraction();
if (this._listRef) {
this._listRef.recordInteraction();
}
}

/**
Expand All @@ -384,7 +395,9 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
* @platform ios
*/
flashScrollIndicators() {
this._listRef.flashScrollIndicators();
if (this._listRef) {
this._listRef.flashScrollIndicators();
}
}

/**
Expand Down Expand Up @@ -457,13 +470,10 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
}

_hasWarnedLegacy = false;
_listRef: VirtualizedList;
_listRef: null | VirtualizedList | ListView;
_virtualizedListPairs: Array<ViewabilityConfigCallbackPair> = [];

_captureRef = ref => {
/* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss) This comment
* suppresses an error when upgrading Flow's support for React. To see the
* error delete this comment and run Flow. */
this._listRef = ref;
};

Expand Down

0 comments on commit 316b270

Please sign in to comment.