-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
80 lines (66 loc) · 1.94 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
import React from 'react';
import { Button, SectionList, StyleSheet, Text, View } from 'react-native';
import Constants from 'expo-constants';
import contacts, { compareNames } from './contacts'
import AddContactForm from './AddContactForm'
import ContactsList from './ContactsList'
export default class App extends React.Component {
state = {
showContacts: false,
showForm: false,
contacts: contacts,
}
toggleContacts = () => {
this.setState(prevState => ({ showContacts: !prevState.showContacts }))
}
toggleForm = () => {
this.setState(prevState => ({ showForm: !prevState.showForm }))
}
sort = () => {
this.setState(prevState => ({
contacts: prevState.contacts.sort(compareNames)
}))
}
render() {
if (!this.state.showForm) {
return (
<View style = { styles.container } >
<
Button title = "toggle contacts"
onPress = { this.toggleContacts }
/>
<Button title = "Add Contact"
onPress = { this.toggleForm }
/>
<Button title = "sort"
onPress = { this.sort }
/>
{
(this.state.showContacts) && ( <
ContactsList contacts = { this.state.contacts }
/>
)
}
</View>
)
} else {
return (
<View >
<
AddContactForm addContact = { this.addContact }
/>
<Button title = "back"
onPress = { this.toggleForm }
/>
</View >
)
}
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
paddingTop: Constants.statusBarHeight,
},
});