Skip to content

Commit 069b541

Browse files
authored
Feature/array empty (#9)
* remove data prop required * add empty list test
1 parent 682e517 commit 069b541

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/components/GridList/__snapshots__/test.js.snap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,32 @@ exports[`grid list renders correctly 1`] = `
9999
/>
100100
`;
101101

102+
exports[`grid list renders empty list 1`] = `
103+
<FlatList
104+
ItemSeparatorComponent={[Function]}
105+
animationDuration={500}
106+
animationInitialBackgroundColor="#FFFFFF"
107+
contentContainerStyle={false}
108+
data={Array []}
109+
disableVirtualization={false}
110+
horizontal={false}
111+
initialNumToRender={10}
112+
itemStyle={Object {}}
113+
keyExtractor={[Function]}
114+
maxToRenderPerBatch={10}
115+
numColumns={3}
116+
onEndReachedThreshold={2}
117+
renderItem={[Function]}
118+
scrollEventThrottle={50}
119+
separatorBorderColor="#FFFFFF"
120+
separatorBorderWidth={0}
121+
showAnimation={false}
122+
showsVerticalScrollIndicator={false}
123+
updateCellsBatchingPeriod={50}
124+
windowSize={21}
125+
/>
126+
`;
127+
102128
exports[`grid list renders showAnimation 1`] = `
103129
<FlatList
104130
ItemSeparatorComponent={[Function]}

src/components/GridList/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class GridList extends PureComponent {
2222
// Only is allowed children or data not both
2323
children(props, propName) {
2424
const { data } = props;
25-
if (!props[propName] && data && data.length === 0) {
25+
if (!props[propName] && !data) {
2626
return new Error('Invalid props, `data` or `children` is required');
2727
}
2828
if (data && data.length !== 0 && !props.renderItem) {
@@ -34,6 +34,7 @@ export default class GridList extends PureComponent {
3434

3535
static defaultProps = {
3636
numColumns: 3,
37+
data: [],
3738
itemStyle: {},
3839
showSeparator: false,
3940
showAnimation: false,

src/components/GridList/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ describe('grid list', () => {
1717
);
1818
expect(wrapper).toMatchSnapshot();
1919
});
20+
21+
it('renders empty list', () => {
22+
const wrapper = shallow(
23+
<GridList
24+
data={[]}
25+
renderItem={({ item }) => <Image source={item.thumbnail} />}
26+
/>,
27+
);
28+
expect(wrapper).toMatchSnapshot();
29+
});
2030

2131
it('renders showSeparator', () => {
2232
const wrapper = shallow(

0 commit comments

Comments
 (0)