Skip to content

Commit 35d21a0

Browse files
authored
TabBar - Adding 'backgroundColor' prop (#917)
1 parent 54d2073 commit 35d21a0

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

demo/src/screens/componentScreens/TabBarScreen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default class TabBarScreen extends Component {
175175
label={`Change index: ${this.state.selectedIndex}`}
176176
onPress={this.changeIndex}
177177
/>
178-
<TabBar style={styles.tabbar} selectedIndex={this.state.selectedIndex} enableShadow>
178+
<TabBar style={styles.tabbar} selectedIndex={this.state.selectedIndex} enableShadow backgroundColor={Colors.green70}>
179179
<TabBar.Item label="LONG LABEL"/>
180180
<TabBar.Item label="ACTIVE"/>
181181
<TabBar.Item label="INACTIVE"/>

src/components/tabBar/index.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export type TabBarProps = BaseComponentInjectedProps & ViewPropTypes & {
4242
* custom style for the selected indicator
4343
*/
4444
indicatorStyle?: ViewStyle,
45+
/**
46+
* The background color
47+
*/
48+
backgroundColor: string,
4549
/**
4650
* Tab Bar height
4751
*/
@@ -77,7 +81,8 @@ class TabBar extends Component<TabBarProps, State> {
7781
static displayName = 'TabBar';
7882

7983
static defaultProps = {
80-
selectedIndex: 0
84+
selectedIndex: 0,
85+
backgroundColor: DEFAULT_BACKGROUND_COLOR
8186
};
8287

8388
static Item: typeof TabBarItem;
@@ -92,7 +97,7 @@ class TabBar extends Component<TabBarProps, State> {
9297
};
9398
}
9499

95-
styles = createStyles();
100+
styles = createStyles(this.props);
96101
scrollContainerWidth: number = Constants.screenWidth;
97102
scrollContentWidth = 0;
98103
contentOffset: any = {x: 0, y: 0};
@@ -247,7 +252,7 @@ class TabBar extends Component<TabBarProps, State> {
247252
}
248253

249254
renderTabBar() {
250-
const {height} = this.props;
255+
const {height, backgroundColor} = this.props;
251256
const {scrollEnabled} = this.state;
252257
const containerHeight = height || DEFAULT_HEIGHT;
253258

@@ -268,7 +273,7 @@ class TabBar extends Component<TabBarProps, State> {
268273
{this.renderChildren()}
269274
</View>
270275
</ScrollView>
271-
{this.renderGradient(containerHeight, DEFAULT_BACKGROUND_COLOR)}
276+
{this.renderGradient(containerHeight, backgroundColor)}
272277
</View>
273278
);
274279
}
@@ -312,7 +317,7 @@ class TabBar extends Component<TabBarProps, State> {
312317
}
313318
}
314319

315-
function createStyles() {
320+
function createStyles({backgroundColor = DEFAULT_BACKGROUND_COLOR}) {
316321
return StyleSheet.create({
317322
container: {
318323
zIndex: 100
@@ -334,7 +339,7 @@ function createStyles() {
334339
tabBar: {
335340
flex: 1,
336341
height: DEFAULT_HEIGHT,
337-
backgroundColor: DEFAULT_BACKGROUND_COLOR
342+
backgroundColor
338343
},
339344
shadowImage: {
340345
width: '100%'

0 commit comments

Comments
 (0)