-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
155 lines (148 loc) · 4.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
import React, { useState } from 'react';
import { View, Text, TextInput, TouchableOpacity, StyleSheet } from 'react-native';
const IMCCalculator = () => {
const [nome, setNome] = useState('');
const [altura, setAltura] = useState('');
const [peso, setPeso] = useState('');
const [resultado, setResultado] = useState('');
const calcularIMC = () => {
if (nome !== '' && altura !== '' && peso !== '') {
const valorIMC = (peso / (altura * altura)).toFixed(1);
let classificacao = '';
if (valorIMC < 18.5) {
classificacao = 'abaixo do peso.';
} else if (valorIMC < 25) {
classificacao = 'com peso ideal. Parabéns!!!';
} else if (valorIMC < 30) {
classificacao = 'levemente acima do peso.';
} else if (valorIMC < 35) {
classificacao = 'com obesidade grau I.';
} else if (valorIMC < 40) {
classificacao = 'com obesidade grau II';
} else {
classificacao = 'com obesidade grau III. Cuidado!!';
}
setResultado(`${nome} seu IMC é ${valorIMC} e você está ${classificacao}`);
} else {
setResultado('Preencha todos os campos!!!');
}
};
return (
<View style={styles.container}>
<Text style={styles.title}>Calculadora - IMC</Text>
<View style={styles.input}>
<Text>Nome:</Text>
<TextInput
style={styles.textInput}
value={nome}
onChangeText={(text) => setNome(text)}
placeholder="Digite seu nome"
/>
</View>
<View style={styles.input}>
<Text>Altura:</Text>
<TextInput
style={styles.textInput}
value={altura}
onChangeText={(text) => setAltura(text)}
keyboardType="numeric"
placeholder="Digite sua altura"
/>
</View>
<View style={styles.input}>
<Text>Peso:</Text>
<TextInput
style={styles.textInput}
value={peso}
onChangeText={(text) => setPeso(text)}
keyboardType="numeric"
placeholder="Digite seu peso"
/>
</View>
<TouchableOpacity style={styles.button} onPress={calcularIMC}>
<Text style={{ color: '#fff' }}>Calcular</Text>
</TouchableOpacity>
<View style={styles.result}>
<Text style={{ color: '#fff' }}>{resultado}</Text>
</View>
<View style={styles.table}>
<Text style={styles.tableText}>Classificações:</Text>
<Text style={styles.tableText}>- Abaixo de 18.5: Abaixo do peso</Text>
<Text style={styles.tableText}>- 18.5 a 24.9: Peso normal</Text>
<Text style={styles.tableText}>- 25 a 29.9: Sobrepeso</Text>
<Text style={styles.tableText}>- 30 a 34.9: Obesidade grau 1</Text>
<Text style={styles.tableText}>- 35 a 39.9: Obesidade grau 2</Text>
<Text style={styles.tableText}>- Acima de 40: Obesidade grau 3</Text>
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#6600cc',
paddingHorizontal: 20,
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 20,
marginTop: 40,
color: '#fff',
},
input: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 10,
},
textInput: {
flex: 1,
height: 40,
borderWidth: 1,
borderRadius: 5,
paddingHorizontal: 10,
backgroundColor: 'black',
marginLeft: 10,
},
button: {
backgroundColor: 'black',
width: 200,
height: 40,
justifyContent: 'center',
alignItems: 'center',
borderRadius: 5,
marginBottom: 20,
},
result: {
width: '100%',
height: 150,
backgroundColor: 'black',
borderRadius: 5,
justifyContent: 'center',
alignItems: 'center',
marginTop: 20,
padding: 20,
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 4,
elevation: 5,
},
table: {
marginTop: 20,
padding: 10,
backgroundColor: 'black',
borderRadius: 5,
alignItems: 'center',
},
tableText: {
color: '#fff',
marginBottom: 5,
},
});
export default IMCCalculator;