Repository navigation
Expand file tree
/
Copy pathButton.js
More file actions
99 lines (89 loc) · 2.87 KB
/
Copy pathButton.js
File metadata and controls
99 lines (89 loc) · 2.87 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
/* @flow */
import React, { Component } from 'react';
import _ from 'lodash';
import { TouchableOpacity, Platform, View, TouchableNativeFeedback } from 'react-native';
import { connectStyle } from '@shoutem/theme';
import variables from './../theme/variables/platform';
import { Badge } from './Badge';
import { Text } from './Text';
import computeProps from '../Utils/computeProps';
import mapPropsToStyleNames from '../Utils/mapPropsToStyleNames';
class Button extends Component {
getInitialStyle() {
return {
borderedBtn: {
borderWidth: (this.props.bordered) ? 1 : undefined,
borderRadius: (this.props.rounded && this.props.bordered) ? variables.borderRadiusLarge : 2,
},
};
}
prepareRootProps() {
const defaultProps = {
style: this.getInitialStyle().borderedBtn,
};
return computeProps(this.props, defaultProps);
}
render() {
if (Platform.OS==='ios' || variables.androidRipple===false || Platform['Version'] <= 21) {
return (
<TouchableOpacity
{...this.prepareRootProps()}
ref={c => this._root = c}
activeOpacity={(this.props.activeOpacity) ? this.props.activeOpacity : 0.5}
>
{this.props.children}
</TouchableOpacity>
);
}
if (Platform.OS==='web') {
return (
<TouchableOpacity
{...this.prepareRootProps()}
ref={c => this._root = c}
activeOpacity={(this.props.activeOpacity) ? this.props.activeOpacity : 0.5}
>
{this.props.children}
</TouchableOpacity>
);
}
else {
return(
<TouchableNativeFeedback ref={c => this._root = c}
onPress={this.props.onPress}
background={(this.props.androidRippleColor) ? TouchableNativeFeedback.Ripple(this.props.androidRippleColor) : TouchableNativeFeedback.Ripple(variables.androidRippleColor)}
{...this.prepareRootProps()}>
<View {...this.prepareRootProps()}>
{this.props.children}
</View>
</TouchableNativeFeedback>
);
}
}
}
Button.propTypes = {
...TouchableOpacity.propTypes,
style: React.PropTypes.object,
block: React.PropTypes.bool,
primary: React.PropTypes.bool,
transparent: React.PropTypes.bool,
success: React.PropTypes.bool,
danger: React.PropTypes.bool,
warning: React.PropTypes.bool,
info: React.PropTypes.bool,
bordered: React.PropTypes.bool,
capitalize: React.PropTypes.bool,
disabled: React.PropTypes.bool,
rounded: React.PropTypes.bool,
large: React.PropTypes.bool,
small: React.PropTypes.bool,
active: React.PropTypes.bool,
badgeColor: React.PropTypes.string,
badgeValueStyle: React.PropTypes.object,
};
Button.defaultProps = {
capitalize: true
}
const StyledButton = connectStyle('NativeBase.Button', {}, mapPropsToStyleNames)(Button);
export {
StyledButton as Button,
};