From 9c09ad29fc0849d6db625bb66ab28b6caa026df0 Mon Sep 17 00:00:00 2001 From: Saleel S Date: Sat, 2 Feb 2019 01:37:05 +0400 Subject: [PATCH] Preserve original keys of section when passing down to SectionList --- README.md | 3 +++ SectionGrid.js | 8 +++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a0f5186..8abb8b5 100644 --- a/README.md +++ b/README.md @@ -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'; diff --git a/SectionGrid.js b/SectionGrid.js index 7a347da..f6c0b9f 100644 --- a/SectionGrid.js +++ b/SectionGrid.js @@ -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 ( this.renderRow({ rowItems: item, rowIndex: index, - section: section.actualSection, + section: section, isFirstRow: index === 0, itemsPerRow, rowStyle,