-
Notifications
You must be signed in to change notification settings - Fork 0
/
DetailsScreen.js
100 lines (88 loc) · 2.09 KB
/
DetailsScreen.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
import React, { Component } from 'react';
import { AsyncStorage, FlatList, StyleSheet, Text, View,Button, TextInput,TouchableHighlight,Alert,CheckBox} from 'react-native';
import {createStackNavigator } from 'react-navigation';
var i = 1;
class UselessTextInput extends Component {
render() {
return (
<TextInput
{...this.props} // Inherit any props passed to it; e.g., multiline, numberOfLines below
editable = {true}
maxLength = {35}
/>
);
}
}
export default class DetailsScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
text: 'New Item',
data: [],
};
}
render() {
return (
<View style={styles.container}>
<View style={{marginTop: 20, height: 50, backgroundColor: 'powderblue', flex: 0.05, flexDirection: 'row'} }>
<Button
onPress={() => {this.setState((prevState, props) => {
var textBox = prevState.text
if (textBox === 'New Item') {
textBox = 'New Item' + String(i)
i = i+1;
}
if (Boolean(textBox)) {
return {data: [{key: textBox, done : false}].concat(prevState.data) };
}
})}}
title="+"
color="black"
/>
<UselessTextInput
multiline = {true}
numberOfLines = {1}
onChangeText={(text) => this.setState({text})}
value={this.state.text}
/>
</View>
<FlatList
data= {this.state.data}
renderItem={({item}) =>
<Button style = {item.done ? styles.done : styles.item} onPress={() =>
{
item.done = true;
this.setState({data: this.state.data.filter(function(item) {
return !(item.done)
})});
}
}
title={item.key}
color="black"
/>
}
keyExtractor={(item, index) => index.toString()}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 22
},
item: {
alignContent: 'flex-start',
padding: 10,
fontSize: 18,
height: 44,
},
done : {
alignContent: 'flex-start',
padding: 10,
fontSize: 18,
height: 44,
color: 'red',
}
})