A fonctional ToDo app, Features comming soon
This commit is contained in:
parent
f90472a9a1
commit
d595ea1265
117
App.js
117
App.js
@ -1,11 +1,78 @@
|
||||
import { StatusBar } from 'expo-status-bar';
|
||||
import { StyleSheet, Text, View } from 'react-native';
|
||||
import { StatusBar } from "expo-status-bar";
|
||||
import {
|
||||
KeyboardAvoidingView,
|
||||
Platform,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TextInput,
|
||||
View,
|
||||
TouchableOpacity,
|
||||
Keyboard,
|
||||
ScrollView,
|
||||
} from "react-native";
|
||||
import React, { useState } from "react";
|
||||
import Task from "./components/Task";
|
||||
|
||||
export default function App() {
|
||||
const [task, setTask] = useState();
|
||||
const [taskItems, setTaskItems] = useState([]);
|
||||
|
||||
const handleAddTask = () => {
|
||||
Keyboard.dismiss();
|
||||
setTaskItems([...taskItems, task]);
|
||||
setTask(null);
|
||||
};
|
||||
|
||||
const completeTask = (index) => {
|
||||
let itemsCopy = [...taskItems];
|
||||
itemsCopy.splice(index, 1);
|
||||
setTaskItems(itemsCopy);
|
||||
};
|
||||
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text>Open up App.js to start working on your app!</Text>
|
||||
<StatusBar style="auto" />
|
||||
<ScrollView
|
||||
contentContainerStyle={{
|
||||
flexGrow: 1,
|
||||
}}
|
||||
keyboardShouldPersistTaps="handled"
|
||||
>
|
||||
{/* Today's Tasks */}
|
||||
<View style={styles.tasksWrapper}>
|
||||
<Text style={styles.sectionTitle}>Today's tasks</Text>
|
||||
<View style={styles.items}>
|
||||
{/* This is where the tasks will go! */}
|
||||
{taskItems.map((item, index) => {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
key={index}
|
||||
onPress={() => completeTask(index)}
|
||||
>
|
||||
<Task text={item} />
|
||||
</TouchableOpacity>
|
||||
);
|
||||
})}
|
||||
</View>
|
||||
</View>
|
||||
</ScrollView>
|
||||
|
||||
{/* Write a task */}
|
||||
<KeyboardAvoidingView
|
||||
behavior={Platform.OS == "ios" ? "padding" : "height"}
|
||||
style={styles.writeTaskWrapper}
|
||||
>
|
||||
<TextInput
|
||||
style={styles.input}
|
||||
placeholder={"Write a task"}
|
||||
value={task}
|
||||
onChangeText={(text) => setTask(text)}
|
||||
/>
|
||||
<TouchableOpacity onPress={() => handleAddTask()}>
|
||||
<View style={styles.addWrapper}>
|
||||
<Text style={styles.addText}>+</Text>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
</KeyboardAvoidingView>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
@ -13,8 +80,44 @@ export default function App() {
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
||||
flex: 1,
|
||||
backgroundColor: '#fff',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
backgroundColor: "#E8EAED",
|
||||
},
|
||||
tasksWrapper: {
|
||||
paddingTop: 80,
|
||||
paddingHorizontal: 20,
|
||||
},
|
||||
sectionTitle: {
|
||||
fontSize: 24,
|
||||
fontWeight: "bold",
|
||||
},
|
||||
items: {
|
||||
marginTop: 30,
|
||||
},
|
||||
writeTaskWrapper: {
|
||||
position: "absolute",
|
||||
bottom: 60,
|
||||
width: "100%",
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-around",
|
||||
},
|
||||
input: {
|
||||
paddingVertical: 15,
|
||||
paddingHorizontal: 15,
|
||||
backgroundColor: "#FFF",
|
||||
borderRadius: 60,
|
||||
borderColor: "#C0C0C0",
|
||||
borderWidth: 1,
|
||||
width: 250,
|
||||
},
|
||||
addWrapper: {
|
||||
width: 60,
|
||||
height: 60,
|
||||
backgroundColor: "#FFF",
|
||||
borderRadius: 60,
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
borderColor: "#C0C0C0",
|
||||
borderWidth: 1,
|
||||
},
|
||||
});
|
||||
|
||||
51
components/Task.js
Normal file
51
components/Task.js
Normal file
@ -0,0 +1,51 @@
|
||||
import React from "react";
|
||||
import { View, Text, StyleSheet } from "react-native";
|
||||
|
||||
const Task = (props) => {
|
||||
return (
|
||||
<View style={styles.item}>
|
||||
<View style={styles.itemLeft}>
|
||||
<View style={styles.square}></View>
|
||||
<Text style={styles.itemText}>{props.text}</Text>
|
||||
</View>
|
||||
<View style={styles.circular}></View>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
item: {
|
||||
backgroundColor: "#FFF",
|
||||
padding: 15,
|
||||
borderRadius: 10,
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
marginBottom: 20,
|
||||
},
|
||||
itemLeft: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
flexWrap: "wrap",
|
||||
},
|
||||
square: {
|
||||
width: 24,
|
||||
height: 24,
|
||||
backgroundColor: "#55BCF6",
|
||||
opacity: 0.4,
|
||||
borderRadius: 5,
|
||||
marginRight: 15,
|
||||
},
|
||||
itemText: {
|
||||
maxWidth: "80%",
|
||||
},
|
||||
circular: {
|
||||
width: 12,
|
||||
height: 12,
|
||||
borderColor: "#55BCF6",
|
||||
borderWidth: 2,
|
||||
borderRadius: 5,
|
||||
},
|
||||
});
|
||||
|
||||
export default Task;
|
||||
2121
package-lock.json
generated
2121
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -16,7 +16,8 @@
|
||||
"react-native": "0.76.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.20.0"
|
||||
"@babel/core": "^7.20.0",
|
||||
"@react-native-community/cli": "latest"
|
||||
},
|
||||
"private": true
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user