Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add override of tab bar container and row style. #976

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions DefaultTabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const DefaultTabBar = createReactClass({
activeTab: PropTypes.number,
tabs: PropTypes.array,
backgroundColor: PropTypes.string,
activeBackgroundColor: PropTypes.string,
inactiveBackgroundColor: PropTypes.string,
activeTextColor: PropTypes.string,
inactiveTextColor: PropTypes.string,
textStyle: Text.propTypes.style,
Expand All @@ -26,6 +28,8 @@ const DefaultTabBar = createReactClass({

getDefaultProps() {
return {
activeBackgroundColor: 'white',
inactiveBackgroundColor: 'white',
activeTextColor: 'navy',
inactiveTextColor: 'black',
backgroundColor: null,
Expand All @@ -36,7 +40,8 @@ const DefaultTabBar = createReactClass({
},

renderTab(name, page, isTabActive, onPressHandler) {
const { activeTextColor, inactiveTextColor, textStyle, } = this.props;
const { activeBackgroundColor, inactiveBackgroundColor, activeTextColor, inactiveTextColor, textStyle, } = this.props;
const backgroundColor = isTabActive ? activeBackgroundColor : inactiveBackgroundColor;
const textColor = isTabActive ? activeTextColor : inactiveTextColor;
const fontWeight = isTabActive ? 'bold' : 'normal';

Expand All @@ -48,7 +53,7 @@ const DefaultTabBar = createReactClass({
accessibilityTraits='button'
onPress={() => onPressHandler(page)}
>
<View style={[styles.tab, this.props.tabStyle, ]}>
<View style={[styles.tab, {backgroundColor, }, this.props.tabStyle, ]}>
<Text style={[{color: textColor, fontWeight, }, textStyle, ]}>
{name}
</Text>
Expand Down
9 changes: 7 additions & 2 deletions ScrollableTabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const ScrollableTabBar = createReactClass({
activeTab: PropTypes.number,
tabs: PropTypes.array,
backgroundColor: PropTypes.string,
activeBackgroundColor: PropTypes.string,
inactiveBackgroundColor: PropTypes.string,
activeTextColor: PropTypes.string,
inactiveTextColor: PropTypes.string,
scrollOffset: PropTypes.number,
Expand All @@ -36,6 +38,8 @@ const ScrollableTabBar = createReactClass({
getDefaultProps() {
return {
scrollOffset: 52,
activeBackgroundColor: 'white',
inactiveBackgroundColor: 'white',
activeTextColor: 'navy',
inactiveTextColor: 'black',
backgroundColor: null,
Expand Down Expand Up @@ -125,7 +129,8 @@ const ScrollableTabBar = createReactClass({
},

renderTab(name, page, isTabActive, onPressHandler, onLayoutHandler) {
const { activeTextColor, inactiveTextColor, textStyle, } = this.props;
const { activeBackgroundColor, inactiveBackgroundColor, activeTextColor, inactiveTextColor, textStyle, } = this.props;
const backgroundColor = isTabActive ? activeBackgroundColor : inactiveBackgroundColor;
const textColor = isTabActive ? activeTextColor : inactiveTextColor;
const fontWeight = isTabActive ? 'bold' : 'normal';

Expand All @@ -137,7 +142,7 @@ const ScrollableTabBar = createReactClass({
onPress={() => onPressHandler(page)}
onLayout={onLayoutHandler}
>
<View style={[styles.tab, this.props.tabStyle, ]}>
<View style={[styles.tab, {backgroundColor, }, this.props.tabStyle, ]}>
<Text style={[{color: textColor, fontWeight, }, textStyle, ]}>
{name}
</Text>
Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ const ScrollableTabView = createReactClass({
if (!width || width <= 0 || Math.round(width) === Math.round(this.state.containerWidth)) {
return;
}

if (Platform.OS === 'ios') {
const containerWidthAnimatedValue = new Animated.Value(width);
// Need to call __makeNative manually to avoid a native animated bug. See
Expand Down Expand Up @@ -365,6 +365,12 @@ const ScrollableTabView = createReactClass({
if (this.props.tabBarBackgroundColor) {
tabBarProps.backgroundColor = this.props.tabBarBackgroundColor;
}
if (this.props.tabBarActiveBackgroundColor) {
tabBarProps.activeBackgroundColor = this.props.tabBarActiveBackgroundColor;
}
if (this.props.tabBarInactiveBackgroundColor) {
tabBarProps.inactiveBackgroundColor = this.props.tabBarInactiveBackgroundColor;
}
if (this.props.tabBarActiveTextColor) {
tabBarProps.activeTextColor = this.props.tabBarActiveTextColor;
}
Expand All @@ -377,6 +383,12 @@ const ScrollableTabView = createReactClass({
if (this.props.tabBarUnderlineStyle) {
tabBarProps.underlineStyle = this.props.tabBarUnderlineStyle;
}
if (this.props.tabBarTabStyle) {
tabBarProps.tabStyle = this.props.tabBarTabStyle;
}
if (this.props.tabBarContainerStyle) {
tabBarProps.style = this.props.tabBarContainerStyle;
}
if (overlayTabs) {
tabBarProps.style = {
position: 'absolute',
Expand Down