Skip to content
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

Update FlatList doc #12714

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Libraries/CustomComponents/Lists/FlatList.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ type OptionalProps<ItemT> = {
*/
keyExtractor: (item: ItemT, index: number) => string,
/**
* Multiple columns can only be rendered with `horizontal={false}`` and will zig-zag like a
* 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,
Expand Down Expand Up @@ -130,7 +130,7 @@ type OptionalProps<ItemT> = {
/**
* Optional custom style for multi-item rows generated when numColumns > 1
*/
columnWrapperStyle?: StyleObj,
rowWrapperStyle?: StyleObj,
/**
* Optional optimization to minimize re-rendering items.
*/
Expand Down Expand Up @@ -164,8 +164,9 @@ type DefaultProps = typeof defaultProps;
* - Separator support.
* - Pull to Refresh.
* - Scroll loading.
* - ScrollToIndex support.
*
* If you need section support, use [`<SectionList>`](/react-native/docs/sectionlist.html).
* If you need section support, use [`<SectionList>`](docs/sectionlist.html).
*
* Minimal Example:
*
Expand All @@ -174,7 +175,7 @@ type DefaultProps = typeof defaultProps;
* renderItem={({item}) => <Text>{item.key}</Text>}
* />
*
* This is a convenience wrapper around [`<VirtualizedList>`](/react-native/docs/virtualizedlist.html),
* This is a convenience wrapper around [`<VirtualizedList>`](docs/virtualizedlist.html),
* and thus inherits the following caveats:
*
* - Internal state is not preserved when content scrolls out of the render window. Make sure all
Expand Down Expand Up @@ -251,13 +252,13 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
horizontal,
legacyImplementation,
numColumns,
columnWrapperStyle,
rowWrapperStyle,
} = props;
invariant(!getItem && !getItemCount, 'FlatList does not support custom data formats.');
if (numColumns > 1) {
invariant(!horizontal, 'numColumns does not support horizontal.');
} else {
invariant(!columnWrapperStyle, 'columnWrapperStyle not supported for single column lists');
invariant(!rowWrapperStyle, 'rowWrapperStyle not supported for single column lists');
}
if (legacyImplementation) {
invariant(numColumns === 1, 'Legacy list does not support multiple columns.');
Expand Down Expand Up @@ -331,12 +332,12 @@ class FlatList<ItemT> extends React.PureComponent<DefaultProps, Props<ItemT>, vo
};

_renderItem = (info: {item: ItemT | Array<ItemT>, index: number}) => {
const {renderItem, numColumns, columnWrapperStyle} = this.props;
const {renderItem, numColumns, rowWrapperStyle} = this.props;
if (numColumns > 1) {
const {item, index} = info;
invariant(Array.isArray(item), 'Expected array of items with numColumns > 1');
return (
<View style={[{flexDirection: 'row'}, columnWrapperStyle]}>
<View style={[{flexDirection: 'row'}, rowWrapperStyle]}>
{item.map((it, kk) => {
const element = renderItem({item: it, index: index * numColumns + kk});
return element && React.cloneElement(element, {key: kk});
Expand Down