-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.js
126 lines (103 loc) · 2.64 KB
/
Main.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
import React from 'react';
import { Text, View, Button, TouchableOpacity, StyleSheet, TextInput, TouchableHighlight } from 'react-native';
import { addPerson ,setCount} from './actions';
// import PersonList from './PersonList'
import { connect } from 'react-redux';
class Main extends React.Component {
static navigationOptions = {
title: 'Peaple'
};
constructor(props) {
super(props);
}
state = {
personName: '',couterValue:''
}
addPersonValue = () => {
if (this.state.personName === '') return;
this.props.addPerson({name:this.state.personName});
this.setState({ personName: '' });
}
setCounterValue = () => {
if (this.state.couterValue === '') return;
this.props.setCount(this.state.couterValue);
this.setState({ couterValue: '' });
}
updatePerson = (personName) => {
this.setState({ personName })
}
updateCounter = (couterValue) => {
this.setState({ couterValue })
}
render() {
return (
<View style={styles.container}>
<TextInput
onChangeText={text => this.updateCounter(text)}
style={styles.input}
value={this.state.couterValue}
keyboardType={'numeric'}
placeholder="Counter"
/>
<TouchableHighlight
underlayColor="#ffa012"
style={styles.button}
onPress={() =>this.setCounterValue()}
>
<Text style={styles.buttonText}>Set Counter</Text>
</TouchableHighlight>
<TextInput
onChangeText={text => this.updatePerson(text)}
style={styles.input}
value={this.state.personName}
placeholder="Name"
/>
<TouchableHighlight
underlayColor="#ffa012"
style={styles.button}
onPress={() =>this.addPersonValue()}
>
<Text style={styles.buttonText}>Add Person</Text>
</TouchableHighlight>
<TouchableOpacity>
<Button
onPress={() => this.props.navigation.navigate('Screen1')}
title="Go to Next Screen"
/>
</TouchableOpacity>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
marginTop: 20,
padding: 20,
},
input: {
backgroundColor: '#e4e4e4',
height: 55,
borderRadius: 3,
padding: 5,
marginTop: 12,
},
button: {
backgroundColor: '#ff9900',
height: 40,
justifyContent: 'center',
alignItems: 'center',
marginTop: 12,
borderRadius: 3,
},
buttonText: {
color: 'white',
}
});
const mapDispatchToProps = {
addPerson,
setCount
};
export default sts = connect(
null,
mapDispatchToProps,
)(Main)