numColumns default
Reviewed By: blairvanderhoof Differential Revision: D4545192 fbshipit-source-id: 75a1e9eb27f0d3cab0c78b44d842847b64849dba
This commit is contained in:
parent
476b9f83a8
commit
906e579dd7
|
@ -93,7 +93,7 @@ type OptionalProps = {
|
|||
* Multiple columns can only be rendered with horizontal={false} and will zig-zag like a flexWrap
|
||||
* layout. Items should all be the same height - masonry layouts are not supported.
|
||||
*/
|
||||
numColumns?: number,
|
||||
numColumns: number,
|
||||
/**
|
||||
* Called once when the scroll position gets within onEndReachedThreshold of the rendered content.
|
||||
*/
|
||||
|
@ -145,6 +145,7 @@ type Props = RequiredProps & OptionalProps; // plus props from the underlying im
|
|||
class FlatList extends React.PureComponent {
|
||||
static defaultProps = {
|
||||
keyExtractor: VirtualizedList.defaultProps.keyExtractor,
|
||||
numColumns: 1,
|
||||
shouldItemUpdate: VirtualizedList.defaultProps.shouldItemUpdate,
|
||||
};
|
||||
props: Props;
|
||||
|
@ -194,13 +195,13 @@ class FlatList extends React.PureComponent {
|
|||
_captureRef = (ref) => { this._listRef = ref; };
|
||||
|
||||
_checkProps(props: Props) {
|
||||
const {getItem, getItemCount, horizontal, legacyImplementation, numColumns, } = props;
|
||||
const {getItem, getItemCount, horizontal, legacyImplementation, numColumns} = props;
|
||||
invariant(!getItem && !getItemCount, 'FlatList does not support custom data formats.');
|
||||
if (numColumns > 1) {
|
||||
invariant(!horizontal, 'numColumns does not support horizontal.');
|
||||
}
|
||||
if (legacyImplementation) {
|
||||
invariant(!(numColumns > 1), 'Legacy list does not support multiple columns.');
|
||||
invariant(numColumns === 1, 'Legacy list does not support multiple columns.');
|
||||
// Warning: may not have full feature parity and is meant more for debugging and performance
|
||||
// comparison.
|
||||
if (!this._hasWarnedLegacy) {
|
||||
|
@ -228,7 +229,7 @@ class FlatList extends React.PureComponent {
|
|||
};
|
||||
|
||||
_getItemCount = (data: Array<Item>): number => {
|
||||
return Math.floor(data.length / (this.props.numColumns || 1));
|
||||
return Math.floor(data.length / this.props.numColumns);
|
||||
};
|
||||
|
||||
_keyExtractor = (items: Item | Array<Item>, index: number): string => {
|
||||
|
|
Loading…
Reference in New Issue