Skip to content
This repository was archived by the owner on Feb 25, 2020. It is now read-only.

Commit 3165ede

Browse files
committed
Add theme support
1 parent 9ac7b3d commit 3165ede

3 files changed

Lines changed: 67 additions & 9 deletions

File tree

example/App.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import {
77
} from 'react-navigation';
88
import { List, Divider } from 'react-native-paper';
99

10-
// Unclear why this isn't getitng picked up :O
11-
// eslint-disable-next-line import/named
10+
// eslint-disable-next-line import/no-unresolved
1211
import { Assets as StackAssets } from 'react-navigation-stack';
1312

1413
import SimpleTabs from './src/SimpleTabs';

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-navigation-material-bottom-tabs",
3-
"version": "1.0.0-alpha.6",
3+
"version": "1.1.1",
44
"description": "Material Bottom Tab Navigation component for React Navigation",
55
"main": "dist/index.js",
66
"files": [
@@ -44,7 +44,7 @@
4444
"dependencies": {
4545
"hoist-non-react-statics": "^2.5.0",
4646
"prop-types": "^15.6.0",
47-
"react-navigation-tabs": "1.0.0-alpha.4"
47+
"react-navigation-tabs": "~1.2.0"
4848
},
4949
"devDependencies": {
5050
"@expo/vector-icons": "^6.2.0",

src/navigators/createMaterialBottomTabNavigator.js

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,79 @@
11
/* @flow */
22

33
import * as React from 'react';
4+
import { ThemeContext } from '@react-navigation/core';
45
import { BottomNavigation } from 'react-native-paper';
56
import { createTabNavigator, type InjectedProps } from 'react-navigation-tabs';
67

78
type Props = InjectedProps & {
89
activeTintColor?: string,
10+
activeTintColorLight?: string,
11+
activeTintColorDark?: string,
912
inactiveTintColor?: string,
13+
inactiveTintColorLight?: string,
14+
inactiveTintColorDark?: string,
15+
// todo: once this is properly typed, add other types for themed props
1016
};
1117

1218
class BottomNavigationView extends React.Component<Props> {
19+
static contextType = ThemeContext;
20+
1321
_getColor = ({ route }) => {
1422
const { descriptors } = this.props;
1523
const descriptor = descriptors[route.key];
1624
const options = descriptor.options;
1725

18-
return options.tabBarColor;
26+
if (this.context === 'dark' && options.tabBarColorDark) {
27+
return options.tabBarColorDark;
28+
} else if (this.tabBarColorLight) {
29+
return options.tabBarColorLight;
30+
} else {
31+
return options.tabBarColor;
32+
}
33+
};
34+
35+
_getActiveTintColor = () => {
36+
let {
37+
activeTintColor,
38+
activeTintColorLight,
39+
activeTintColorDark,
40+
} = this.props;
41+
42+
if (this.context === 'dark' && activeTintColorDark) {
43+
return activeTintColorDark;
44+
} else if (activeTintColorLight) {
45+
return activeTintColorLight;
46+
} else {
47+
return activeTintColor;
48+
}
49+
};
50+
51+
_getInactiveTintColor = () => {
52+
let {
53+
inactiveTintColor,
54+
inactiveTintColorLight,
55+
inactiveTintColorDark,
56+
} = this.props;
57+
58+
if (this.context === 'dark' && inactiveTintColorDark) {
59+
return inactiveTintColorDark;
60+
} else if (inactiveTintColorLight) {
61+
return inactiveTintColorLight;
62+
} else {
63+
return inactiveTintColor;
64+
}
65+
};
66+
67+
_getBarStyle = () => {
68+
let { barStyle, barStyleLight, barStyleDark } = this.props;
69+
70+
if (this.context === 'dark' && barStyleDark) {
71+
return barStyleDark;
72+
} else if (barStyleLight) {
73+
return barStyleLight;
74+
} else {
75+
return barStyle;
76+
}
1977
};
2078

2179
_isVisible() {
@@ -32,15 +90,16 @@ class BottomNavigationView extends React.Component<Props> {
3290

3391
render() {
3492
const {
35-
activeTintColor,
36-
inactiveTintColor,
3793
navigation,
3894
// eslint-disable-next-line no-unused-vars
3995
descriptors,
40-
barStyle,
4196
...rest
4297
} = this.props;
4398

99+
const activeTintColor = this._getActiveTintColor();
100+
const inactiveTintColor = this._getInactiveTintColor();
101+
const barStyle = this._getBarStyle();
102+
44103
const isVisible = this._isVisible();
45104
const extraStyle =
46105
typeof isVisible === 'boolean'
@@ -50,9 +109,9 @@ class BottomNavigationView extends React.Component<Props> {
50109
return (
51110
<BottomNavigation
52111
// Pass these for backward compaibility
112+
{...rest}
53113
activeColor={activeTintColor}
54114
inactiveColor={inactiveTintColor}
55-
{...rest}
56115
renderIcon={this._renderIcon}
57116
barStyle={[barStyle, extraStyle]}
58117
navigationState={navigation.state}

0 commit comments

Comments
 (0)