forked from GeekyAnts/NativeBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButton.js
More file actions
91 lines (84 loc) · 2.53 KB
/
Button.js
File metadata and controls
91 lines (84 loc) · 2.53 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
import React, { Component } from "react";
import PropTypes from "prop-types";
import { TouchableOpacity, Platform, View, TouchableNativeFeedback } from "react-native";
import { connectStyle } from "native-base-shoutem-theme";
import variables from "./../theme/variables/platform";
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,
},
};
}
_root: React$Element<TouchableOpacity | TouchableNativeFeedback>;
prepareRootProps() {
const defaultProps = {
style: this.getInitialStyle().borderedBtn,
};
return computeProps(this.props, defaultProps);
}
render() {
const children =
Platform.OS === "ios"
? this.props.children
: React.Children.map(
this.props.children,
child =>
child && child.type === Text
? React.cloneElement(child, { uppercase: true, ...child.props })
: child
);
if (Platform.OS === "ios" || variables.androidRipple === false || Platform["Version"] <= 21) {
return (
<TouchableOpacity
{...this.prepareRootProps()}
ref={c => (this._root = c)}
activeOpacity={this.props.activeOpacity > 0 ? this.props.activeOpacity : 0.5}
>
{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()}>
{children}
</View>
</TouchableNativeFeedback>
);
}
}
}
Button.propTypes = {
...TouchableOpacity.propTypes,
style: PropTypes.oneOfType([PropTypes.object, PropTypes.number, PropTypes.array]),
block: PropTypes.bool,
primary: PropTypes.bool,
transparent: PropTypes.bool,
success: PropTypes.bool,
danger: PropTypes.bool,
warning: PropTypes.bool,
info: PropTypes.bool,
bordered: PropTypes.bool,
disabled: PropTypes.bool,
rounded: PropTypes.bool,
large: PropTypes.bool,
small: PropTypes.bool,
active: PropTypes.bool,
};
const StyledButton = connectStyle("NativeBase.Button", {}, mapPropsToStyleNames)(Button);
export { StyledButton as Button };