Skip to content

Commit 6dc8a33

Browse files
committed
refactor SwiperFlatList and bump version
1 parent 83131b0 commit 6dc8a33

File tree

2 files changed

+3
-51
lines changed

2 files changed

+3
-51
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-swiper-flatlist",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"main": "index.js",
55
"license": "Apache-2.0",
66
"author": "Gustavo Gard <gusgard@gmail.com> (https://gusgard.com)",

src/components/SwiperFlatList/index.js

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React, { Component } from 'react';
1+
import React, { PureComponent } from 'react';
22
import PropTypes from 'prop-types';
33
import { TouchableOpacity, View, FlatList } from 'react-native';
44

55
import { colors } from '../../themes';
66
import styles from './styles';
77

8-
export default class SwiperFlatList extends Component {
8+
export default class SwiperFlatList extends PureComponent {
99
static propTypes = {
1010
data: PropTypes.array.isRequired,
1111
onMomentumScrollEnd: PropTypes.func,
@@ -64,54 +64,6 @@ export default class SwiperFlatList extends Component {
6464
}
6565
}
6666

67-
shouldComponentUpdate(nextProps, nextState) {
68-
// TODO improve shouldComponentUpdate
69-
const { paginationIndex } = this.state;
70-
const { paginationIndex: nextPaginationIndex } = nextState;
71-
const {
72-
children,
73-
data,
74-
renderItem,
75-
renderAll,
76-
autoplayDelay,
77-
autoplayDirection,
78-
autoplayLoop,
79-
autoplay,
80-
showPagination,
81-
vertical,
82-
} = this.props;
83-
const {
84-
children: newChildren,
85-
data: newData,
86-
renderItem: newRenderItem,
87-
renderAll: newRenderAll,
88-
autoplayDelay: newAutoplayDelay,
89-
autoplayDirection: newAutoplayDirection,
90-
autoplayLoop: newAutoplayLoop,
91-
autoplay: newAutoplay,
92-
showPagination: newShowPagination,
93-
vertical: newVertical,
94-
} = nextProps;
95-
let shouldUpdate =
96-
nextPaginationIndex !== paginationIndex ||
97-
newRenderItem !== renderItem ||
98-
renderAll !== newRenderAll ||
99-
autoplayDelay !== newAutoplayDelay ||
100-
autoplayDirection !== newAutoplayDirection ||
101-
autoplayLoop !== newAutoplayLoop ||
102-
autoplay !== newAutoplay ||
103-
showPagination !== newShowPagination ||
104-
vertical !== newVertical;
105-
106-
if (children) {
107-
shouldUpdate = shouldUpdate || children.length !== newChildren.length;
108-
}
109-
if (data) {
110-
shouldUpdate = shouldUpdate || data.length !== newData.length;
111-
}
112-
return shouldUpdate;
113-
}
114-
11567
componentWillUpdate(nextProps) {
11668
this.setup(nextProps);
11769
}

0 commit comments

Comments
 (0)