-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
81 lines (74 loc) · 2.55 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
import type { Node } from 'react';
import React, { useState } from 'react';
import {
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
useColorScheme,
View
} from 'react-native';
import { Colors } from 'react-native/Libraries/NewAppScreen';
import Button from './src/components/Button';
import Display from './src/components/Display';
const App: () => Node = () => {
const isDarkMode = useColorScheme() === 'dark';
const [displayVal, setDisplayVal] = useState(0);
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
const addDigit = n => {
const newVal = displayVal === 0 ? n : displayVal + n;
setDisplayVal(newVal);
};
const clearMemory = () => {
setDisplayVal(0);
};
const setOperation = operation => {};
return (
<SafeAreaView style={backgroundStyle}>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={backgroundStyle}>
<View style={styles.container}>
<Display value={displayVal} />
<View style={styles.buttons}>
<Button label="AC" triple onClick={() => clearMemory()} />
<Button label="/" operation onClick={() => setOperation('/')} />
<Button label="7" onClick={() => addDigit('7')} />
<Button label="8" onClick={() => addDigit('8')} />
<Button label="9" onClick={() => addDigit('9')} />
<Button label="*" operation onClick={() => setOperation('*')} />
<Button label="4" onClick={() => addDigit('4')} />
<Button label="5" onClick={() => addDigit('5')} />
<Button label="6" onClick={() => addDigit('6')} />
<Button label="-" operation onClick={() => setOperation('-')} />
<Button label="1" onClick={() => addDigit('1')} />
<Button label="2" onClick={() => addDigit('2')} />
<Button label="3" onClick={() => addDigit('3')} />
<Button label="+" operation onClick={() => setOperation('+')} />
<Button label="0" onClick={() => addDigit('0')} />
<Button label="." onClick={() => addDigit('.')} />
<Button
label="="
operation
onClick={() => setOperation('=')}
double
/>
</View>
</View>
</ScrollView>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
buttons: {
flexDirection: 'row',
flexWrap: 'wrap',
},
});
export default App;