-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventForm.js
109 lines (100 loc) · 2.96 KB
/
EventForm.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
import React, { Component } from 'react';
import { View, Text, TouchableHighlight, TextInput, StyleSheet } from 'react-native';
import DateTimePicker from 'react-native-modal-datetime-picker';
import { formatDateTime, saveEvent } from './api';
const styles = StyleSheet.create({
fieldContainer: {
marginTop: 20,
marginBottom: 20,
backgroundColor: "#fff",
},
text: {
height: 40,
margin: 0,
marginRight: 7,
paddingLeft: 10
},
button: {
height: 50,
backgroundColor: '#48BBEC',
borderColor: '#48bbec',
alignSelf: 'stretch',
margin: 10,
justifyContent: 'center',
alignItems: 'center',
borderRadius: 5,
},
buttonText: {
color: '#fff',
fontSize: 18,
},
borderTop: {
borderColor: '#edeeef',
borderTopWidth: 0.5
}
});
class EventForm extends Component {
state = {
title: null,
date: '',
};
handleAddPress = () => {
saveEvent(this.state)
.then(() => this.props.navigation.navigate('Home'));
}
handleChangeTitle = (value) => {
this.setState({ title: value })
}
handleDatePress = () => {
this.setState({ showDatePicker: true })
}
handleDatePicked = (date) => {
this.setState({
date,
});
this.handleDatePickerHide();
}
handleDatePickerHide = () => {
this.setState({ showDatePicker: false });
}
render() {
return (
<View
style={{
flex: 1
}}
>
<View style={styles.fieldContainer}>
<TextInput
style={styles.text}
placeholder="Event"
spellCheck={false}
value={this.state.title}
onChangeText={this.handleChangeTitle}
/>
<TextInput
style={[styles.text, styles.borderTop]}
placeholder="Event date"
spellCheck={false}
value={formatDateTime(this.state.date.toString())}
editable={!this.state.showDatePicker}
onFocus={this.handleDatePress}
/>
<DateTimePicker
isVisible={this.state.showDatePicker}
mode="datetime"
onConfirm={this.handleDatePicked}
onCancel={this.handleDatePickerHide}
/>
</View>
<TouchableHighlight
onPress={this.handleAddPress}
style={styles.button}
>
<Text style={styles.buttonText}>Add</Text>
</TouchableHighlight>
</View>
)
}
}
export default EventForm;