-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
67 lines (60 loc) · 1.67 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
import { StatusBar } from 'expo-status-bar'
import React from 'react'
import { StyleSheet, Text, View, Button, TextInput } from 'react-native'
export default function App() {
const [result, setResult] = React.useState(0)
const [num1, setNum1] = React.useState('')
const [num2, setNum2] = React.useState('')
const addition = () => {
const sum = parseFloat(num1) + parseFloat(num2)
setResult(sum)
setNum1('')
setNum2('')
}
const subtraction = () => {
const sub = parseFloat(num1) - parseFloat(num2)
setResult(sub)
setNum1('')
setNum2('')
}
return (
<View style={styles.container}>
<View style={styles.container}>
<Text style={{ fontSize: 18 }}>Result = {result}</Text>
<TextInput
style={{ width: 200, borderColor: 'gray', borderWidth: 1 }}
value={num1}
onChangeText={(text) => setNum1(text)}
keyboardType="numeric"
/>
<TextInput
style={{ width: 200, borderColor: 'gray', borderWidth: 1 }}
value={num2}
onChangeText={(text) => setNum2(text)}
keyboardType="numeric"
/>
</View>
<View style={styles.buttonContainer}>
<Button title=" + " onPress={addition} />
<Button title=" - " onPress={subtraction} />
<StatusBar style="auto" />
</View>
</View>
)
}
const styles = StyleSheet.create({
container: {
flex: 2,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
buttonContainer: {
flex: 5,
width: 80,
flexDirection: 'row',
backgroundColor: '#fff',
alignItems: 'flex-start',
justifyContent: 'space-around',
},
})