forked from mastermoo/react-native-action-button
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionButtonItem.js
More file actions
119 lines (107 loc) · 2.67 KB
/
Copy pathActionButtonItem.js
File metadata and controls
119 lines (107 loc) · 2.67 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
'use strict';
var React = require('react-native');
var {
Component,
StyleSheet,
Text,
View,
Animated,
TouchableOpacity,
} = React;
let actionBtnWidth = 0;
class ActionButtonItem extends Component {
constructor(props) {
super(props);
this.state = {
spaceBetween: 10,
offsetTop: props.size > 42 ? 17 : 10,
};
if (!props.children || Array.isArray(props.children)) throw new Error("ActionButtonItem must have a Child component.");
if(this.props.size > 0) actionBtnWidth = this.props.size;
}
render() {
return (
<Animated.View style={
[
styles.actionButtonWrap,
{
marginBottom: this.props.spacing,
opacity: this.props.anim,
transform: [
{
translateY: this.props.anim.interpolate({
inputRange: [0, 1],
outputRange: [40, 0]
}),
},
],
}
]
}>
<TouchableOpacity style={{flex:1}} onPress={this.props.onPress}>
<View style={[styles.actionButton, this.props.style,
{
width: actionBtnWidth,
height: actionBtnWidth,
borderRadius: actionBtnWidth/2,
backgroundColor: this.props.buttonColor || 'white'
}
]}>
{this.props.children}
</View>
</TouchableOpacity>
<TouchableOpacity style={this.getTextStyles()} onPress={this.props.onPress}>
<Text style={this.actionTextOnly}>{this.props.title}</Text>
</TouchableOpacity>
</Animated.View>
);
}
getTextStyles() {
let positionStyles = {
right: actionBtnWidth + this.state.spaceBetween,
top: this.state.offsetTop - 3
}
if (this.props.position == 'left') positionStyles = {
left: actionBtnWidth + this.state.spaceBetween,
top: this.state.offsetTop
}
return [styles.actionText, positionStyles]
}
}
var styles = StyleSheet.create({
actionButtonWrap: {
alignItems: 'center',
},
actionButton: {
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
paddingTop: 2,
shadowRadius: 3,
shadowOffset: {
width: 0,
height: 1,
},
shadowOpacity: 0.8,
},
actionTextOnly: {
color: '#9E9E9E',
fontFamily: 'Avenir',
fontSize: 14,
fontWeight: '600',
},
actionText: {
paddingVertical: 5,
paddingHorizontal: 10,
position: 'absolute',
backgroundColor: 'white',
borderRadius: 5,
shadowRadius: 0.25,
shadowOffset: {
width: 0,
height: 0.25,
},
shadowOpacity: 0.8,
},
});
module.exports = ActionButtonItem;