Skip to content

Commit

Permalink
Flowtype ListView
Browse files Browse the repository at this point in the history
Reviewed By: yungsters

Differential Revision: D7985836

fbshipit-source-id: 6e0944a8d2fb85aabc34dfd3125a07b208749f21
  • Loading branch information
elicwhite authored and facebook-github-bot committed May 14, 2018
1 parent af6e2eb commit 4b1ecb6
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Libraries/Components/ScrollView/ScrollView.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type VRProps = $ReadOnly<{|
scrollBarThumbImage?: ?($ReadOnly<{||}> | number),
|}>;

type Props = $ReadOnly<{|
export type Props = $ReadOnly<{|
...ViewProps,
...TouchableProps,
...IOSProps,
Expand Down
2 changes: 2 additions & 0 deletions Libraries/Experimental/SwipeableRow/SwipeableListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ class SwipeableListView extends React.Component<Props, State> {

render(): React.Node {
return (
// $FlowFixMe Found when typing ListView
<ListView
{...this.props}
ref={ref => {
// $FlowFixMe Found when typing ListView
this._listViewRef = ref;
}}
dataSource={this.state.dataSource.getDataSource()}
Expand Down
1 change: 1 addition & 0 deletions Libraries/Inspector/NetworkOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ class NetworkOverlay extends React.Component<
renderRow={this._renderRow}
enableEmptySections={true}
renderSeparator={this._renderSeperator}
// $FlowFixMe Found when typing ListView
onLayout={this._listViewOnLayout}
/>
</View>
Expand Down
9 changes: 8 additions & 1 deletion Libraries/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
viewPosition?: number,
}) {
if (this._listRef) {
// $FlowFixMe Found when typing ListView
this._listRef.scrollToIndex(params);
}
}
Expand All @@ -362,6 +363,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
viewPosition?: number,
}) {
if (this._listRef) {
// $FlowFixMe Found when typing ListView
this._listRef.scrollToItem(params);
}
}
Expand All @@ -373,6 +375,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
*/
scrollToOffset(params: {animated?: ?boolean, offset: number}) {
if (this._listRef) {
// $FlowFixMe Found when typing ListView
this._listRef.scrollToOffset(params);
}
}
Expand All @@ -384,6 +387,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
*/
recordInteraction() {
if (this._listRef) {
// $FlowFixMe Found when typing ListView
this._listRef.recordInteraction();
}
}
Expand All @@ -395,6 +399,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
*/
flashScrollIndicators() {
if (this._listRef) {
// $FlowFixMe Found when typing ListView
this._listRef.flashScrollIndicators();
}
}
Expand All @@ -404,12 +409,14 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
*/
getScrollResponder() {
if (this._listRef) {
// $FlowFixMe Found when typing ListView
return this._listRef.getScrollResponder();
}
}

getScrollableNode() {
if (this._listRef) {
// $FlowFixMe Found when typing ListView
return this._listRef.getScrollableNode();
}
}
Expand Down Expand Up @@ -472,7 +479,7 @@ class FlatList<ItemT> extends React.PureComponent<Props<ItemT>, void> {
}

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

_captureRef = ref => {
Expand Down
30 changes: 30 additions & 0 deletions Libraries/Lists/ListView/InternalListViewType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/

const React = require('React');
const ListViewDataSource = require('ListViewDataSource');

// This class is purely a facsimile of ListView so that we can
// properly type it with Flow before migrating ListView off of
// createReactClass. If there are things missing here that are in
// ListView, that is unintentional.
class InternalListViewType<Props> extends React.Component<Props> {
static DataSource = ListViewDataSource;
setNativeProps(props: Object) {}
flashScrollIndicators() {}
getScrollResponder(): any {}
getScrollableNode(): any {}
// $FlowFixMe
getMetrics(): Object {}
scrollTo(...args: Array<mixed>) {}
scrollToEnd(options?: ?{animated?: ?boolean}) {}
}

module.exports = InternalListViewType;
31 changes: 28 additions & 3 deletions Libraries/Lists/ListView/ListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
'use strict';

const InternalListViewType = require('InternalListViewType');
const ListViewDataSource = require('ListViewDataSource');
const Platform = require('Platform');
const React = require('React');
Expand All @@ -25,12 +26,36 @@ const createReactClass = require('create-react-class');
const isEmpty = require('isEmpty');
const merge = require('merge');

import type {Props as ScrollViewProps} from 'ScrollView';

const DEFAULT_PAGE_SIZE = 1;
const DEFAULT_INITIAL_ROWS = 10;
const DEFAULT_SCROLL_RENDER_AHEAD = 1000;
const DEFAULT_END_REACHED_THRESHOLD = 1000;
const DEFAULT_SCROLL_CALLBACK_THROTTLE = 50;

type Props = $ReadOnly<{|
...ScrollViewProps,

dataSource: ListViewDataSource,
renderSeparator?: ?Function,
renderRow: Function,
initialListSize?: ?number,
onEndReached?: ?Function,
onEndReachedThreshold?: ?number,
pageSize?: ?number,
renderFooter?: ?Function,
renderHeader?: ?Function,
renderSectionHeader?: ?Function,
renderScrollComponent?: ?Function,
scrollRenderAheadDistance?: ?number,
onChangeVisibleRows?: ?Function,
removeClippedSubviews?: ?boolean,
stickySectionHeadersEnabled?: ?boolean,
stickyHeaderIndices?: ?$ReadOnlyArray<number>,
enableEmptySections?: ?boolean,
|}>;

/**
* DEPRECATED - use one of the new list components, such as [`FlatList`](docs/flatlist.html)
* or [`SectionList`](docs/sectionlist.html) for bounded memory use, fewer bugs,
Expand Down Expand Up @@ -92,7 +117,7 @@ const ListView = createReactClass({
displayName: 'ListView',
_childFrames: ([]: Array<Object>),
_sentEndForContentLength: (null: ?number),
_scrollComponent: (null: any),
_scrollComponent: (null: ?React.ElementRef<typeof ScrollView>),
_prevRenderedRowsCount: 0,
_visibleRows: ({}: Object),
scrollProperties: ({}: Object),
Expand Down Expand Up @@ -555,7 +580,7 @@ const ListView = createReactClass({
);
},

_setScrollComponentRef: function(scrollComponent: Object) {
_setScrollComponentRef: function(scrollComponent) {
this._scrollComponent = scrollComponent;
},

Expand Down Expand Up @@ -752,4 +777,4 @@ const ListView = createReactClass({
},
});

module.exports = ListView;
module.exports = ((ListView: any): Class<InternalListViewType<Props>>);
2 changes: 2 additions & 0 deletions Libraries/Lists/MetroListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class MetroListView extends React.Component<Props, $FlowFixMeState> {
}
render() {
return (
// $FlowFixMe Found when typing ListView
<ListView
{...this.props}
dataSource={this.state.ds}
Expand Down Expand Up @@ -170,6 +171,7 @@ class MetroListView extends React.Component<Props, $FlowFixMeState> {
} else {
invariant(!props.sections, 'Cannot have both sections and items props.');
return {
// $FlowFixMe Found when typing ListView
ds: state.ds.cloneWithRows(props.items),
sectionHeaderData,
};
Expand Down
1 change: 1 addition & 0 deletions Libraries/Lists/SectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class SectionList<SectionT: SectionBase<any>> extends React.PureComponent<
*/
recordInteraction() {
const listRef = this._wrapperListRef && this._wrapperListRef.getListRef();
// $FlowFixMe Found when typing ListView
listRef && listRef.recordInteraction();
}

Expand Down

0 comments on commit 4b1ecb6

Please sign in to comment.