Skip to content
This repository was archived by the owner on Nov 27, 2022. It is now read-only.

Commit 5f6603f

Browse files
committed
fix: use label color from styles if specified. closes #1175
1 parent 90ff61f commit 5f6603f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/TabBarItem.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ export default class TabBarItem<T extends Route> extends React.Component<
8686
route,
8787
position,
8888
navigationState,
89-
renderLabel: renderLabelPassed,
89+
renderLabel: renderLabelCustom,
9090
renderIcon,
9191
renderBadge,
9292
getLabelText,
9393
getTestID,
9494
getAccessibilityLabel,
9595
getAccessible,
96-
activeColor = DEFAULT_ACTIVE_COLOR,
97-
inactiveColor = DEFAULT_INACTIVE_COLOR,
96+
activeColor: activeColorCustom,
97+
inactiveColor: inactiveColorCustom,
9898
pressColor,
9999
pressOpacity,
100100
labelStyle,
@@ -107,6 +107,21 @@ export default class TabBarItem<T extends Route> extends React.Component<
107107
const tabIndex = navigationState.routes.indexOf(route);
108108
const isFocused = navigationState.index === tabIndex;
109109

110+
const labelColorFromStyle = StyleSheet.flatten(labelStyle || {}).color;
111+
112+
const activeColor =
113+
activeColorCustom !== undefined
114+
? activeColorCustom
115+
: typeof labelColorFromStyle === 'string'
116+
? labelColorFromStyle
117+
: DEFAULT_ACTIVE_COLOR;
118+
const inactiveColor =
119+
inactiveColorCustom !== undefined
120+
? inactiveColorCustom
121+
: typeof labelColorFromStyle === 'string'
122+
? labelColorFromStyle
123+
: DEFAULT_INACTIVE_COLOR;
124+
110125
const activeOpacity = this.getActiveOpacity(
111126
position,
112127
navigationState.routes,
@@ -150,8 +165,8 @@ export default class TabBarItem<T extends Route> extends React.Component<
150165
}
151166

152167
const renderLabel =
153-
renderLabelPassed !== undefined
154-
? renderLabelPassed
168+
renderLabelCustom !== undefined
169+
? renderLabelCustom
155170
: ({ route, color }: { route: T; color: string }) => {
156171
const labelText = getLabelText({ route });
157172

0 commit comments

Comments
 (0)