-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
210 lines (156 loc) · 12 KB
/
App.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import {SafeAreaView, StatusBar, Text, TouchableOpacity, View} from "react-native";
import Feather from 'react-native-vector-icons/Feather';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import Entypo from 'react-native-vector-icons/Entypo';
import FontAwesome5 from "react-native-vector-icons/FontAwesome5";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
import {useState} from "react";
export default function App(){
const [result, setResult] = useState('')
let [math, setMath] = useState('')
const [braket, setBraket] = useState(true)
const [alert, setAlert] = useState('')
const [mode, setMode] = useState(true)
const color = {
background: mode? '#181b2f' : '#f3f3f3',
colorText: mode? '#a4b4c9' : '#292d41',
}
function handleAC(){
setMath('')
setResult('')
}
function handleBraket(){
const brakets = braket? '(' : ')'
if ( math[math.length - 1] == '+' || math[math.length - 1] == '-' || math[math.length - 1] == '*' || math[math.length - 1] == '/'){
if (math.lastIndexOf("(") < 1){
setMath(math += '(')
} else {
setMath(math += '(')
}
}
if (math.lastIndexOf("(") > 1){
if ( Number.isInteger(parseInt(math[math.length - 1])) ){
if (math.lastIndexOf(")") < 1){
setMath(math += ')')
}
}
}
}
function handleResult(){
try {
if (math.length < 20){
setResult(eval(math))
} else {
setAlert('Limit Reached')
setTimeout(() => {
setAlert('')
}, 3000)
}
} catch(e){
setAlert(e.message)
setTimeout(() => {
setAlert('')
}, 3000)
}
}
return(
<SafeAreaView style={{backgroundColor: mode? '#0d0e1f' : '#ffffff', flex:1}}>
<StatusBar barStyle={mode? 'light-content' : 'dark-content'} backgroundColor={mode? '#0d0e1f' : '#ffffff'} />
<View style={{flex:1, paddingHorizontal:20}}>
<View style={{flex:1, paddingTop:30, alignItems:'center', justifyContent:'flex-start', }}>
<View style={{flexDirection:'row', width:120, backgroundColor: mode? '#151a2f' : '#e3e1e1' , paddingVertical:10, alignItems:'center', justifyContent:'space-evenly', borderRadius:20, }}>
<TouchableOpacity onPress={() => setMode(false)}>
<Feather name="sun" size={22} color={mode ? '#54557c' : '#000'} />
</TouchableOpacity>
<TouchableOpacity onPress={() => setMode(true)} >
<MaterialIcons name="nightlight-round" size={22} color={mode ? '#ffffff' : '#bbbbbb'} />
</TouchableOpacity>
</View>
<Text style={{color:'green', paddingTop:20, fontSize:20, fontWeight:'bold'}}>{alert}</Text>
</View>
<View style={{justifyContent:'flex-end', flex:2, }}>
<View style={{alignItems:'flex-end', paddingTop:30, paddingBottom:20, justifyContent:'flex-end'}}>
<Text style={{color:'#7a9ba6', fontSize:25, fontWeight:'bold'}}>{math}</Text>
</View>
<View style={{alignItems:'flex-end', paddingBottom:10, justifyContent:'flex-end'}}>
<Text style={{color:mode? '#d7d3d3' : '#000000', fontSize:55, fontWeight:'bold', }}>{result}</Text>
</View>
</View>
<View style={{flex:6, justifyContent:'flex-end', }}>
<View style={{backgroundColor: mode? '#17192d' : '#eeeeee', borderTopRightRadius:30, borderTopLeftRadius:30, marginHorizontal:-20, padding:20, marginTop:10, justifyContent:'flex-end'}}>
<View style={{flexDirection:'row', alignItems:'center', justifyContent:'space-around', marginVertical:10}}>
<TouchableOpacity onPress={handleAC} style={{backgroundColor: color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:20, }}>AC</Text>
</TouchableOpacity>
<TouchableOpacity onPress={handleBraket} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>( )</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '%')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>%</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '/')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Feather name="divide" size={25} color={color.colorText} />
</TouchableOpacity>
</View>
<View style={{flexDirection:'row', alignItems:'center', justifyContent:'space-around', marginVertical:10}}>
<TouchableOpacity onPress={() => setMath(math += '7')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>7</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '8')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>8</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '9')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>9</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '*')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Feather name="x" size={25} color={color.colorText} />
</TouchableOpacity>
</View>
<View style={{flexDirection:'row', alignItems:'center', justifyContent:'space-around', marginVertical:10}}>
<TouchableOpacity onPress={() => setMath(math += '4')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>4</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '5')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>5</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '6')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>6</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '-')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Feather name="minus" size={25} color={color.colorText} />
</TouchableOpacity>
</View>
<View style={{flexDirection:'row', alignItems:'center', justifyContent:'space-around', marginVertical:10}}>
<TouchableOpacity onPress={() => setMath(math += '1')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>1</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '2')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>2</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '3')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>3</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '+')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Feather name="plus" size={25} color={color.colorText} />
</TouchableOpacity>
</View>
<View style={{flexDirection:'row', alignItems:'center', justifyContent:'space-around', marginVertical:10}}>
<TouchableOpacity onPress={() => setMath(math.slice(0, -1)) } style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Feather name={'delete'} size={25} color={color.colorText} />
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += 0)} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Text style={{color:color.colorText, fontWeight:'bold', fontSize:25, }}>0</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setMath(math += '.')} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<Entypo name={'dot-single'} size={25} color={color.colorText} />
</TouchableOpacity>
<TouchableOpacity onPress={handleResult} style={{backgroundColor:color.background, borderRadius:10, height:65, width:65, alignItems:'center', justifyContent:'center' }}>
<MaterialCommunityIcons name="equal" size={25} color={color.colorText} />
</TouchableOpacity>
</View>
</View>
</View>
</View>
</SafeAreaView>
)
}