From 22e2686a7ec2bc81656d8309676ddbd74057f0ba Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Fri, 3 Nov 2017 19:47:54 -0700 Subject: [PATCH 1/2] Fix $FlowFixMe in Flatlist --- Libraries/Lists/FlatList.js | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index 9b145cdbd4b5bc..d7dcb12f0dd914 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -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 extends React.PureComponent, 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 extends React.PureComponent, void> { viewOffset?: number, viewPosition?: number, }) { - this._listRef.scrollToIndex(params); + if (this._listRef) { + this._listRef.scrollToIndex(params); + } } /** @@ -357,7 +362,9 @@ class FlatList extends React.PureComponent, void> { item: ItemT, viewPosition?: number, }) { - this._listRef.scrollToItem(params); + if (this._listRef) { + this._listRef.scrollToItem(params); + } } /** @@ -366,7 +373,9 @@ class FlatList extends React.PureComponent, 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 extends React.PureComponent, void> { * taps on items or by navigation actions. */ recordInteraction() { - this._listRef.recordInteraction(); + if (this._listRef) { + this._listRef.recordInteraction(); + } } /** @@ -384,7 +395,9 @@ class FlatList extends React.PureComponent, void> { * @platform ios */ flashScrollIndicators() { - this._listRef.flashScrollIndicators(); + if (this._listRef) { + this._listRef.flashScrollIndicators(); + } } /** @@ -457,13 +470,10 @@ class FlatList extends React.PureComponent, void> { } _hasWarnedLegacy = false; - _listRef: VirtualizedList; + _listRef: null | VirtualizedList | ListView; _virtualizedListPairs: Array = []; - _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. */ + _captureRef = (ref: null | VirtualizedList | ListView) => { this._listRef = ref; }; From 989f55272d979d19c476728a17a8b297894933db Mon Sep 17 00:00:00 2001 From: Chris Lewis Date: Sun, 19 Nov 2017 14:56:35 -0800 Subject: [PATCH 2/2] PR feedback --- Libraries/Lists/FlatList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index d7dcb12f0dd914..63539c89ca1df0 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -473,7 +473,7 @@ class FlatList extends React.PureComponent, void> { _listRef: null | VirtualizedList | ListView; _virtualizedListPairs: Array = []; - _captureRef = (ref: null | VirtualizedList | ListView) => { + _captureRef = ref => { this._listRef = ref; };