From bb6663951920841bde6db757efd53454c4e9d772 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Tue, 8 May 2018 17:37:21 -0700 Subject: [PATCH] [fix] ScrollView stickyHeaderIndices basic support Close #434 --- .../src/exports/ScrollView/index.js | 23 ++++++++++++++++--- .../ScrollView/ScrollViewScreen.js | 13 +++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/react-native-web/src/exports/ScrollView/index.js b/packages/react-native-web/src/exports/ScrollView/index.js index 529a757a..a4250aa0 100644 --- a/packages/react-native-web/src/exports/ScrollView/index.js +++ b/packages/react-native-web/src/exports/ScrollView/index.js @@ -18,7 +18,7 @@ import StyleSheet from '../StyleSheet'; import View from '../View'; import ViewPropTypes from '../ViewPropTypes'; import React from 'react'; -import { bool, element, func, number, oneOf } from 'prop-types'; +import { arrayOf, bool, element, func, number, oneOf } from 'prop-types'; const emptyObject = {}; @@ -35,6 +35,7 @@ const ScrollView = createReactClass({ refreshControl: element, scrollEnabled: bool, scrollEventThrottle: number, + stickyHeaderIndices: arrayOf(number), style: ViewPropTypes.style }, @@ -135,11 +136,11 @@ const ScrollView = createReactClass({ horizontal, onContentSizeChange, refreshControl, + stickyHeaderIndices, /* eslint-disable */ keyboardDismissMode, onScroll, pagingEnabled, - stickyHeaderIndices, /* eslint-enable */ ...other } = this.props; @@ -163,10 +164,21 @@ const ScrollView = createReactClass({ }; } + const children = + !horizontal && Array.isArray(stickyHeaderIndices) + ? React.Children.map(this.props.children, (child, i) => { + if (stickyHeaderIndices.indexOf(i) > -1) { + return React.cloneElement(child, { style: [child.props.style, styles.stickyHeader] }); + } else { + return child; + } + }) + : this.props.children; + const contentContainer = ( ( } /> + + + An array of child indices determining which children get docked to the top of the screen + when scrolling. For example, passing stickyHeaderIndices={[0]} will cause the first + child to be fixed to the top of the scroll view. This property is not supported in + conjunction with horizontal={true}. + + } + />