Skip to content

add backgroundColor to tabBar #935

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

Merged
merged 4 commits into from
Sep 29, 2020
Merged
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
29 changes: 20 additions & 9 deletions src/components/tabController/TabBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {Code, Value, interpolate, block, set} = Reanimated;

const DEFAULT_HEIGHT = 48;
const INDICATOR_INSET = Spacings.s4;
const DEFAULT_BACKGROUND_COLOR = Colors.white;

const DEFAULT_LABEL_STYLE = {
...Typography.text80,
Expand Down Expand Up @@ -54,6 +55,10 @@ class TabBar extends PureComponent {
* Show Tab Bar bottom shadow
*/
enableShadow: PropTypes.bool,
/**
* custom shadow style
*/
shadowStyle: ViewPropTypes.style,
// /**
// * The minimum number of tabs to render in scroll mode
// */
Expand Down Expand Up @@ -95,6 +100,10 @@ class TabBar extends PureComponent {
* Apply background color on press for TouchableOpacity
*/
activeBackgroundColor: PropTypes.string,
/**
* The TabBar background Color
*/
backgroundColor: PropTypes.string,
/**
* The TabBar container width
*/
Expand All @@ -107,7 +116,9 @@ class TabBar extends PureComponent {

static defaultProps = {
labelStyle: DEFAULT_LABEL_STYLE,
selectedLabelStyle: DEFAULT_SELECTED_LABEL_STYLE
selectedLabelStyle: DEFAULT_SELECTED_LABEL_STYLE,
backgroundColor: DEFAULT_BACKGROUND_COLOR

// containerWidth: Constants.screenWidth
};

Expand Down Expand Up @@ -384,18 +395,22 @@ class TabBar extends PureComponent {
return block(nodes);
};

getShadowStyle() {
const {enableShadow, shadowStyle} = this.props;
return enableShadow && (shadowStyle || styles.containerShadow);
}

render() {
const {height, enableShadow, containerStyle, testID} = this.props;
const {height, containerStyle, testID, backgroundColor} = this.props;
const {itemsWidths, scrollEnabled, fadeLeft, fadeRight} = this.state;
return (
<View
style={[styles.container, enableShadow && styles.containerShadow, {width: this.containerWidth}, containerStyle]}
style={[styles.container, this.getShadowStyle(), {width: this.containerWidth}, containerStyle]}
>
<ScrollView
ref={this.tabBar}
horizontal
showsHorizontalScrollIndicator={false}
style={styles.tabBarScroll}
contentContainerStyle={{minWidth: this.containerWidth}}
scrollEnabled={scrollEnabled}
onScroll={this.onScroll}
Expand All @@ -404,7 +419,7 @@ class TabBar extends PureComponent {
snapToOffsets={this.getSnapBreakpoints()}
decelerationRate={'fast'}
>
<View style={[styles.tabBar, height && {height}, {paddingHorizontal: this.centerOffset}]}>
<View style={[styles.tabBar, height && {height}, {paddingHorizontal: this.centerOffset, backgroundColor}]}>
{this.renderTabBarItems()}
</View>
{this.renderSelectedIndicator()}
Expand All @@ -423,14 +438,10 @@ const styles = StyleSheet.create({
},
tabBar: {
flex: 1,
backgroundColor: Colors.white,
height: DEFAULT_HEIGHT,
flexDirection: 'row',
justifyContent: 'space-between'
},
tabBarScroll: {
backgroundColor: Colors.white
},
tabBarScrollContent: {
minWidth: Constants.screenWidth
},
Expand Down