-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Fix $FlowFixMe in Flatlist #16882
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
|
||
|
@@ -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); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -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); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -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); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -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); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -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(); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -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(); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -457,13 +470,10 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> { | |
} | ||
|
||
_hasWarnedLegacy = false; | ||
_listRef: VirtualizedList; | ||
_listRef: null | VirtualizedList | ListView; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would the listRef ever be a ListView? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm if it's just |
||
_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; | ||
}; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wut?