Skip to content

Commit faaa050

Browse files
authored
Merge pull request ptomasroos#401 from anyx/render-tab-name-option
renderTabName ScrollableTabBar property
2 parents 3231588 + 464ddad commit faaa050

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

DefaultTabBar.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const DefaultTabBar = React.createClass({
2020
inactiveTextColor: React.PropTypes.string,
2121
textStyle: Text.propTypes.style,
2222
tabStyle: View.propTypes.style,
23+
renderTabName: React.PropTypes.func,
2324
},
2425

2526
getDefaultProps() {
@@ -29,14 +30,12 @@ const DefaultTabBar = React.createClass({
2930
underlineColor: 'navy',
3031
backgroundColor: null,
3132
underlineHeight: 4,
33+
renderTabName: this.renderTabName,
3234
};
3335
},
3436

3537
renderTabOption(name, page) {
3638
const isTabActive = this.props.activeTab === page;
37-
const { activeTextColor, inactiveTextColor, textStyle, } = this.props;
38-
const textColor = isTabActive ? activeTextColor : inactiveTextColor;
39-
const fontWeight = isTabActive ? 'bold' : 'normal';
4039

4140
return <Button
4241
style={{flex: 1, }}
@@ -46,14 +45,22 @@ const DefaultTabBar = React.createClass({
4645
accessibilityTraits='button'
4746
onPress={() => this.props.goToPage(page)}
4847
>
49-
<View style={[styles.tab, this.props.tabStyle, ]}>
50-
<Text style={[{color: textColor, fontWeight, }, textStyle, ]}>
51-
{name}
52-
</Text>
53-
</View>
48+
{this.renderTabName(name, page, isTabActive)}
5449
</Button>;
5550
},
5651

52+
renderTabName(name, page, isTabActive) {
53+
const { activeTextColor, inactiveTextColor, textStyle, } = this.props;
54+
const textColor = isTabActive ? activeTextColor : inactiveTextColor;
55+
const fontWeight = isTabActive ? 'bold' : 'normal';
56+
57+
return <View style={[styles.tab, this.props.tabStyle, ]}>
58+
<Text style={[{color: textColor, fontWeight, }, textStyle, ]}>
59+
{name}
60+
</Text>
61+
</View>;
62+
},
63+
5764
render() {
5865
const containerWidth = this.props.containerWidth;
5966
const numberOfTabs = this.props.tabs.length;

ScrollableTabBar.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const ScrollableTabBar = React.createClass({
2828
tabStyle: View.propTypes.style,
2929
tabsContainerStyle: View.propTypes.style,
3030
textStyle: Text.propTypes.style,
31+
renderTabName: React.PropTypes.func,
3132
},
3233

3334
getDefaultProps() {
@@ -41,6 +42,7 @@ const ScrollableTabBar = React.createClass({
4142
style: {},
4243
tabStyle: {},
4344
tabsContainerStyle: {},
45+
renderTabName: this.renderTabName,
4446
};
4547
},
4648

@@ -124,9 +126,6 @@ const ScrollableTabBar = React.createClass({
124126

125127
renderTabOption(name, page) {
126128
const isTabActive = this.props.activeTab === page;
127-
const { activeTextColor, inactiveTextColor, textStyle, } = this.props;
128-
const textColor = isTabActive ? activeTextColor : inactiveTextColor;
129-
const fontWeight = isTabActive ? 'bold' : 'normal';
130129

131130
return <Button
132131
key={`${name}_${page}`}
@@ -136,14 +135,22 @@ const ScrollableTabBar = React.createClass({
136135
onPress={() => this.props.goToPage(page)}
137136
onLayout={this.measureTab.bind(this, page)}
138137
>
139-
<View style={[styles.tab, this.props.tabStyle, ]}>
140-
<Text style={[{color: textColor, fontWeight, }, textStyle, ]}>
141-
{name}
142-
</Text>
143-
</View>
138+
{this.renderTabName(name, page, isTabActive)}
144139
</Button>;
145140
},
146141

142+
renderTabName(name, page, isTabActive) {
143+
const { activeTextColor, inactiveTextColor, textStyle, } = this.props;
144+
const textColor = isTabActive ? activeTextColor : inactiveTextColor;
145+
const fontWeight = isTabActive ? 'bold' : 'normal';
146+
147+
return <View style={[styles.tab, this.props.tabStyle, ]}>
148+
<Text style={[{color: textColor, fontWeight, }, textStyle, ]}>
149+
{name}
150+
</Text>
151+
</View>;
152+
},
153+
147154
measureTab(page, event) {
148155
const { x, width, height, } = event.nativeEvent.layout;
149156
this._tabsMeasurements[page] = {left: x, right: x + width, width, height, };
@@ -163,7 +170,7 @@ const ScrollableTabBar = React.createClass({
163170
width: this.state._widthTabUnderline,
164171
};
165172

166-
return <View
173+
return <View
167174
style={[styles.container, {backgroundColor: this.props.backgroundColor, }, this.props.style, ]}
168175
onLayout={this.onContainerLayout}
169176
>

0 commit comments

Comments
 (0)