forked from cmsapp/todont
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TDEdit.js
135 lines (122 loc) · 3.17 KB
/
TDEdit.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
'use strict';
var React = require('react-native');
var commonStyles = require('./CommonStyles');
var colors = require('./colors');
var TDSeverity = require('./TDSeverity');
var TDLabel = require('./TDLabel');
var TDButton = require('./TDButton');
var TDSwipable = require('./TDSwipable');
var {
View,
TouchableHighlight,
Text,
StyleSheet,
TextInput,
SwitchIOS,
SliderIOS,
PanResponder,
LayoutAnimation
} = React;
class TDEdit extends React.Component {
constructor(props) {
super();
this.onUpdate = this.onUpdate.bind(this);
this.onDelete = this.onDelete.bind(this);
var item = props.item;
this.state = item ? {
description: item.description,
doneItBefore: item.doneItBefore,
severity: item.severity
} : {};
}
onUpdate() {
this.props.update(this.state, this.props.id);
}
onDelete() {
this.props.delete(this.props.id);
}
containerTouched(event) {
this.refs.textInput.blur();
return false;
}
render() {
return (
<View style={styles.container}
onStartShouldSetResponder={this.containerTouched.bind(this)}>
<TDLabel value="Thing not to do"/>
<TextInput
ref='textInput'
value={this.state.description}
onChangeText={description => this.setState({description})}
style={styles.textbox}
/>
<TDLabel value="Done it before?"/>
<SwitchIOS
value={this.state.doneItBefore}
onValueChange={doneItBefore => {
LayoutAnimation.easeInEaseOut();
this.setState({doneItBefore});
}}
style={styles.switch}
onTintColor={colors.primary}
/>
{this.state.doneItBefore ?
<TDSeverity
value={this.state.severity}
onValueChange={severity => this.setState({severity})}
/> : <View/>
}
{!this.props.item ?
<TDButton containerStyle={{marginLeft: 0, marginRight: 0}} text="Save" onPress={this.onUpdate}/>
:
<View style={{flex: 0, paddingTop: 5, flexDirection: 'row'}}>
<TDButton containerStyle={{flex: 1, marginLeft: 0}} text="Save" onPress={this.onUpdate}/>
<TDButton containerStyle={{
flex: 1,
marginRight: 0,
backgroundColor: '#ED1C23',
borderColor: '#ED1C23'
}} text="Delete" underlayColor={'rgba(237, 28, 35, 0.75)'} onPress={this.onDelete}
/>
</View>
}
<TDSwipable
onBackSwipe={this.props.back}
onUpSwipe={this.props.previous}
onDownSwipe={this.props.next}
style={styles.backSwipe}
/>
</View>
)
}
}
var styles = StyleSheet.create({
container: {
marginTop: 70,
flex: 1,
padding: 10,
backgroundColor: '#ffffff',
},
textbox: {
color: '#000000',
fontSize: 17,
height: 36,
padding: 7,
borderRadius: 4,
borderColor: '#cccccc',
borderWidth: 1,
marginBottom: 5
},
switch: {
marginBottom: 10
},
saveButton: {
borderColor: '#48BBEC',
borderWidth: 1,
borderRadius: 8,
},
backSwipe: {
flex:1
}
});
module.exports = TDEdit;