forked from aksonov/react-native-tabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (68 loc) · 1.98 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
64
65
66
67
68
69
70
71
72
'use strict';
var React = require('react-native');
var {
Component,
StyleSheet,
View,
Text,
TouchableOpacity,
} = React;
class Tabs extends Component {
onSelect(el){
if (el.props.onSelect) {
el.props.onSelect(el);
} else if (this.props.onSelect) {
this.props.onSelect(el);
}
}
render(){
const self = this;
let selected = this.props.selected
if (!selected){
React.Children.forEach(this.props.children, el=>{
if (!selected || el.props.initial){
selected = el.props.name;
}
});
}
return (
<View style={[styles.tabbarView, this.props.style]}>
{React.Children.map(this.props.children,(el)=>
<TouchableOpacity key={el.props.name+"touch"}
style={[styles.iconView, this.props.iconStyle, el.props.name == selected ? this.props.selectedIconStyle || el.props.selectedIconStyle || {} : {} ]}
onPress={()=>!self.props.locked && self.onSelect(el)}
onLongPress={()=>self.props.locked && self.onSelect(el)}>
{selected == el.props.name ? React.cloneElement(el, {selected: true, style: [el.props.style, this.props.selectedStyle, el.props.selectedStyle]}) : el}
</TouchableOpacity>
)}
</View>
);
}
}
var styles = StyleSheet.create({
container: {
flex: 1
},
tabbarView: {
position:'absolute',
bottom:0,
right:0,
left:0,
height:50,
opacity:1,
backgroundColor:'transparent',
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center'
},
iconView: {
flex: 1,
height: 50,
justifyContent: 'center',
alignItems: 'center',
},
contentView: {
flex: 1
}
});
module.exports = Tabs;