Preserve original keys of section when passing down to SectionList

This commit is contained in:
Saleel S
2019-02-02 01:37:05 +04:00
parent 6fc1414553
commit 9c09ad29fc
2 changed files with 6 additions and 5 deletions

View File

@@ -88,6 +88,9 @@ import { SectionGrid } from 'react-native-super-grid';
All additional props you pass will be passed on to the internal FlatList/SectionList. This means you can make use of various props and methods like `ListHeaderComponent`, `onEndReached`, `onRefresh`...etc. While these are not tested for compatibility, most of them should work as expected.
In **SectionGrid**, `section` argument in methods like `renderSectionHeader`, `renderSectionFooter`, `ItemSeparatorComponent` will slightly different from the actual section you passed. The `data` key in the `section` will be the grouped versions of items (items that go in one row), and the original list of items can be found in `originalData` key. All other keys will remain intact.
## FlatGrid Example
```javascript
import React, { Component } from 'react';

View File

@@ -92,7 +92,6 @@ class SectionGrid extends Component {
itemDimension,
staticDimension,
renderItem,
renderSectionHeader,
onLayout,
...restProps
} = this.props;
@@ -119,9 +118,9 @@ class SectionGrid extends Component {
const chunkedData = chunkArray(section.data, itemsPerRow);
return {
title: section.title,
...section,
data: chunkedData,
actualSection: section,
originalData: section.data,
};
});
@@ -129,11 +128,10 @@ class SectionGrid extends Component {
return (
<SectionList
sections={groupedSections}
renderSectionHeader={renderSectionHeader}
renderItem={({ item, index, section }) => this.renderRow({
rowItems: item,
rowIndex: index,
section: section.actualSection,
section: section,
isFirstRow: index === 0,
itemsPerRow,
rowStyle,