-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
109 lines (99 loc) · 2.77 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
import React, { Component } from "react";
import { View, Text } from "react-native";
import Button from "./components/Button";
import Calc from "./components/Calc";
import Topview from "./components/Topview";
import Result from "./components/Result";
import styles from "./components/CSS";
import Title from "./components/Title";
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
expression: "",
result: "",
operator: false
};
this.handlePress = val => {
if (val === "+" || val === "-" || val === "/" || val === "*") {
this.setState({
operator: true
});
} else {
this.setState({
operator: false
});
}
if (this.state.operator === false) {
this.setState({
expression: this.state.expression + val
});
}
};
this.handleCalculate = e => {
this.setState({
result: eval(this.state.expression)
});
};
this.handleClean = e => {
this.setState({
expression: "",
result: ""
});
};
}
render() {
return (
<View style={styles.container}>
<Title />
<Topview
expression={this.state.expression}
currentOperator={this.state.currentOperator}
/>
<Button handlePress={this.handlePress}>7</Button>
<Button handlePress={this.handlePress}>8</Button>
<Button handlePress={this.handlePress}>9</Button>
<Button
handlePress={this.handlePress}
customCSS={styles.buttonOperation}
>
/
</Button>
<Button handlePress={this.handlePress}>4</Button>
<Button handlePress={this.handlePress}>5</Button>
<Button handlePress={this.handlePress}>6</Button>
<Button
handlePress={this.handlePress}
customCSS={styles.buttonOperation}
>
*
</Button>
<Button handlePress={this.handlePress}>1</Button>
<Button handlePress={this.handlePress}>2</Button>
<Button handlePress={this.handlePress}>3</Button>
<Button
handlePress={this.handlePress}
customCSS={styles.buttonOperation}
>
-
</Button>
<Button handlePress={this.handlePress}>0</Button>
<Button handlePress={this.handlePress}>.</Button>
<Calc
handlePress={this.handleCalculate}
customCSS={styles.buttonResult}
textCSS={styles.textWhite}
>
=
</Calc>
<Button
customCSS={styles.buttonOperation}
handlePress={this.handlePress}
>
+
</Button>
<Result handleClean={this.handleClean} result={this.state.result} />
</View>
);
}
}