-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.tsx
101 lines (92 loc) · 2.37 KB
/
App.tsx
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
91
92
93
94
95
96
97
98
99
100
101
import React, {useState} from 'react';
import {
FlatList,
Image,
Pressable,
SafeAreaView,
Text,
View,
} from 'react-native';
import type {ImageStyle, TextStyle, ViewStyle} from 'react-native';
import {Contact, TurboContacts} from './turbo-contacts/spec';
function App(): React.JSX.Element {
const [hasPermission, setHasPermission] = useState(
TurboContacts.hasContactsPermission(),
);
const [contacts, setContacts] = useState<Array<Contact>>([]);
{
/*ListHeaderComponent={
// <Image source={require('./phone-book.jpg')} style={$image} />
// }*/
}
return (
<SafeAreaView style={$container}>
<FlatList
data={contacts}
renderItem={({item}) => (
<View style={$values}>
<View style={$icon}>
<Text>{`${item.firstName.charAt(0).toUpperCase()}${item.lastName
.charAt(0)
.toUpperCase()}`}</Text>
</View>
<View>
<Text>{`${item.firstName} ${item.lastName}`}</Text>
<Text>{item.phoneNumber}</Text>
</View>
</View>
)}
keyExtractor={(_, index) => index.toString()}
ListEmptyComponent={
<>
{hasPermission ? (
<Pressable
onPress={() => setContacts(TurboContacts.getContacts())}>
<Text>Load Contacts</Text>
</Pressable>
) : (
<Pressable
onPress={() =>
TurboContacts.requestContactsPermission().then(
setHasPermission,
)
}>
<Text>Request Permission</Text>
</Pressable>
)}
</>
}
ItemSeparatorComponent={() => <View style={$itemSeparator} />}
/>
</SafeAreaView>
);
}
const $container: ViewStyle = {
flex: 1,
marginHorizontal: 12,
};
const $values: ViewStyle = {
flexDirection: 'row',
alignItems: 'center',
paddingVertical: 12,
};
const $itemSeparator: ViewStyle = {
height: 1,
backgroundColor: 'gray',
};
const $icon: TextStyle = {
marginRight: 12,
backgroundColor: 'lightgray',
padding: 4,
borderRadius: 40 / 2,
height: 40,
width: 40,
justifyContent: 'center',
alignItems: 'center',
};
const $image: ImageStyle = {
width: '100%',
height: 200,
resizeMode: 'cover',
};
export default App;