From 2d1e303a6a40590c5da8673fa86d02e41f9e8361 Mon Sep 17 00:00:00 2001 From: Nicolas Gallagher Date: Mon, 31 Dec 2018 10:26:33 -0800 Subject: [PATCH] [fix] ScrollView with stickyHeaderIndices regression A ScrollView with stickyHeaderIndices would not render children that weren't sticky. Fixes 1e202b6bd5e2da6dde6834c808dd47f82691c7ce --- .../ScrollView/__tests__/index-test.js | 16 ++++++++++++ .../src/exports/ScrollView/index.js | 26 +++++++++---------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/packages/react-native-web/src/exports/ScrollView/__tests__/index-test.js b/packages/react-native-web/src/exports/ScrollView/__tests__/index-test.js index 76c388c2..c12de3b2 100644 --- a/packages/react-native-web/src/exports/ScrollView/__tests__/index-test.js +++ b/packages/react-native-web/src/exports/ScrollView/__tests__/index-test.js @@ -3,6 +3,7 @@ import React from 'react'; import ScrollView from '..'; import StyleSheet from '../../StyleSheet'; +import View from '../../View'; import { mount, shallow } from 'enzyme'; describe('components/ScrollView', () => { @@ -13,6 +14,21 @@ describe('components/ScrollView', () => { }).not.toThrow(); }); + test('"children" prop', () => { + const component = shallow( + + + + ); + expect(component.find({ testID: 'child' }).length).toBe(1); + + component.setProps({ stickyHeaderIndices: [4] }); + expect(component.find({ testID: 'child' }).length).toBe(1); + + component.setProps({ pagingEnabled: true }); + expect(component.find({ testID: 'child' }).length).toBe(1); + }); + test('"pagingEnabled" prop', () => { const getStyleProp = (component, prop) => StyleSheet.flatten(component.prop('style'))[prop]; diff --git a/packages/react-native-web/src/exports/ScrollView/index.js b/packages/react-native-web/src/exports/ScrollView/index.js index 7fa8bea5..b4847660 100644 --- a/packages/react-native-web/src/exports/ScrollView/index.js +++ b/packages/react-native-web/src/exports/ScrollView/index.js @@ -168,20 +168,18 @@ const ScrollView = createReactClass({ const children = hasStickyHeaderIndices || pagingEnabled ? React.Children.map(this.props.children, (child, i) => { - if (child != null) { - const isSticky = hasStickyHeaderIndices && stickyHeaderIndices.indexOf(i) > -1; - if (isSticky || pagingEnabled) { - return ( - - {child} - - ); - } + const isSticky = hasStickyHeaderIndices && stickyHeaderIndices.indexOf(i) > -1; + if (child != null && (isSticky || pagingEnabled)) { + return ( + + {child} + + ); } else { return child; }