-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathCalculator.js
116 lines (106 loc) · 3.54 KB
/
Calculator.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
import React, { Component } from 'react';
import { View, Text, TextInput, StyleSheet } from 'react-native';
import {connect} from 'react-redux';
import ActionCreator from '../actions';
class Calculator extends Component {
constructor(props, context) {
super(props, context);
}
render() {
return (
<View style={calculatorStyles.container}>
<TextInput
style={ calculatorStyles.input }
keyboardType={'number-pad'}
maxLength={1}
placeholder={'0'}
onChangeText={(text) => {
this.setState({text});
var numberAsInt = 0
if (text !== '') {
numberAsInt = parseInt(text, 10);
}
console.log(numberAsInt);
this.props.updateFirst(numberAsInt);
}}
// onSubmitEditing = {() => { this.props.updateFirst(1); }}
// placeholderTextColor = {'red'}
></TextInput>
<View style={calculatorStyles.view}>
<Text
s3yle={ calculatorStyles.text }
>+</Text>
</View>
<TextInput
style={ calculatorStyles.input }
keyboardType={'number-pad'}
maxLength={1}
placeholder={'0'}
onChangeText={(text) => {
this.setState({text});
var numberAsInt = 0
if (text !== '') {
numberAsInt = parseInt(text, 10);
}
console.log(numberAsInt);
this.props.updateSecond(numberAsInt);
}}
></TextInput>
<View style={ calculatorStyles.view }>
<Text
style={ calculatorStyles.text }
>=</Text>
</View>
<View style={ calculatorStyles.view }>
<Text
style={ calculatorStyles.text }
>{this.props.result}</Text>
</View>
</View>
);
}
}
function mapStateToProps(state) {
return {
result: state.calculator.result,
first: state.calculator.sumInfo.first,
second: state.calculator.sumInfo.second
};
}
function mapDispatchToProps(dispatch) {
return {
updateFirst:(num) => {
dispatch(ActionCreator.updateSumValueFirst(num));
},
updateSecond:(num) => {
dispatch(ActionCreator.updateSumValueSecond(num));
}
};
}
var FONT_CALCULATOR_DEFULT = 18;
const calculatorStyles = StyleSheet.create({
container: {
flexDirection:'row',
justifyContent: 'center',
marginTop:50,
backgroundColor:'white',
},
input: {
width: 50 ,
height: 50,
backgroundColor:'transparent',
fontSize: FONT_CALCULATOR_DEFULT,
justifyContent: 'center',
},
text: {
fontSize: FONT_CALCULATOR_DEFULT,
backgroundColor:'transparent',
},
view: {
width: 50 ,
height: 50,
backgroundColor:'transparent',
justifyContent: 'center',
},
});
export default connect(mapStateToProps, mapDispatchToProps)(Calculator);