-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlatButton.js
More file actions
120 lines (105 loc) · 2.65 KB
/
Copy pathFlatButton.js
File metadata and controls
120 lines (105 loc) · 2.65 KB
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
import React, {
Component
} from 'react';
import {
View,
Text,
StyleSheet,
TouchableOpacity
} from 'react-native';
class FlatButton extends Component {
constructor(props){
super(props);
const {
backgroundColor,
borderColor,
borderLeftWidth,
borderRadius,
borderRightWidth,
shadowHeight,
pressShadowHeight,
type,
} = this.props;
let pressInStyle = {
borderColor : 'transparent',
borderBottomWidth: 0,
borderLeftWidth : 0,
borderRightWidth : 0
};
let buttonContainer = {
borderRadius : props.borderRadius,
borderTopWidth : props.shadowHeight,
borderBottomWidth: props.shadowHeight,
backgroundColor : props.backgroundColor,
borderColor : props.borderColor,
borderLeftWidth : props.borderLeftWidth,
borderRightWidth : props.borderRightWidth,
justifyContent : 'center',
alignItems : 'center'
};
this.state = {
style : [ buttonContainer, props.buttonStyle ],
pressInStyle : [ pressInStyle, props.buttonPressStyle ],
isBorderPresent : true,
}
this._pressIn = this._pressIn.bind(this);
this._pressOut = this._pressOut.bind(this);
}
_pressIn(){
this.setState({ isBorderPresent: false, });
}
_pressOut(){
this.setState({ isBorderPresent: true, });
}
render() {
const { activeOpacity, buttonContainer, containerStyle, contentStyle, onPress, shadowHeight, pressShadowHeight, child, buttonText } = this.props;
const { isBorderPresent, style } = this.state;
return (
<TouchableOpacity
{...this.props}
onPress={onPress}
onPressIn={this._pressIn}
onPressOut={this._pressOut}
activeOpacity={activeOpacity}
style={[ buttonContainer, style, { borderBottomWidth: isBorderPresent ? shadowHeight : pressShadowHeight }, containerStyle]}>
{this.renderChildren()}
</TouchableOpacity>
)
}
renderChildren () {
let childElements = [];
React.Children.forEach(this.props.children, (item) => {
if (typeof item === 'string' || typeof item === 'number') {
const element = (
<Text
key={item}
style={[ styles.text, this.props.contentStyle ]} >
{item}
</Text>
);
childElements.push(element);
} else if (React.isValidElement(item)) {
childElements.push(item);
}
});
return (childElements);
}
}
const styles = StyleSheet.create({
text:{
color: 'white',
fontSize: 18,
// fontWeight: 'bold'
}
});
FlatButton.defaultProps = {
borderRadius : 8,
shadowHeight : 2,
pressShadowHeight : 0,
activeOpacity : 0.9,
backgroundColor : '#34495e',
borderColor : '#2c3e50',
borderLeftWidth : 0.5,
borderRightWidth : 0.5
};
export default FlatButton;