-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
63 lines (55 loc) · 1.58 KB
/
index.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
import React, { Component } from 'react'
import { View, Text, TouchableOpacity } from 'react-native'
import { getDefaultStyle, getPressInStyle } from './helpers'
import { staticDefaultProps } from './static'
import { buttonStyles, styles } from './styles'
class Button extends Component {
static defaultProps = {...staticDefaultProps}
constructor(props){
super(props)
const {
backgroundColor,
borderColor,
borderLeftWidth,
borderRadius,
borderRightWidth,
shadowHeight,
type,
} = this.props
this.state = {
style: getDefaultStyle(type, this.props),
pressInStyle: getPressInStyle(type, backgroundColor, borderRadius),
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, children, containerStyle, contentStyle, onPress, shadowHeight } = this.props
const { isBorderPresent, style } = this.state
return (
<TouchableOpacity
{...this.props}
onPress={onPress}
onPressIn={this._pressIn}
onPressOut={this._pressOut}
activeOpacity={activeOpacity}
style={[styles.buttonContainer, style, { borderBottomWidth: isBorderPresent ? shadowHeight : 0 }, containerStyle]}>
<Text style={[styles.text, contentStyle]}>
{children}
</Text>
</TouchableOpacity>
)
}
}
export default Button