|
1 | | -import React, { Component } from 'react'; |
| 1 | +import React, { PureComponent } from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | 3 | import { TouchableOpacity, View, FlatList } from 'react-native'; |
4 | 4 |
|
5 | 5 | import { colors } from '../../themes'; |
6 | 6 | import styles from './styles'; |
7 | 7 |
|
8 | | -export default class SwiperFlatList extends Component { |
| 8 | +export default class SwiperFlatList extends PureComponent { |
9 | 9 | static propTypes = { |
10 | 10 | data: PropTypes.array.isRequired, |
11 | 11 | onMomentumScrollEnd: PropTypes.func, |
@@ -64,54 +64,6 @@ export default class SwiperFlatList extends Component { |
64 | 64 | } |
65 | 65 | } |
66 | 66 |
|
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 | | - |
115 | 67 | componentWillUpdate(nextProps) { |
116 | 68 | this.setup(nextProps); |
117 | 69 | } |
|
0 commit comments