-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppForm.js
116 lines (110 loc) · 2.63 KB
/
AppForm.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
import React, { useState, useEffect } from "react";
import { StatusBar } from "expo-status-bar";
import {
StyleSheet,
Text,
View,
TextInput,
TouchableOpacity,
} from "react-native";
import Database from "./Database";
export default function AppForm({ route, navigation }) {
const id = route.params ? route.params.id : undefined;
const [descricao, setDescricao] = useState("");
const [quantidade, setQuantidade] = useState("");
useEffect(() => {
if (!route.params) return;
setDescricao(route.params.descricao);
setQuantidade(route.params.quantidade.toString());
}, [route]);
function handleDescriptionChange(descricao) {
setDescricao(descricao);
}
function handleQuantityChange(quantidade) {
setQuantidade(quantidade);
}
async function handleButtonPress() {
const listItem = { descricao, quantidade: parseInt(quantidade) };
Database.saveItem(listItem, id).then((response) =>
navigation.navigate("AppList", listItem)
);
}
return (
<View style={styles.container}>
<Text style={styles.title}>Item para comprar</Text>
<View style={styles.inputContainer}>
<TextInput
style={styles.input}
onChangeText={handleDescriptionChange}
placeholder="O que está faltando em casa?"
clearButtonMode="always"
value={descricao}
/>
<TextInput
style={styles.input}
onChangeText={handleQuantityChange}
placeholder="Digite a quantidade"
keyboardType={"numeric"}
clearButtonMode="always"
value={quantidade.toString()}
/>
<TouchableOpacity style={styles.button} onPress={handleButtonPress}>
<View style={styles.buttonContainer}>
<Icon name="save" size={22} color="white" />
<Text style={styles.buttonText}>Salvar</Text>
</View>
</TouchableOpacity>
</View>
<StatusBar style="light" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#D93600",
alignItems: "center",
},
title: {
color: "#fff",
fontSize: 20,
fontWeight: "bold",
marginTop: 50,
},
inputContainer: {
flex: 1,
marginTop: 30,
width: "90%",
padding: 20,
borderTopLeftRadius: 10,
borderTopRightRadius: 10,
alignItems: "stretch",
backgroundColor: "#fff",
},
input: {
marginTop: 10,
height: 60,
backgroundColor: "#fff",
borderRadius: 10,
paddingHorizontal: 24,
fontSize: 16,
alignItems: "stretch",
},
button: {
marginTop: 10,
height: 60,
backgroundColor: "blue",
borderRadius: 10,
paddingHorizontal: 24,
fontSize: 16,
alignItems: "center",
justifyContent: "center",
elevation: 20,
shadowOpacity: 20,
shadowColor: "#ccc",
},
buttonText: {
color: "#fff",
fontWeight: "bold",
},
});