[fix] ScrollView with stickyHeaderIndices regression

A ScrollView with stickyHeaderIndices would not render children that
weren't sticky.

Fixes 1e202b6bd5
This commit is contained in:
Nicolas Gallagher
2018-12-31 10:26:33 -08:00
parent 209ff1fa40
commit 2d1e303a6a
2 changed files with 28 additions and 14 deletions

View File

@@ -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(
<ScrollView>
<View testID="child" />
</ScrollView>
);
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];

View File

@@ -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 (
<View
style={StyleSheet.compose(
isSticky && styles.stickyHeader,
pagingEnabled && styles.pagingEnabledChild
)}
>
{child}
</View>
);
}
const isSticky = hasStickyHeaderIndices && stickyHeaderIndices.indexOf(i) > -1;
if (child != null && (isSticky || pagingEnabled)) {
return (
<View
style={StyleSheet.compose(
isSticky && styles.stickyHeader,
pagingEnabled && styles.pagingEnabledChild
)}
>
{child}
</View>
);
} else {
return child;
}