Skip to content

Commit 689f750

Browse files
committed
renderTab small fixes
1 parent 8889da6 commit 689f750

File tree

3 files changed

+11
-40
lines changed

3 files changed

+11
-40
lines changed

DefaultTabBar.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ const DefaultTabBar = React.createClass({
3434
},
3535

3636
renderTabOption(name, page) {
37-
const isTabActive = this.props.activeTab === page;
38-
39-
let onPressHandler = this.props.goToPage;
40-
let renderTab = this.props.renderTab ? this.props.renderTab : this.renderTab;
41-
42-
return renderTab(name, page, isTabActive, onPressHandler);
4337
},
4438

4539
renderTab(name, page, isTabActive, onPressHandler) {
@@ -80,7 +74,11 @@ const DefaultTabBar = React.createClass({
8074

8175
return (
8276
<View style={[styles.tabs, {backgroundColor: this.props.backgroundColor, }, this.props.style, ]}>
83-
{this.props.tabs.map((tab, i) => this.renderTabOption(tab, i))}
77+
{this.props.tabs.map((name, page) => {
78+
const isTabActive = this.props.activeTab === page;
79+
const renderTab = this.props.renderTab || this.renderTab;
80+
return renderTab(name, page, isTabActive, this.props.goToPage);
81+
})}
8482
<Animated.View style={[tabUnderlineStyle, { left, }, ]} />
8583
</View>
8684
);

ScrollableTabBar.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,6 @@ const ScrollableTabBar = React.createClass({
123123
}
124124
},
125125

126-
renderTabOption(name, page) {
127-
const isTabActive = this.props.activeTab === page;
128-
129-
let onPressHandler = this.props.goToPage;
130-
let onLayoutHandler = this.measureTab.bind(this, page);
131-
let renderTab = this.props.renderTab ? this.props.renderTab : this.renderTab;
132-
133-
return renderTab(name, page, isTabActive, onPressHandler, onLayoutHandler);
134-
},
135-
136126
renderTab(name, page, isTabActive, onPressHandler, onLayoutHandler) {
137127
const { activeTextColor, inactiveTextColor, textStyle, } = this.props;
138128
const textColor = isTabActive ? activeTextColor : inactiveTextColor;
@@ -191,7 +181,11 @@ const ScrollableTabBar = React.createClass({
191181
ref={'tabContainer'}
192182
onLayout={this.onTabContainerLayout}
193183
>
194-
{this.props.tabs.map((tab, i) => this.renderTabOption(tab, i))}
184+
{this.props.tabs.map((name, page) => {
185+
const isTabActive = this.props.activeTab === page;
186+
const renderTab = this.props.renderTab || this.renderTab;
187+
return renderTab(name, page, isTabActive, this.props.goToPage, this.measureTab.bind(this, page));
188+
})}
195189
<Animated.View style={[tabUnderlineStyle, dynamicTabUnderline, ]} />
196190
</View>
197191
</ScrollView>

examples/FacebookTabsExample/DynamicExample.js

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,11 @@
11
import React from 'react';
22
import {
33
Text,
4-
StyleSheet,
5-
View,
64
TouchableHighlight,
75
} from 'react-native';
86
import TimerMixin from 'react-timer-mixin';
9-
import Icon from 'react-native-vector-icons/Ionicons';
107
import ScrollableTabView, { DefaultTabBar, } from 'react-native-scrollable-tab-view';
118

12-
const styles = StyleSheet.create({
13-
tab: {
14-
flex: 1,
15-
flexDirection: 'row',
16-
alignItems: 'center',
17-
justifyContent: 'center',
18-
paddingBottom: 10,
19-
},
20-
icon: {
21-
marginRight: 3,
22-
},
23-
});
24-
259
const Child = React.createClass({
2610
onEnter() {
2711
console.log('enter: ' + this.props.i); // eslint-disable-line no-console
@@ -67,12 +51,7 @@ export default React.createClass({
6751
style={{flex: 1, }}
6852
underlayColor="#aaaaaa"
6953
>
70-
<View style={[styles.tab, this.props.tabStyle, ]}>
71-
<Icon name="md-star" color="red" size={16} style={styles.icon}/>
72-
<Text style={[{color: 'blue', }, ]}>
73-
{name}
74-
</Text>
75-
</View>
54+
<Text>{name}</Text>
7655
</TouchableHighlight>;
7756
},
7857

0 commit comments

Comments
 (0)