Skip to content

Commit 7615de1

Browse files
add backgroundColor to tabBar (#935)
* add backgroundColor to tabBar * tabBar's shadowStyle * shadow style Co-authored-by: Ethan Sharabi <[email protected]>
1 parent c6a178c commit 7615de1

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/components/tabController/TabBar.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const {Code, Value, interpolate, block, set} = Reanimated;
2020

2121
const DEFAULT_HEIGHT = 48;
2222
const INDICATOR_INSET = Spacings.s4;
23+
const DEFAULT_BACKGROUND_COLOR = Colors.white;
2324

2425
const DEFAULT_LABEL_STYLE = {
2526
...Typography.text80,
@@ -54,6 +55,10 @@ class TabBar extends PureComponent {
5455
* Show Tab Bar bottom shadow
5556
*/
5657
enableShadow: PropTypes.bool,
58+
/**
59+
* custom shadow style
60+
*/
61+
shadowStyle: ViewPropTypes.style,
5762
// /**
5863
// * The minimum number of tabs to render in scroll mode
5964
// */
@@ -95,6 +100,10 @@ class TabBar extends PureComponent {
95100
* Apply background color on press for TouchableOpacity
96101
*/
97102
activeBackgroundColor: PropTypes.string,
103+
/**
104+
* The TabBar background Color
105+
*/
106+
backgroundColor: PropTypes.string,
98107
/**
99108
* The TabBar container width
100109
*/
@@ -107,7 +116,9 @@ class TabBar extends PureComponent {
107116

108117
static defaultProps = {
109118
labelStyle: DEFAULT_LABEL_STYLE,
110-
selectedLabelStyle: DEFAULT_SELECTED_LABEL_STYLE
119+
selectedLabelStyle: DEFAULT_SELECTED_LABEL_STYLE,
120+
backgroundColor: DEFAULT_BACKGROUND_COLOR
121+
111122
// containerWidth: Constants.screenWidth
112123
};
113124

@@ -384,18 +395,22 @@ class TabBar extends PureComponent {
384395
return block(nodes);
385396
};
386397

398+
getShadowStyle() {
399+
const {enableShadow, shadowStyle} = this.props;
400+
return enableShadow && (shadowStyle || styles.containerShadow);
401+
}
402+
387403
render() {
388-
const {height, enableShadow, containerStyle, testID} = this.props;
404+
const {height, containerStyle, testID, backgroundColor} = this.props;
389405
const {itemsWidths, scrollEnabled, fadeLeft, fadeRight} = this.state;
390406
return (
391407
<View
392-
style={[styles.container, enableShadow && styles.containerShadow, {width: this.containerWidth}, containerStyle]}
408+
style={[styles.container, this.getShadowStyle(), {width: this.containerWidth}, containerStyle]}
393409
>
394410
<ScrollView
395411
ref={this.tabBar}
396412
horizontal
397413
showsHorizontalScrollIndicator={false}
398-
style={styles.tabBarScroll}
399414
contentContainerStyle={{minWidth: this.containerWidth}}
400415
scrollEnabled={scrollEnabled}
401416
onScroll={this.onScroll}
@@ -404,7 +419,7 @@ class TabBar extends PureComponent {
404419
snapToOffsets={this.getSnapBreakpoints()}
405420
decelerationRate={'fast'}
406421
>
407-
<View style={[styles.tabBar, height && {height}, {paddingHorizontal: this.centerOffset}]}>
422+
<View style={[styles.tabBar, height && {height}, {paddingHorizontal: this.centerOffset, backgroundColor}]}>
408423
{this.renderTabBarItems()}
409424
</View>
410425
{this.renderSelectedIndicator()}
@@ -423,14 +438,10 @@ const styles = StyleSheet.create({
423438
},
424439
tabBar: {
425440
flex: 1,
426-
backgroundColor: Colors.white,
427441
height: DEFAULT_HEIGHT,
428442
flexDirection: 'row',
429443
justifyContent: 'space-between'
430444
},
431-
tabBarScroll: {
432-
backgroundColor: Colors.white
433-
},
434445
tabBarScrollContent: {
435446
minWidth: Constants.screenWidth
436447
},

0 commit comments

Comments
 (0)