Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix $FlowFixMe in Flatlist #16882

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wut?


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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would the listRef ever be a ListView?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it should be MetroListView instead (https://github.com/cdlewis/react-native/blob/22e2686a7ec2bc81656d8309676ddbd74057f0ba/Libraries/Lists/FlatList.js#L624). My bad for not noticing this, probably still passed flow because they have the same props.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, when I change it to MetroListView I see a bunch of errors related to that component not having properties such as getScrollResponder. Any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm if it's just getScrollResponder maybe you could just add it to MetroListView and just call the method on the underlying ListView ref.

_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