-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventForm.js
More file actions
113 lines (102 loc) · 2.51 KB
/
Copy pathEventForm.js
File metadata and controls
113 lines (102 loc) · 2.51 KB
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
import React, { Component } from 'react';
import { View, Text, TouchableHighlight, TextInput, StyleSheet } from 'react-native';
import { formatDateTime, saveEvent } from './api';
import DateTimePicker from 'react-native-modal-datetime-picker';
const styles = StyleSheet.create({
fieldContainer: {
marginTop: 20,
marginBottom: 20,
backgroundColor: '#fff'
},
text: {
height: 40,
margin: 0,
marginRight: 7,
paddingLeft: 10,
},
borderTop: {
borderColor: '#edeeef',
borderTopWidth: 0.5,
},
button: {
height: 50,
backgroundColor: '#48BBEC',
borderColor: '#48BBEC',
alignSelf: 'stretch',
margin: 10,
justifyContent: 'center',
alignItems: 'center',
borderRadius: 5,
},
buttonText: {
color: '#fff',
fontSize: 18,
},
});
class EventForm extends Component {
state = {
title: null,
date: '',
showDatePicker: false
};
handleAddPress = () => {
saveEvent(this.state)
.then(() => this.props.navigation.goBack());
};
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,
backgroundColor: '#F3F3F3'
}}
>
<View style={styles.fieldContainer}>
<TextInput
style={styles.text}
placeholder="Event title"
spellCheck={false}
onChangeText={this.handleChangeTitle}
value={this.state.title}
/>
<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
style={styles.button}
onPress={this.handleAddPress}
>
<Text style={styles.buttonText}>Add</Text>
</TouchableHighlight>
</View>
);
}
}
export default EventForm;