-
Notifications
You must be signed in to change notification settings - Fork 74
/
tab.js
105 lines (88 loc) · 3.48 KB
/
tab.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
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
import React from 'react';
import PropTypes from 'prop-types';
import {
Text,
View,
TouchableOpacity,
Navigator,
InteractionManager,
Platform,
ScrollView,
Image,
DeviceEventEmitter
} from 'react-native';
import styles from './style';
class TabBar extends React.Component {
constructor(props) {
super(props);
this._setAnimationValue = this._setAnimationValue.bind(this);
this.state = {
cameraPressed: false
};
this.tabComponent = [];
}
static propTypes = {
goToPage: PropTypes.func,
activeTab: PropTypes.number,
tabs: PropTypes.array,
};
componentDidMount() {
this._listener = this.props.scrollValue.addListener(this._setAnimationValue);
if (Platform.OS === 'android')
setTimeout(()=>{
this.props.goToPage(this.props.activeTab+1);
},100)
}
componentWillUpdate(){
}
_setAnimationValue({ value, }) {
}
_onIconPress(i) {
this.props.goToPage(i);
if (Platform.OS === 'android' && this.props.asyncRender)
DeviceEventEmitter.emit('tabChanged', i);
}
_getMore() {
this.props.onPlusPress();
}
componentWillReceiveProps() {
}
render() {
return (
<View style={[styles.tabs, this.props.style, ]}>
<ScrollView
horizontal={true}
showsHorizontalScrollIndicator={false}
>
{this.props.tabs.map((tab, i) => {
if(tab === 'plus'){
return <TouchableOpacity ref={(component) => this.tabComponent.push(component)}
key={tab} onPress={() => this._getMore()}
style={[styles.tab,{backgroundColor: (this.props.activeTab === i? '#f1f1f1': '#fff')}]}>
<Image
resizeMode={'contain'}
style={styles.plusButton}
source={require('./plus.png')}/>
</TouchableOpacity>;
}
if(tab === 'history'){
return <TouchableOpacity ref={(component) => this.tabComponent.push(component)}
key={tab} onPress={() => this._onIconPress(i)}
style={[styles.tab,{backgroundColor: (this.props.activeTab === i? '#f1f1f1': '#fff')}]}>
<Image
resizeMode={'contain'}
style={styles.plusButton}
source={require('./history.png')}/>
</TouchableOpacity>;
}
return <TouchableOpacity ref={(component) => this.tabComponent.push(component)}
key={tab} onPress={() => this._onIconPress(i)}
style={[styles.tab,{backgroundColor: (this.props.activeTab === i? '#f1f1f1': '#fff')}]}>
<Text style={styles.emoji }>{this.props.tabs[i]}</Text>
</TouchableOpacity>;
})}
</ScrollView>
</View>);
}
}
export default TabBar;