Skip to content

Commit a24b9fc

Browse files
authored
Feature/small fixes (#3)
* update animation every time component is re-renderer * add more tests
1 parent 0a2cd67 commit a24b9fc

File tree

5 files changed

+148
-27
lines changed

5 files changed

+148
-27
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
language: node_js
22
node_js:
33
- "8"
4+
notifications:
5+
email:
6+
on_success: never
7+
on_failure: always

package.json

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-grid-list",
3-
"version": "1.0.2",
3+
"version": "1.0.4",
44
"main": "index.js",
55
"license": "Apache-2.0",
66
"author": "Gustavo Gard <[email protected]> (https://gusgard.com)",
@@ -62,10 +62,17 @@
6262
"jest": {
6363
"preset": "react-native",
6464
"setupTestFrameworkScriptFile": "./enzyme.js",
65-
"modulePathIgnorePatterns": ["<rootDir>/example/node_modules/"],
66-
"snapshotSerializers": ["./node_modules/enzyme-to-json/serializer"]
65+
"modulePathIgnorePatterns": [
66+
"<rootDir>/example/node_modules/"
67+
],
68+
"snapshotSerializers": [
69+
"./node_modules/enzyme-to-json/serializer"
70+
]
6771
},
6872
"pre-commit": {
69-
"run": ["lint", "test"]
73+
"run": [
74+
"lint",
75+
"test"
76+
]
7077
}
7178
}

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

+83-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,88 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`renders correctly 1`] = `
3+
exports[`grid list renders correctly 1`] = `
4+
<FlatList
5+
ItemSeparatorComponent={[Function]}
6+
animationDuration={500}
7+
contentContainerStyle={false}
8+
data={
9+
Array [
10+
Object {
11+
"id": 1,
12+
"thumbnail": Object {
13+
"uri": "https://...",
14+
},
15+
},
16+
Object {
17+
"id": 2,
18+
"thumbnail": Object {
19+
"uri": "https://...",
20+
},
21+
},
22+
]
23+
}
24+
disableVirtualization={false}
25+
horizontal={false}
26+
initialNumToRender={10}
27+
itemStyle={Object {}}
28+
keyExtractor={[Function]}
29+
maxToRenderPerBatch={10}
30+
numColumns={3}
31+
onEndReachedThreshold={2}
32+
renderItem={[Function]}
33+
scrollEventThrottle={50}
34+
showAnimation={false}
35+
showsVerticalScrollIndicator={false}
36+
updateCellsBatchingPeriod={50}
37+
windowSize={21}
38+
/>
39+
`;
40+
41+
exports[`grid list renders showAnimation 1`] = `
42+
<FlatList
43+
ItemSeparatorComponent={[Function]}
44+
animationDuration={500}
45+
contentContainerStyle={
46+
Object {
47+
"borderBottomWidth": 5,
48+
"borderColor": "#FFFFFF",
49+
"borderTopWidth": 5,
50+
}
51+
}
52+
data={
53+
Array [
54+
Object {
55+
"id": 1,
56+
"thumbnail": Object {
57+
"uri": "https://...",
58+
},
59+
},
60+
Object {
61+
"id": 2,
62+
"thumbnail": Object {
63+
"uri": "https://...",
64+
},
65+
},
66+
]
67+
}
68+
disableVirtualization={false}
69+
horizontal={false}
70+
initialNumToRender={10}
71+
itemStyle={Object {}}
72+
keyExtractor={[Function]}
73+
maxToRenderPerBatch={10}
74+
numColumns={3}
75+
onEndReachedThreshold={2}
76+
renderItem={[Function]}
77+
scrollEventThrottle={50}
78+
showAnimation={true}
79+
showsVerticalScrollIndicator={false}
80+
updateCellsBatchingPeriod={50}
81+
windowSize={21}
82+
/>
83+
`;
84+
85+
exports[`grid list renders showSeparator 1`] = `
486
<FlatList
587
ItemSeparatorComponent={[Function]}
688
animationDuration={500}

src/components/GridList/index.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export default class GridList extends PureComponent {
3131
};
3232

3333
componentWillMount() {
34+
this.animate();
35+
}
36+
componentWillUpdate() {
37+
this.animate();
38+
}
39+
animate() {
3440
if (this.props.showAnimation) {
3541
const { data, numColumns, animationDuration } = this.props;
3642
this.animatedValue = [];
@@ -70,20 +76,15 @@ export default class GridList extends PureComponent {
7076
}
7177
}
7278

73-
return showAnimation ? (
74-
<Animated.View
75-
style={[
76-
style,
77-
this.itemDimension,
78-
{ opacity: this.animatedValue[index] },
79-
itemStyle,
80-
]}
81-
>
82-
{renderItem({ item, index, stagger: this.stagger[index] })}
83-
</Animated.View>
84-
) : (
79+
return (
8580
<View style={[style, this.itemDimension, itemStyle]}>
86-
{renderItem({ item, index })}
81+
{showAnimation ? (
82+
<Animated.View style={[{ opacity: this.animatedValue[index] }]}>
83+
{renderItem({ item, index, stagger: this.stagger[index] })}
84+
</Animated.View>
85+
) : (
86+
renderItem({ item, index })
87+
)}
8788
</View>
8889
);
8990
};
@@ -92,7 +93,7 @@ export default class GridList extends PureComponent {
9293
const { showSeparator, ...props } = this.props;
9394
return (
9495
<FlatList
95-
contentContainerStyle={styles.container}
96+
contentContainerStyle={showSeparator && styles.container}
9697
keyExtractor={this._keyExtractor}
9798
ItemSeparatorComponent={() =>
9899
showSeparator ? <View style={styles.separator} /> : null

src/components/GridList/test.js

+35-8
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,39 @@ import GridList from './index';
77
const logo = { uri: 'https://...' };
88
const items = [{ id: 1, thumbnail: logo }, { id: 2, thumbnail: logo }];
99

10-
it('renders correctly', () => {
11-
const wrapper = shallow(
12-
<GridList
13-
data={items}
14-
renderItem={({ item }) => <Image source={item.thumbnail} />}
15-
/>,
16-
);
17-
expect(wrapper).toMatchSnapshot();
10+
describe('grid list', () => {
11+
it('renders correctly', () => {
12+
const wrapper = shallow(
13+
<GridList
14+
data={items}
15+
renderItem={({ item }) => <Image source={item.thumbnail} />}
16+
/>,
17+
);
18+
expect(wrapper).toMatchSnapshot();
19+
});
20+
21+
it('renders showSeparator', () => {
22+
const wrapper = shallow(
23+
<GridList
24+
showSeparator
25+
data={items}
26+
renderItem={({ item }) => <Image source={item.thumbnail} />}
27+
/>,
28+
);
29+
expect(wrapper).toMatchSnapshot();
30+
});
31+
32+
it('renders showAnimation', () => {
33+
const wrapper = shallow(
34+
<GridList
35+
showSeparator
36+
showAnimation
37+
data={items}
38+
renderItem={({ item, stagger }) => (
39+
<Image source={item.thumbnail} onLoad={() => stagger.start()} />
40+
)}
41+
/>,
42+
);
43+
expect(wrapper).toMatchSnapshot();
44+
});
1845
});

0 commit comments

Comments
 (0)