-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
90 lines (84 loc) · 2 KB
/
App.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React, { Component } from 'react';
import {
StyleSheet,
NativeModules,
Text,
View,
Image,
FlatList,
DeviceEventEmitter
} from 'react-native';
const ContactsManager = NativeModules.ContactsManager;
export default class App extends Component {
constructor(props) {
super(props);
this.state = { contacts: [] };
}
componentWillMount() {
ContactsManager.getContacts();
DeviceEventEmitter.addListener('aaa', function (e) {
this.setState({ contacts: [...this.state.contacts, e] });
}.bind(this));
}
renderItem(contact) {
const data = contact.split('*');
const { itemStyle, textStyle, imageStyle } = styles;
return (
<View style={itemStyle}>
{data[2] !== 'null' && <Image source={{ uri: data[2] }} style={[imageStyle, { borderRadius: 25 }]} />}
{data[2] === 'null' && <Image source={require('./contact.png')} style={imageStyle} />}
<View style={{ marginLeft: 10 }}>
<Text style={textStyle}>{data[0]}</Text>
<Text>{data[1]}</Text>
</View>
</View>
);
}
render() {
const { contacts } = this.state;
const { headerStyle, titleStyle } = styles;
return (
<View>
<View style={headerStyle}>
<Text style={titleStyle}>Contacts</Text>
</View>
<FlatList
data={contacts.sort()}
renderItem={({ item }) => this.renderItem(item)}
keyExtractor={(item, index) => index}
/>
</View>
);
}
}
const styles = StyleSheet.create({
itemStyle: {
flexDirection: 'row',
alignItems: 'center',
borderColor: '#ccc',
borderBottomWidth: 1,
padding: 10,
flex: 1
},
textStyle: {
fontSize: 18,
flex: 1,
flexWrap: 'wrap'
},
imageStyle: {
width: 50,
height: 50
},
headerStyle: {
height: 60,
alignItems: 'center',
justifyContent: 'center',
elevation: 3,
backgroundColor: '#e93636'
},
titleStyle: {
fontWeight: 'bold',
fontSize: 19,
color: 'white'
}
});