-
Notifications
You must be signed in to change notification settings - Fork 0
/
Items.js
183 lines (131 loc) · 5.3 KB
/
Items.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// import React from 'react';
// import { Text, View, TextInput, FlatList, Button } from 'react-native';
// import Cards from '../../components/Cards';
// import Login from '../Login/LoginScreen';
// import styles from './StyleItems';
// export default class Items extends React.Component {
// state={
// id: 1,
// description:"",
// amount:0,
// total:0,
// isVisible: true,
// }
// DATA = [];
// handleSubmit = () => {
// this.setState({
// id: this.state.id + 1,
// description: this.state.description,
// amount: this.state.amount,
// total: Number(this.state.total) + Number(this.state.amount)
// })
// console.log(this.state);
// this.DATA.push({id:1 + this.state.id,description:this.state.description, amount: this.state.amount})
// }
// render(){
// const Item = ({ desc, amount }) => (
// <Cards desc={desc} amount={amount} />
// );
// const renderItem = ({ item }) => (
// <Item desc={item.description} amount={item.amount}/>
// );
// return (
// <View style={styles.container}>
// <Text style={styles.logo}>Total Items: {this.DATA.length} </Text>
// <Text style={styles.logo}>Total Amount: {this.state.total} </Text>
// <View style={styles.card}>
// <View style={styles.inputView} >
// <TextInput
// style={styles.inputText}
// placeholder="Item Description..."
// placeholderTextColor="#003f5c"
// onChangeText={text => this.setState({description:text})}
// />
// </View>
// <View style={styles.inputView} >
// <TextInput
// keyboardType='numeric'
// style={styles.inputText}
// placeholder="Amount..."
// placeholderTextColor="#003f5c"
// onChangeText={text => this.setState({amount:text})}
// />
// </View>
// <Button title="Submit" onPress={this.handleSubmit}/>
// </View>
// <FlatList
// data={this.DATA}
// renderItem={renderItem}
// keyExtractor={item => item.id}
// />
// </View>
// )
// }
// }
import React,{useEffect, useState} from 'react';
import { Text, View, TextInput, FlatList, Button, Alert } from 'react-native';
import Cards from '../../components/Cards';
import styles from './StyleItems';
function Items()
{
//const [id, setid] = useState(1);
const[description,setdescription] = useState("");
const [total,settotal]= useState(0);
const[amount,setamount] = useState(0);
const [ isVisible,setisVisible]= useState(true)
const [ items,setitems]= useState()
let id=1;
const DATA=[];
const handleSubmit=()=>
{
// setid((pr)=>pr + 1),
// setdescription(description),
// setamount(amount),
// settotal(+(total) + +(amount))
// DATA.push({id:id,description:description,amount:amount})
// Alert.alert("DATA")
setitems({id:Math.random(),description:description,amount:amount})
DATA.push(items);
console.log(DATA);
console.log(DATA.length);
}
let Item = ({ desc, amount }) => (
<Cards desc={desc} amount={amount} />
);
const renderItem = ({item}) => (
<Item desc={item.description} amount={item.amount}/>
);
return (
<View style={styles.container}>
<Text style={styles.logo}>Total Items: {id} </Text>
<Text style={styles.logo}>Total Amount: {total} </Text>
<View style={styles.card}>
<View style={styles.inputView} >
<TextInput
style={styles.inputText}
placeholder="Item Description..."
placeholderTextColor="#003f5c"
onChangeText={text => setdescription(text)}
/>
</View>
<View style={styles.inputView} >
<TextInput
keyboardType='numeric'
style={styles.inputText}
placeholder="Amount..."
placeholderTextColor="#003f5c"
onChangeText={(text) => setamount(text)}
/>
</View>
<Button title="Submit" onPress={handleSubmit}/>
</View>
<View><Text>{DATA.map(Item=()=>(<Cards />))}</Text></View>
{/* <FlatList
data={DATA}
renderItem={renderItem}
keyExtractor={item => item.id}
/> */}
</View>
)
}
export default Items;