-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem.js
95 lines (85 loc) · 2.05 KB
/
item.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
import React, { Component } from 'react'
import { View, Text, StyleSheet, Switch, TouchableOpacity, TextInput } from "react-native";
class Item extends Component {
// Component for creating list of to do task
render() {
const { complete } = this.props;
const textComponent = (
<View style={styles.textWrap}>
<Text style={[styles.text, complete && styles.complete]}>{this.props.text}</Text>
</View>
)
const updateComponent = (
<TouchableOpacity onPress={() => this.props.onToggleEdit(true)}>
<Text style={styles.update}>Update</Text>
</TouchableOpacity>
)
const removeButton = (
<TouchableOpacity onPress={this.props.onRemove}>
<Text style={styles.destroy}>Delete</Text>
</TouchableOpacity>
)
const editingComponet = (
<View style={styles.textWrap}>
<TextInput
onChangeText={this.props.onUpdate}
autoFocus
value={this.props.text}
style={styles.input}
/>
</View>
)
return (
<View style={styles.container}>
<Switch
value={complete}
onValueChange={this.props.onComplete}
/>
{this.props.editing ? editingComponet : textComponent}
{this.props.editing ? updateComponent : removeButton}
</View >
)
}
}
const styles = StyleSheet.create({
container: {
padding: 10,
flexDirection: "row",
alignItems: "flex-start",
justifyContent: "space-between"
},
textWrap: {
//flex: 1,
marginHorizontal: 10,
},
text: {
fontSize: 24,
color: "#4d4d4d",
},
complete: {
textDecorationLine: "line-through"
}, destroy: {
fontSize: 10,
color: '#fff',
padding: 5,
backgroundColor: "#dc3545",
borderColor: "#dc3545",
borderWidth: 1
},
update: {
fontSize: 10,
color: '#fff',
padding: 5,
borderColor: "#28a745",
backgroundColor: "#28a745",
borderWidth: 1
},
input: {
height: 100,
flex: 1,
fontSize: 24,
padding: 0,
color: "#4d4d4d"
}
})
export default Item;