From 159f4774bdb815493fbc50b263715733ee8e878d Mon Sep 17 00:00:00 2001 From: Kowaio Date: Mon, 18 Mar 2019 14:07:13 +0100 Subject: [PATCH] add scroll to top feature --- SuperGridSectionList.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/SuperGridSectionList.js b/SuperGridSectionList.js index d66b445..5e56305 100644 --- a/SuperGridSectionList.js +++ b/SuperGridSectionList.js @@ -26,7 +26,7 @@ class SuperGridSectionList extends Component { } } - + onLayout(e) { const { staticDimension, onLayout } = this.props; if (!staticDimension) { @@ -42,6 +42,17 @@ class SuperGridSectionList extends Component { } } + scrollToTop = () => { + if (this.refs.list) { + this.refs.list.scrollToLocation({ + sectionIndex: 0, + itemIndex: 0, + viewPosition: 0, + animated: true, + }); + } + } + getDimensions(lvDimension, itemDim) { const { itemWidth, spacing, fixed, staticDimension } = this.props; let itemDimension = itemDim || this.props.itemDimension; @@ -111,12 +122,12 @@ class SuperGridSectionList extends Component { const { itemsPerRow } = this.state; //Deep copy, so that re-renders and chunkArray functions don't affect the actual items object - let sectionsCopy = cloneDeep(sections); + let sectionsCopy = cloneDeep(sections); for (sectionsPair of sectionsCopy){ //Going through all the sections in sectionsCopy, and dividing their 'data' fields into smaller 'chunked' arrays to represent rows - const chunked = chunkArray(sectionsPair.data, itemsPerRow); + const chunked = chunkArray(sectionsPair.data, itemsPerRow); //Now adding metadata to these rows const rows = chunked.map((r, i) => { @@ -131,6 +142,7 @@ class SuperGridSectionList extends Component { return (