Skip to content

Commit 55b329b

Browse files
author
Mark Madlangbayan
committed
Updated to RN 0.60.5
- Migrated from deprecated ListView to FlatList - Migrated componentWillReceiveProps to getDerivedStateFromProps - Fixed warning about “VirtualizedList: missing keys for items, make sure to specify a key property on each item or provide a custom keyExtractor.” by specifying keyExtractor. - Changed package.json from dependencies to peerDependencies. - Updated react version.
1 parent f9d55ea commit 55b329b

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

index.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,25 @@ import {
55
TouchableHighlight,
66
View,
77
StyleSheet,
8-
ListView,
9-
YellowBox
8+
FlatList
109
} from "react-native";
1110
import PropTypes from "prop-types";
1211

12+
1313
export default class ModalPicker extends Component {
1414
constructor(props) {
1515
super(props);
16-
const ds = new ListView.DataSource({
17-
rowHasChanged: (r1, r2) => r1 !== r2
18-
});
1916
this.state = {
20-
dataSource: ds.cloneWithRows(this.props.data),
2117
modalVisible: false
2218
};
23-
YellowBox.ignoreWarnings(['ListView is deprecated']);
2419
}
2520

26-
componentWillReceiveProps( nextProps ) {
27-
if(this.state.dataSource != nextProps.dataSource) {
28-
this.setState({
29-
dataSource: this.state.dataSource.cloneWithRows( nextProps.data )
30-
});
21+
static getDerivedStateFromProps(props, state) {
22+
if (state.data === props.data) {
23+
return null;
3124
}
25+
26+
return { data: props.data };
3227
}
3328

3429
setModalVisible(visible) {
@@ -58,22 +53,23 @@ export default class ModalPicker extends Component {
5853
underlayColor={"#333333cc"}
5954
>
6055
<View>
61-
<ListView
62-
dataSource={this.state.dataSource}
63-
renderRow={(rowData, sectionID, rowID, higlightRow) => {
56+
<FlatList
57+
data={this.state.data}
58+
keyExtractor={(_, index) => index.toString()}
59+
renderItem={({ item, index }) => {
6460
return (
6561
<TouchableHighlight
6662
underlayColor={"transparent"}
6763
onPress={() => {
6864
this.setModalVisible(false);
69-
this.props.onValueChange(rowData[this.props.value], rowID);
65+
this.props.onValueChange(item[this.props.value], index);
7066
}}
7167
>
7268
{this.props.renderRow ? (
73-
this.props.renderRow(rowData, rowID)
69+
this.props.renderRow(item, index)
7470
) : (
7571
<Text style={styles.itemText}>
76-
{rowData[this.props.label]}
72+
{item[this.props.label]}
7773
</Text>
7874
)}
7975
</TouchableHighlight>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"url": "https://github.com/binbytes/react-native-simple-modal-picker/issues"
2828
},
2929
"homepage": "https://github.com/binbytes/react-native-simple-modal-picker#readme",
30-
"dependencies": {
30+
"peerDependencies": {
3131
"prop-types": "^15.6.2",
32-
"react": "^16.4.2"
32+
"react": "^16.8.6"
3333
}
3434
}

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+

0 commit comments

Comments
 (0)