-
Notifications
You must be signed in to change notification settings - Fork 0
/
Toolbar.js
61 lines (54 loc) · 1.63 KB
/
Toolbar.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
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { View, TouchableOpacity, StyleSheet } from 'react-native';
const styles = StyleSheet.create({
button: {
alignItems: 'center',
justifyContent: 'center',
},
});
export default class Toolbar extends Component {
static defaultProps = {
height: 56,
onLeftButtonPress: () => {
},
hideLeftButton: false,
};
static propTypes = {
height: PropTypes.number,
leftButton: PropTypes.element,
onLeftButtonPress: PropTypes.func,
hideLeftButton: PropTypes.bool,
rightButtons: PropTypes.arrayOf(PropTypes.shape({
icon: PropTypes.element.isRequired,
onPress: PropTypes.func.isRequired,
})),
children: PropTypes.element,
};
_handleLeftButtonPress = () => {
this.props.onLeftButtonPress();
};
render() {
const { height: buttonSize, leftButton, hideLeftButton, rightButtons, children, style } = this.props;
return (
<View style={[style, { flexDirection: 'row', height: buttonSize }]}>
{hideLeftButton === false && leftButton && (
<TouchableOpacity
onPress={this._handleLeftButtonPress}
style={[styles.button, { width: buttonSize }]}>
{leftButton}
</TouchableOpacity>
)}
<View style={{ flex: 1 }}>{children}</View>
{rightButtons && rightButtons.map((button, i) => (
<TouchableOpacity
key={i}
style={[styles.button, { width: buttonSize }]}
onPress={button.onPress}>
{button.icon}
</TouchableOpacity>
))}
</View>
);
}
}