forked from robcalcroft/react-native-multiselect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiSelectRow.js
More file actions
67 lines (58 loc) · 1.44 KB
/
MultiSelectRow.js
File metadata and controls
67 lines (58 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { TouchableHighlight, View, StyleSheet } from 'react-native';
const styles = StyleSheet.create({
row: {
flexDirection: 'row',
alignItems: 'center',
},
});
class MultiSelectRow extends Component {
constructor() {
super();
this.isSelected = false;
}
shouldComponentUpdate(nextProps) {
if (this.isSelected === nextProps.isSelected) {
return false;
}
return true;
}
render() {
const {
row,
rowStyle,
isSelected,
renderRow,
selectRow,
activeOpacity,
underlayColor,
} = this.props;
this.isSelected = isSelected;
return (
<TouchableHighlight
activeOpacity={activeOpacity || 0.8}
underlayColor={underlayColor || 'white'}
onPress={() => selectRow(row)}
>
<View style={[styles.row, StyleSheet.flatten(rowStyle)]}>
{renderRow(row, isSelected)}
</View>
</TouchableHighlight>
);
}
}
MultiSelectRow.propTypes = {
row: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
isSelected: PropTypes.bool,
renderRow: PropTypes.func.isRequired,
selectRow: PropTypes.func.isRequired,
activeOpacity: PropTypes.number,
underlayColor: PropTypes.string,
rowStyle: PropTypes.oneOfType([
PropTypes.object,
PropTypes.number,
PropTypes.string,
]),
};
export default MultiSelectRow;