11/* @flow */
22
33import * as React from 'react' ;
4+ import { ThemeContext } from '@react-navigation/core' ;
45import { BottomNavigation } from 'react-native-paper' ;
56import { createTabNavigator , type InjectedProps } from 'react-navigation-tabs' ;
67
78type 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
1218class 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