-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp3.js
More file actions
90 lines (88 loc) · 2.18 KB
/
App3.js
File metadata and controls
90 lines (88 loc) · 2.18 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
import { StatusBar } from "expo-status-bar";
import {
StyleSheet,
Text,
View,
TouchableOpacity,
TouchableHighlight,
TouchableWithoutFeedback,
Pressable,
TextInput,
} from "react-native";
import { theme } from "./colors";
import { useState } from "react";
export default function App() {
const [working, setWorking] = useState(true);
const [text, setText] = useState("");
const [toDos, setToDos] = useState({});
const travel = () => setWorking(false);
const work = () => setWorking(true);
const onChangeText = (payload) => setText(payload);
const addToDo = () => {
if (text === " ") {
return;
}
const newToDOs = Object.assign({}, toDos, {
[Date.now()]: { text, work: working },
});
setToDos(newToDOs);
setText("");
};
console.log(toDos);
return (
<View style={styles.container}>
<StatusBar style="auto" />
<View style={styles.Header}>
<TouchableOpacity onPress={work}>
<Text
style={{ ...styles.btnText, color: working ? "white" : theme.grey }}
>
Work
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={travel}>
<Text
style={{
...styles.btnText,
color: !working ? "white" : theme.grey,
}}
>
Travel
</Text>
</TouchableOpacity>
</View>
<TextInput
onSubmitEditing={addToDo}
returnKeyType="done"
onChangeText={onChangeText}
value={text}
placeholder={working ? "ADD a To DO" : "Where do yout want to go?"}
style={styles.input}
></TextInput>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: theme.bg,
paddingHorizontal: 20,
},
Header: {
justifyContent: "space-between",
flexDirection: "row",
marginTop: 100,
},
btnText: {
fontSize: 38,
fontWeight: "600",
},
input: {
backgroundColor: "white",
paddingVertical: 15,
paddingHorizontal: 20,
borderRadius: 30,
marginTop: 20,
fontSize: 18,
},
});