|
1 | | -'use strict'; |
2 | | - |
3 | | -var React = require('react-native'); |
4 | | -var { |
| 1 | +import React, { |
5 | 2 | StyleSheet, |
6 | 3 | Text, |
7 | 4 | View, |
8 | 5 | TouchableOpacity, |
9 | 6 | Animated, |
10 | | -} = React; |
| 7 | +} from 'react-native'; |
11 | 8 |
|
12 | | -const Icon = require('react-native-vector-icons/Ionicons'); |
| 9 | +import Icon from 'react-native-vector-icons/Ionicons'; |
13 | 10 |
|
14 | | -var styles = StyleSheet.create({ |
15 | | - tab: { |
16 | | - flex: 1, |
17 | | - alignItems: 'center', |
18 | | - justifyContent: 'center', |
19 | | - paddingBottom: 10, |
20 | | - }, |
21 | | - tabs: { |
22 | | - height: 45, |
23 | | - flexDirection: 'row', |
24 | | - paddingTop: 5, |
25 | | - borderWidth: 1, |
26 | | - borderTopWidth: 0, |
27 | | - borderLeftWidth: 0, |
28 | | - borderRightWidth: 0, |
29 | | - borderBottomColor: 'rgba(0,0,0,0.05)', |
30 | | - }, |
31 | | - icon: { |
32 | | - position: 'absolute', |
33 | | - top: 0, |
34 | | - left: 20, |
35 | | - }, |
36 | | -}); |
37 | | - |
38 | | -var FacebookTabBar = React.createClass({ |
| 11 | +const FacebookTabBar = React.createClass({ |
39 | 12 | selectedTabIcons: [], |
40 | 13 | unselectedTabIcons: [], |
41 | 14 |
|
42 | 15 | propTypes: { |
43 | 16 | goToPage: React.PropTypes.func, |
44 | 17 | activeTab: React.PropTypes.number, |
45 | | - tabs: React.PropTypes.array |
| 18 | + tabs: React.PropTypes.array, |
46 | 19 | }, |
47 | 20 |
|
48 | 21 | renderTabOption(name, page) { |
49 | | - var isTabActive = this.props.activeTab === page; |
| 22 | + const isTabActive = this.props.activeTab === page; |
50 | 23 |
|
51 | 24 | return ( |
52 | 25 | <TouchableOpacity key={name} onPress={() => this.props.goToPage(page)} style={styles.tab}> |
53 | 26 | <Icon name={name} size={30} color='#3B5998' style={styles.icon} |
54 | | - ref={(icon) => { this.selectedTabIcons[page] = icon }}/> |
| 27 | + ref={(icon) => { this.selectedTabIcons[page] = icon; }}/> |
55 | 28 | <Icon name={name} size={30} color='#ccc' style={styles.icon} |
56 | | - ref={(icon) => { this.unselectedTabIcons[page] = icon }}/> |
| 29 | + ref={(icon) => { this.unselectedTabIcons[page] = icon; }}/> |
57 | 30 | </TouchableOpacity> |
58 | 31 | ); |
59 | 32 | }, |
60 | 33 |
|
61 | 34 | componentDidMount() { |
62 | | - this.setAnimationValue({value: this.props.activeTab}); |
| 35 | + this.setAnimationValue({ value: this.props.activeTab, }); |
63 | 36 | this._listener = this.props.scrollValue.addListener(this.setAnimationValue); |
64 | 37 | }, |
65 | 38 |
|
66 | | - setAnimationValue({value}) { |
67 | | - var currentPage = this.props.activeTab; |
68 | | - |
| 39 | + setAnimationValue({ value, }) { |
69 | 40 | this.unselectedTabIcons.forEach((icon, i) => { |
70 | | - var iconRef = icon; |
| 41 | + let iconRef = icon; |
71 | 42 |
|
72 | 43 | if (!icon.setNativeProps && icon !== null) { |
73 | | - iconRef = icon.refs.icon_image |
| 44 | + iconRef = icon.refs.icon_image; |
74 | 45 | } |
75 | 46 |
|
76 | 47 | if (value - i >= 0 && value - i <= 1) { |
77 | | - iconRef.setNativeProps({ style: {opacity: value - i} }); |
| 48 | + iconRef.setNativeProps({ style: { opacity: value - i, }, }); |
78 | 49 | } |
79 | 50 | if (i - value >= 0 && i - value <= 1) { |
80 | | - iconRef.setNativeProps({ style: {opacity: i - value} }); |
| 51 | + iconRef.setNativeProps({ style: { opacity: i - value, }, }); |
81 | 52 | } |
82 | 53 | }); |
83 | 54 | }, |
84 | 55 |
|
85 | 56 | render() { |
86 | | - var containerWidth = this.props.containerWidth; |
87 | | - var numberOfTabs = this.props.tabs.length; |
88 | | - var tabUnderlineStyle = { |
| 57 | + const containerWidth = this.props.containerWidth; |
| 58 | + const numberOfTabs = this.props.tabs.length; |
| 59 | + const tabUnderlineStyle = { |
89 | 60 | position: 'absolute', |
90 | 61 | width: containerWidth / numberOfTabs, |
91 | 62 | height: 3, |
92 | 63 | backgroundColor: '#3b5998', |
93 | 64 | bottom: 0, |
94 | 65 | }; |
95 | 66 |
|
96 | | - var left = this.props.scrollValue.interpolate({ |
97 | | - inputRange: [0, 1], outputRange: [0, containerWidth / numberOfTabs] |
| 67 | + const left = this.props.scrollValue.interpolate({ |
| 68 | + inputRange: [0, 1, ], outputRange: [0, containerWidth / numberOfTabs, ], |
98 | 69 | }); |
99 | 70 |
|
100 | | - return ( |
101 | | - <View> |
102 | | - <View style={[styles.tabs, this.props.style, ]}> |
103 | | - {this.props.tabs.map((tab, i) => this.renderTabOption(tab, i))} |
104 | | - </View> |
105 | | - <Animated.View style={[tabUnderlineStyle, {left}]} /> |
| 71 | + return <View> |
| 72 | + <View style={[styles.tabs, this.props.style, ]}> |
| 73 | + {this.props.tabs.map((tab, i) => this.renderTabOption(tab, i))} |
106 | 74 | </View> |
107 | | - ); |
| 75 | + <Animated.View style={[tabUnderlineStyle, { left, }, ]} /> |
| 76 | + </View>; |
| 77 | + }, |
| 78 | +}); |
| 79 | + |
| 80 | +const styles = StyleSheet.create({ |
| 81 | + tab: { |
| 82 | + flex: 1, |
| 83 | + alignItems: 'center', |
| 84 | + justifyContent: 'center', |
| 85 | + paddingBottom: 10, |
| 86 | + }, |
| 87 | + tabs: { |
| 88 | + height: 45, |
| 89 | + flexDirection: 'row', |
| 90 | + paddingTop: 5, |
| 91 | + borderWidth: 1, |
| 92 | + borderTopWidth: 0, |
| 93 | + borderLeftWidth: 0, |
| 94 | + borderRightWidth: 0, |
| 95 | + borderBottomColor: 'rgba(0,0,0,0.05)', |
| 96 | + }, |
| 97 | + icon: { |
| 98 | + position: 'absolute', |
| 99 | + top: 0, |
| 100 | + left: 20, |
108 | 101 | }, |
109 | 102 | }); |
110 | 103 |
|
111 | | -module.exports = FacebookTabBar; |
| 104 | +export default FacebookTabBar; |
0 commit comments