-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathForm.js
148 lines (133 loc) · 3.34 KB
/
Form.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
'use strict';
var React = require('react-native');
var {
StyleSheet,
Text,
TextInput,
PickerIOS,
View,
TouchableHighlight,
ActivityIndicatorIOS,
Image,
Component
} = React;
var PickerItemIOS = PickerIOS.Item;
var Button = require('react-native-button');
var PhotoCapture = require('./PhotoCapture');
var Form = React.createClass({
statics: {
title: "Review your picture"
},
getInitialState() {
return {
firstName: "",
lastName: "",
host: 0,
hosts: []
}
},
_handleChangePage() {
this.props.navigator.push({
title: PhotoCapture.title,
component: PhotoCapture,
passProps: {
firstName: this.state.firstName,
lastName: this.state.lastName,
host: this.state.host,
baseUrl: this.props.baseUrl
}
});
},
componentDidMount() {
// fetch the list of hosts.
// a host is the person who the visitor wants to see.
// XXX: what about fetching from local device? how do you do that?
fetch(this.props.baseUrl + "/hosts.json")
.then((response) => response.json())
.then((responseJson) => {
var middleHostIndex = Math.round(responseJson.length/2);
this.setState({
hosts: responseJson,
host: responseJson[middleHostIndex][1]
});
})
.catch((error) => {
console.warn(error)
});
},
componentWillReceiveProps(nextProps) {
if (nextProps.resetForm === true) {
this.setState({
firstName: "",
lastName: "",
host: 0
});
}
},
render() {
// View is like the html5 <main> element
// PickerIOS is equivalent to the html <select> element
// PickerItemIOS is equivalent to html <option> element
return(
<View style={styles.formContainer}>
<TextInput
style={styles.textinput}
onChangeText={(text) => this.setState({firstName: text})}
value={this.state.firstName}
autoCorrect={false}
autoFocus={true}
placeholder="First Name" />
<TextInput
style={styles.textinput}
onChangeText={(text) => this.setState({lastName: text})}
value={this.state.lastName}
autoCorrect={false}
placeholder="Last Name" />
<Text style={styles.instructions}>
Who are you here to see?
</Text>
<PickerIOS
style={styles.picker}
selectedValue={this.state.host}
onValueChange={(host) => this.setState({host: host})}>
{this.state.hosts.map((host) => (
<PickerItemIOS
key={host[1]}
value={host[1]}
label={host[0]} />
)
)}
</PickerIOS>
<Button style={{color: 'green', padding: 10, borderWidth: 1}} onPress={this._handleChangePage}>
Next
</Button>
</View>
);
}
});
// camelCase instead of dashes.
// eg. instead of margin-left, it's marginLeft.
var styles = StyleSheet.create({
formContainer: {
marginLeft: 30,
marginRight: 30
},
picker: {
padding: 0,
margin: 0
},
instructions: {
marginTop: 30,
textAlign: 'center',
color: '#333333'
},
textinput: {
marginTop: 10,
paddingLeft: 5,
height: 40,
borderColor: 'gray',
borderWidth: 1,
backgroundColor: 'white'
}
});
module.exports = Form;