diff --git a/Libraries/Lists/FlatList.js b/Libraries/Lists/FlatList.js index 28932e5bc..3639cc361 100644 --- a/Libraries/Lists/FlatList.js +++ b/Libraries/Lists/FlatList.js @@ -72,6 +72,11 @@ type OptionalProps = { * `separators.updateProps`. */ ItemSeparatorComponent?: ?ReactClass, + /** + * Rendered when the list is empty. Can be a React Component Class, a render function, or + * a rendered element. + */ + ListEmptyComponent?: ?(ReactClass | React.Element), /** * Rendered at the bottom of all the items. Can be a React Component Class, a render function, or * a rendered element. diff --git a/Libraries/Lists/SectionList.js b/Libraries/Lists/SectionList.js index f45936b93..3e9fcae79 100644 --- a/Libraries/Lists/SectionList.js +++ b/Libraries/Lists/SectionList.js @@ -87,11 +87,18 @@ type OptionalProps> = { */ ItemSeparatorComponent?: ?ReactClass, /** - * Rendered at the very beginning of the list. + * Rendered at the very beginning of the list. Can be a React Component Class, a render function, or + * a rendered element. */ ListHeaderComponent?: ?(ReactClass | React.Element), /** - * Rendered at the very end of the list. + * Rendered when the list is empty. Can be a React Component Class, a render function, or + * a rendered element. + */ + ListEmptyComponent?: ?(ReactClass | React.Element), + /** + * Rendered at the very end of the list. Can be a React Component Class, a render function, or + * a rendered element. */ ListFooterComponent?: ?(ReactClass | React.Element), /** diff --git a/Libraries/Lists/VirtualizedList.js b/Libraries/Lists/VirtualizedList.js index 1a9f33438..21ce56dc0 100644 --- a/Libraries/Lists/VirtualizedList.js +++ b/Libraries/Lists/VirtualizedList.js @@ -82,6 +82,21 @@ type OptionalProps = { */ initialScrollIndex?: ?number, keyExtractor: (item: Item, index: number) => string, + /** + * Rendered when the list is empty. Can be a React Component Class, a render function, or + * a rendered element. + */ + ListEmptyComponent?: ?(ReactClass | React.Element), + /** + * Rendered at the bottom of all the items. Can be a React Component Class, a render function, or + * a rendered element. + */ + ListFooterComponent?: ?(ReactClass | React.Element), + /** + * Rendered at the top of all the items. Can be a React Component Class, a render function, or + * a rendered element. + */ + ListHeaderComponent?: ?(ReactClass | React.Element), /** * The maximum number of items to render in each incremental render batch. The more rendered at * once, the better the fill rate, but responsiveness my suffer because rendering content may @@ -394,14 +409,14 @@ class VirtualizedList extends React.PureComponent { }; render() { - const {ListFooterComponent, ListHeaderComponent} = this.props; + const {ListEmptyComponent, ListFooterComponent, ListHeaderComponent} = this.props; const {data, disableVirtualization, horizontal} = this.props; const cells = []; const stickyIndicesFromProps = new Set(this.props.stickyHeaderIndices); const stickyHeaderIndices = []; if (ListHeaderComponent) { const element = React.isValidElement(ListHeaderComponent) - ? ListHeaderComponent + ? ListHeaderComponent // $FlowFixMe : ; cells.push( @@ -476,10 +491,19 @@ class VirtualizedList extends React.PureComponent { ); } + } else if (ListEmptyComponent) { + const element = React.isValidElement(ListEmptyComponent) + ? ListEmptyComponent // $FlowFixMe + : ; + cells.push( + + {element} + + ); } if (ListFooterComponent) { const element = React.isValidElement(ListFooterComponent) - ? ListFooterComponent + ? ListFooterComponent // $FlowFixMe : ; cells.push( @@ -585,6 +609,10 @@ class VirtualizedList extends React.PureComponent { this._maybeCallOnEndReached(); }; + _onLayoutEmpty = (e) => { + this.props.onLayout && this.props.onLayout(e); + }; + _onLayoutFooter = (e) => { this._footerLength = this._selectLength(e.nativeEvent.layout); }; diff --git a/Libraries/Lists/__tests__/FlatList-test.js b/Libraries/Lists/__tests__/FlatList-test.js index e0d6fe56c..d5bed75dc 100644 --- a/Libraries/Lists/__tests__/FlatList-test.js +++ b/Libraries/Lists/__tests__/FlatList-test.js @@ -48,6 +48,7 @@ describe('FlatList', () => { const component = ReactTestRenderer.create( } + ListEmptyComponent={() => } ListFooterComponent={() =>