-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
203 lines (177 loc) · 5.15 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
import { StatusBar } from 'expo-status-bar';
import React, {useState} from 'react';
import { StyleSheet, View, Switch, Text, TextInput, Button } from 'react-native';
export default function App() {
const [feet, onChangeFeet] = React.useState();
const [inches, onChangeInches] = React.useState();
const [pounds, onChangePounds] = React.useState();
const [kilogram, onChangeKg] = React.useState();
const [centimeter, onChangeCm] = React.useState();
const [myText, setMyText] = React.useState();
//For Standard Calulations
const handlePress = ()=> {
var parsedFeet = parseInt(feet)
var parsedInches = parseInt(inches)
var meter = (parsedFeet * 0.3048) + (parsedInches * 0.0254)
var squaredMeter = meter * meter
var kgs = parseInt(pounds) * 0.45359237
var BMI = (kgs/squaredMeter)
var roundedBmi = Math.round(BMI)
if (roundedBmi < 18.5) {
setMyText("Your BMI is " + roundedBmi + " You Are Underweight")
} else if (roundedBmi > 18.5 && roundedBmi < 25) {
setMyText("Your BMI is " + roundedBmi + " Your Weight is Normal")
console.log("Normal Weight")
} else if (roundedBmi >= 25 && roundedBmi < 30) {
setMyText("Your BMI is " + roundedBmi + " You Are Over Weight")
} else {
setMyText("Your BMI is " + roundedBmi + " You Are Obeseve")
}
}
//For Metric Calulations
const handlePressMetric = ()=> {
var kgs = parseInt(kilogram)
var cm = parseInt(centimeter)
var meter = cm * 0.01
var squaredMeter = meter * meter
var BMI = (kgs/squaredMeter)
var roundedBmi = Math.round(BMI)
if (roundedBmi < 18.5) {
setMyText("Your BMI is " + roundedBmi + " You Are Underweight")
} else if (roundedBmi > 18.5 && roundedBmi < 25) {
setMyText("Your BMI is " + roundedBmi + " Your Weight is Normal")
console.log("Normal Weight")
} else if (roundedBmi >= 25 && roundedBmi < 30) {
setMyText("Your BMI is " + roundedBmi + " You Are Over Weight")
} else {
setMyText("Your BMI is " + roundedBmi + " You Are Obeseve")
}
}
const [isEnabled, setIsEnabled] = useState(false);
const toggleSwitch = () => {
onChangeFeet("")
onChangeInches("")
onChangePounds("")
onChangeKg("")
onChangeCm("")
setMyText("")
setIsEnabled(previousState => !previousState)
};
return (
<View style={styles.container}>
{headerView()}
{isEnabled == false? (
standardSystem()
) : (
metricSystem())
}
</View>
);
function metricSystem() {
return <View style={styles.container}>
<Text>Metric System</Text>
<Text>Enter Your Height Centimeter</Text>
<View style={styles.container_row}>
<TextInput
style={styles.input}
onChangeText={onChangeCm}
placeholder="Centimeter"
value={centimeter} />
</View>
<Text>Enter Your Weight in kilogram</Text>
<TextInput
style={styles.input}
onChangeText={onChangeKg}
placeholder="Kilogram"
value={kilogram} />
<Button
onPress={handlePressMetric}
title="Compute BMI"
color="#841584"
accessibilityLabel="BMI" />
<Text style={styles.normalText}>
{myText}
</Text>
</View>;
}
function standardSystem() {
return <View style={styles.container}>
<Text>Standard System</Text>
<Text>Enter Your Height in Feet and Inches</Text>
<View style={styles.container_row}>
<TextInput
style={styles.input}
onChangeText={onChangeFeet}
placeholder="Feet"
value={feet} />
<TextInput
style={styles.input}
onChangeText={onChangeInches}
placeholder="Inches"
value={inches} />
</View>
<Text>Enter Your Weight in Pounds</Text>
<TextInput
style={styles.input}
onChangeText={onChangePounds}
placeholder="Pounds"
value={pounds} />
<Button
onPress={handlePress}
title="Compute BMI"
color="#841584"
accessibilityLabel="BMI" />
<Text style={styles.normalText}>
{myText}
</Text>
</View>;
}
function headerView() {
return <View style={styles.container_row}>
<Text style={styles.titleText}>
Standard System
</Text>
<Switch
trackColor={{ false: "#767577", true: "#81b0ff" }}
thumbColor={isEnabled ? "#f5dd4b" : "#f4f3f4"}
ios_backgroundColor="#3e3e3e"
onValueChange={toggleSwitch}
value={isEnabled} />
<Text style={styles.titleText}>
Metric System
</Text>
</View>;
}
}
const styles = StyleSheet.create({
container_row: {
marginTop: 10,
flexDirection : 'row',
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
container: {
flex: 1,
marginTop: 30,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
titleText : {
padding: 10,
fontSize: 17,
},
normalText : {
padding: 10,
marginTop: 20,
fontSize: 15,
},
input: {
height: 40,
width:150,
margin: 12,
borderWidth: 1,
padding: 10,
},
});