-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathSwitchComponent.js
126 lines (105 loc) · 2.63 KB
/
SwitchComponent.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
'use strict';
import React from 'react';
let { View, StyleSheet, Text, Switch} = require('react-native');
import {Field} from './Field';
export class SwitchComponent extends React.Component{
constructor(props){
super(props);
this.state = {
value: props.value,
}
}
handleLayoutChange(e){
let {x, y, width, height} = {... e.nativeEvent.layout};
this.setState(e.nativeEvent.layout);
//e.nativeEvent.layout: {x, y, width, height}}}.
}
setValue(value){
this.setState({value:value});
if(this.props.onChange) this.props.onChange(value);
if(this.props.onValueChange) this.props.onValueChange(value);
}
handleValueChange(value){
// debugger;
this.setState({value:value});
if(this.props.onChange) this.props.onChange(value);
if(this.props.onValueChange) this.props.onValueChange(value);
}
render(){
return(<Field {...this.props}>
<View style={this.props.containerStyle}
onLayout={this.handleLayoutChange.bind(this)}>
<Text style={this.props.labelStyle}>{this.props.label}</Text>
<Switch
onValueChange={this.handleValueChange.bind(this)}
style={this.props.switchStyle}
value={this.state.value} />
</View>
</Field>
)
}
}
SwitchComponent.propTypes = {
labelStyle: Text.propTypes.style,
containerStyle: View.propTypes.style,
switchStyle: Switch.propTypes.style
}
let formStyles = StyleSheet.create({
form:{
},
alignRight:{
marginTop: 7, position:'absolute', right: 10
},
noBorder:{
borderTopWidth: 0,
borderBottomWidth: 0
},
separatorContainer:{
// borderTopColor: '#C8C7CC',
// borderTopWidth: 1,
paddingTop: 35,
borderBottomColor: '#C8C7CC',
borderBottomWidth: 1,
},
separator:{
paddingLeft: 10,
paddingRight: 10,
color: '#6D6D72',
paddingBottom: 7
},
fieldsWrapper:{
// borderTopColor: '#afafaf',
// borderTopWidth: 1,
},
horizontalContainer:{
flexDirection: 'row',
justifyContent: 'flex-start'
},
fieldContainer:{
borderBottomWidth: 1,
borderBottomColor: '#C8C7CC',
backgroundColor: 'white',
justifyContent: 'center',
height: 45
},
fieldText:{
fontSize: 34/2,
paddingLeft: 10,
paddingRight: 10,
justifyContent: 'center',
lineHeight: 32
},
input:{
paddingLeft: 10,
paddingRight: 10,
},
helpTextContainer:{
marginTop:9,
marginBottom: 25,
paddingLeft: 20,
paddingRight: 20,
},
helpText:{
color: '#7a7a7a'
}
});