Skip to content

Commit 96767fd

Browse files
committed
fix: change api
1 parent 2167733 commit 96767fd

File tree

6 files changed

+58
-34
lines changed

6 files changed

+58
-34
lines changed

docs/docs/docs/guides/standalone-usage.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,15 @@ Whether to enable haptic feedback on tab press.
133133
- Type: `boolean`
134134
- Default: `true`
135135

136+
137+
#### `tabLabelStyle`
138+
139+
Object containing styles for the tab label.
140+
Supported properties:
141+
- `fontFamily`
142+
- `fontSize`
143+
- `fontWeight`
144+
136145
#### `scrollEdgeAppearance` <Badge text="iOS" type="info" />
137146

138147
Appearance attributes for the tab bar when a scroll view is at the bottom.

docs/docs/docs/guides/usage-with-react-navigation.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ Tab views using the sidebar adaptable style have an appearance
149149

150150
Whether to enable haptic feedback on tab press. Defaults to true.
151151

152+
#### `tabLabelStyle`
153+
154+
Object containing styles for the tab label.
155+
156+
Supported properties:
157+
- `fontFamily`
158+
- `fontSize`
159+
- `fontWeight`
160+
161+
152162
### Options
153163

154164
The following options can be used to configure the screens in the navigator. These can be specified under `screenOptions` prop of `Tab.navigator` or `options` prop of `Tab.Screen`.

example/src/Examples/NativeBottomTabs.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ function NativeBottomTabs() {
1818
tabBarActiveTintColor="#F7DBA7"
1919
barTintColor="#1E2D2F"
2020
rippleColor="#F7DBA7"
21-
fontFamily="Avenir"
22-
fontSize={15}
21+
tabLabelStyle={{
22+
fontFamily: 'Avenir',
23+
fontSize: 15,
24+
}}
2325
activeIndicatorColor="#041F1E"
2426
screenListeners={{
2527
tabLongPress: (data) => {

ios/TabViewImpl.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ struct TabItem: View {
170170

171171
private func updateTabBarAppearance(props: TabViewProps, tabBar: UITabBar?) {
172172
guard let tabBar else { return }
173-
173+
174174
if props.scrollEdgeAppearance == "transparent" {
175175
configureTransparentAppearance(tabBar: tabBar, props: props)
176176
return
177177
}
178-
178+
179179
configureStandardAppearance(tabBar: tabBar, props: props)
180180
}
181181

@@ -186,11 +186,11 @@ private func createFontAttributes(
186186
inactiveTintColor: UIColor?
187187
) -> [NSAttributedString.Key: Any] {
188188
var attributes: [NSAttributedString.Key: Any] = [:]
189-
189+
190190
if let inactiveTintColor {
191191
attributes[.foregroundColor] = inactiveTintColor
192192
}
193-
193+
194194
if family != nil || weight != nil {
195195
attributes[.font] = RCTFont.update(
196196
nil,
@@ -204,33 +204,33 @@ private func createFontAttributes(
204204
} else {
205205
attributes[.font] = UIFont.boldSystemFont(ofSize: size)
206206
}
207-
207+
208208
return attributes
209209
}
210210

211211
private func configureTransparentAppearance(tabBar: UITabBar, props: TabViewProps) {
212212
tabBar.barTintColor = props.barTintColor
213213
tabBar.isTranslucent = props.translucent
214214
tabBar.unselectedItemTintColor = props.inactiveTintColor
215-
215+
216216
guard let items = tabBar.items else { return }
217-
218-
let fontSize = props.fontSize ?? 14
217+
218+
let fontSize = props.fontSize != nil ? CGFloat(props.fontSize!) : UIFont.smallSystemFontSize
219219
let attributes = createFontAttributes(
220-
size: CGFloat(fontSize),
220+
size: fontSize,
221221
family: props.fontFamily,
222222
weight: props.fontWeight,
223223
inactiveTintColor: props.inactiveTintColor
224224
)
225-
225+
226226
items.forEach { item in
227227
item.setTitleTextAttributes(attributes, for: .normal)
228228
}
229229
}
230230

231231
private func configureStandardAppearance(tabBar: UITabBar, props: TabViewProps) {
232232
let appearance = UITabBarAppearance()
233-
233+
234234
// Configure background
235235
switch props.scrollEdgeAppearance {
236236
case "opaque":
@@ -239,29 +239,29 @@ private func configureStandardAppearance(tabBar: UITabBar, props: TabViewProps)
239239
appearance.configureWithDefaultBackground()
240240
}
241241
appearance.backgroundColor = props.barTintColor
242-
242+
243243
// Configure item appearance
244244
let itemAppearance = UITabBarItemAppearance()
245245
let fontSize = props.fontSize != nil ? CGFloat(props.fontSize!) : UIFont.smallSystemFontSize
246-
246+
247247
let attributes = createFontAttributes(
248248
size: fontSize,
249249
family: props.fontFamily,
250250
weight: props.fontWeight,
251251
inactiveTintColor: props.inactiveTintColor
252252
)
253-
253+
254254
if let inactiveTintColor = props.inactiveTintColor {
255255
itemAppearance.normal.iconColor = inactiveTintColor
256256
}
257-
257+
258258
itemAppearance.normal.titleTextAttributes = attributes
259-
259+
260260
// Apply item appearance to all layouts
261261
appearance.stackedLayoutAppearance = itemAppearance
262262
appearance.inlineLayoutAppearance = itemAppearance
263263
appearance.compactInlineLayoutAppearance = itemAppearance
264-
264+
265265
// Apply final appearance
266266
tabBar.standardAppearance = appearance
267267
if #available(iOS 15.0, *) {

src/TabView.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,22 @@ interface Props<Route extends BaseRoute> {
123123
* Color of tab indicator. (Android only)
124124
*/
125125
activeIndicatorColor?: ColorValue;
126-
/**
127-
* Font family for the tab labels.
128-
*/
129-
fontFamily?: string;
130-
/**
131-
* Font weight for the tab labels.
132-
*/
133-
fontWeight?: string;
134-
/**
135-
* Font size for the tab labels.
136-
*/
137-
fontSize?: number;
126+
tabLabelStyle?: {
127+
/**
128+
* Font family for the tab labels.
129+
*/
130+
fontFamily?: string;
131+
132+
/**
133+
* Font weight for the tab labels.
134+
*/
135+
fontWeight?: string;
136+
137+
/**
138+
* Font size for the tab labels.
139+
*/
140+
fontSize?: number;
141+
};
138142
}
139143

140144
const ANDROID_MAX_TABS = 6;
@@ -160,6 +164,7 @@ const TabView = <Route extends BaseRoute>({
160164
getHidden = ({ route }: { route: Route }) => route.hidden,
161165
getActiveTintColor = ({ route }: { route: Route }) => route.activeTintColor,
162166
hapticFeedbackEnabled = true,
167+
tabLabelStyle,
163168
...props
164169
}: Props<Route>) => {
165170
// @ts-ignore
@@ -250,6 +255,7 @@ const TabView = <Route extends BaseRoute>({
250255
return (
251256
<TabViewAdapter
252257
{...props}
258+
{...tabLabelStyle}
253259
style={styles.fullWidth}
254260
items={items}
255261
icons={resolvedIconAssets}

src/types.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ export type BaseRoute = {
1414
unfocusedIcon?: ImageSourcePropType | AppleIcon;
1515
activeTintColor?: string;
1616
hidden?: boolean;
17-
fontFamily?: string;
18-
fontWeight?: string;
19-
fontSize?: number;
2017
};
2118

2219
export type NavigationState<Route extends BaseRoute> = {

0 commit comments

Comments
 (0)