-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.android.js
97 lines (89 loc) · 2.33 KB
/
index.android.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
91
92
93
94
95
96
97
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, {Component} from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Button,
TouchableHighlight,
ToastAndroid
} from 'react-native';
import UserList from './components/UserList';
import AddUser from './components/AddUser';
import {SERVER_HOST} from './constants';
export default class ReactNativeFirst extends Component {
constructor(props) {
super(props);
this.state = {
openAddUser: false,
users: []
}
this.openAddUser = this
.openAddUser
.bind(this);
this.loadUsers = this
.loadUsers
.bind(this);
}
openAddUser(visible) {
this.setState({openAddUser: visible});
}
loadUsers() {
fetch(SERVER_HOST + '/findusers').then((response) => response.json()).then((responseJson) => {
this.setState({users: responseJson});
ToastAndroid.show('users loaded', ToastAndroid.SHORT);
}).catch((err) => {
ToastAndroid.show(err, ToastAndroid.SHORT);
});
}
render() {
return (
<View style={styles.container}>
<UserList users={this.state.users}/>
<AddUser
onClose={(users) => {/*this.setState({ users: users || this.state.users });*/
this.openAddUser(false);
}}
visible={this.state.openAddUser}/>
<TouchableHighlight
style={styles.fullWidthButton}
onPress={() => {
this.loadUsers();
}}>
<Text style={styles.fullWidthButtonText}>Click Load Users</Text>
</TouchableHighlight>
<TouchableHighlight
style={styles.fullWidthButton}
onPress={() => {
this.openAddUser(true);
}}>
<Text style={styles.fullWidthButtonText}>Add User</Text>
</TouchableHighlight>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF'
},
fullWidthButton: {
backgroundColor: 'blue',
height: 70,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
marginTop: 2
},
fullWidthButtonText: {
fontSize: 24,
color: 'white'
}
});
AppRegistry.registerComponent('ReactNativeFirst', () => ReactNativeFirst);