Skip to content

Commit 5a98b14

Browse files
committed
support different fontFamily between selected and non-selected TabBarItem
1 parent 8d0b1bf commit 5a98b14

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/components/tabController/TabBarItem.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,29 @@ export default class TabBarItem extends PureComponent {
171171

172172
const labelStyle = this.props.labelStyle;
173173
const selectedLabelStyle = this.props.selectedLabelStyle;
174+
let fontWeight, letterSpacing, fontFamily;
175+
176+
if (labelStyle.fontWeight || selectedLabelStyle.fontWeight) {
177+
fontWeight = cond(and(eq(targetPage, index), defined(itemWidth)),
178+
selectedLabelStyle.fontWeight || 'normal',
179+
labelStyle.fontWeight || 'normal');
180+
}
181+
182+
if (labelStyle.letterSpacing || selectedLabelStyle.letterSpacing) {
183+
letterSpacing = cond(and(eq(targetPage, index), defined(itemWidth)),
184+
selectedLabelStyle.letterSpacing || 0,
185+
labelStyle.letterSpacing || 0);
186+
}
187+
188+
if (labelStyle.fontFamily || selectedLabelStyle.fontFamily) {
189+
fontFamily = cond(and(eq(targetPage, index), defined(itemWidth)),
190+
selectedLabelStyle.fontFamily,
191+
labelStyle.fontFamily);
192+
}
174193

175-
const fontWeight = cond(and(eq(targetPage, index), defined(itemWidth)),
176-
selectedLabelStyle.fontWeight || 'normal',
177-
labelStyle.fontWeight || 'normal');
178-
const letterSpacing = cond(and(eq(targetPage, index), defined(itemWidth)),
179-
selectedLabelStyle.letterSpacing || 0,
180-
labelStyle.letterSpacing || 0);
181-
182194
const inactiveColor = labelColor || DEFAULT_LABEL_COLOR;
183195
const activeColor = !ignore ? selectedLabelColor || DEFAULT_SELECTED_LABEL_COLOR : inactiveColor;
184196

185-
// const color = cond(eq(currentPage, index),
186-
// processColor(activeColor),
187-
// processColor(ignore ? activeColor : inactiveColor),);
188-
189197
// Animated color
190198
const color = interpolateColor(currentPage, {
191199
inputRange: [index - 1, index, index + 1],
@@ -194,11 +202,12 @@ export default class TabBarItem extends PureComponent {
194202

195203
return [
196204
labelStyle,
197-
{
205+
_.omitBy({
206+
fontFamily,
198207
fontWeight,
199208
letterSpacing,
200209
color
201-
}
210+
}, _.isUndefined)
202211
];
203212
}
204213

0 commit comments

Comments
 (0)