mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-01-12 22:51:09 +08:00
[fix] ScrollView with stickyHeaderIndices regression
A ScrollView with stickyHeaderIndices would not render children that
weren't sticky.
Fixes 1e202b6bd5
This commit is contained in:
@@ -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];
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user