Skip to content

Commit 9612726

Browse files
committed
feat: add support for top border color on iOS
1 parent eda6b67 commit 9612726

File tree

9 files changed

+41
-1
lines changed

9 files changed

+41
-1
lines changed

apps/example/src/Examples/TintColors.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default function TintColorsExample() {
5454
tabBarActiveTintColor="red"
5555
tabBarInactiveTintColor="orange"
5656
scrollEdgeAppearance="default"
57+
borderColor="red"
5758
/>
5859
);
5960
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ Whether the tab bar is translucent.
172172
Color of tab indicator.
173173
- Type: `ColorValue`
174174

175+
#### `borderColor` <Badge text="iOS" type="info" />
176+
177+
Color of the tab bar top border.
178+
- Type: `ColorValue`
179+
175180
### Route Configuration
176181

177182
Each route in the `routes` array can have the following properties:

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

+5
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ Available options:
139139
It's recommended to use `transparent` or `opaque` without lazy loading as the tab bar background flashes when a view is rendered lazily.
140140
:::
141141

142+
#### `borderColor` <Badge text="iOS" type="info" />
143+
144+
Color of the tab bar top border.
145+
- Type: `ColorValue`
146+
142147
#### `sidebarAdaptable` <Badge text="iOS" type="info" />
143148

144149
A tab bar style that adapts to each platform.

packages/react-native-bottom-tabs/ios/Fabric/RCTTabViewComponentView.mm

+5-1
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,14 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
142142
_tabViewProvider.inactiveTintColor = RCTUIColorFromSharedColor(newViewProps.inactiveTintColor);
143143
}
144144

145+
if (oldViewProps.borderColor != newViewProps.borderColor) {
146+
_tabViewProvider.borderColor = RCTUIColorFromSharedColor(newViewProps.borderColor);
147+
}
148+
145149
if (oldViewProps.hapticFeedbackEnabled != newViewProps.hapticFeedbackEnabled) {
146150
_tabViewProvider.hapticFeedbackEnabled = newViewProps.hapticFeedbackEnabled;
147151
}
148-
152+
149153
if (oldViewProps.fontSize != newViewProps.fontSize) {
150154
_tabViewProvider.fontSize = [NSNumber numberWithInt:newViewProps.fontSize];
151155
}

packages/react-native-bottom-tabs/ios/RCTTabViewViewManager.mm

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ @implementation RCTTabView
3333
RCT_EXPORT_VIEW_PROPERTY(barTintColor, UIColor)
3434
RCT_EXPORT_VIEW_PROPERTY(activeTintColor, UIColor)
3535
RCT_EXPORT_VIEW_PROPERTY(inactiveTintColor, UIColor)
36+
RCT_EXPORT_VIEW_PROPERTY(borderColor, UIColor)
3637
RCT_EXPORT_VIEW_PROPERTY(hapticFeedbackEnabled, BOOL)
3738
RCT_EXPORT_VIEW_PROPERTY(fontFamily, NSString)
3839
RCT_EXPORT_VIEW_PROPERTY(fontWeight, NSString)

packages/react-native-bottom-tabs/ios/TabViewImpl.swift

+13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class TabViewProps: ObservableObject {
2222
@Published var ignoresTopSafeArea: Bool = true
2323
@Published var disablePageAnimations: Bool = false
2424
@Published var hapticFeedbackEnabled: Bool = false
25+
@Published var borderColor: UIColor?
2526
@Published var fontSize: Int?
2627
@Published var fontFamily: String?
2728
@Published var fontWeight: String?
@@ -241,6 +242,11 @@ private func configureTransparentAppearance(tabBar: UITabBar, props: TabViewProp
241242
items.forEach { item in
242243
item.setTitleTextAttributes(attributes, for: .normal)
243244
}
245+
246+
if let borderColor = props.borderColor {
247+
tabBar.layer.borderWidth = 0.5
248+
tabBar.layer.borderColor = borderColor.cgColor
249+
}
244250
}
245251

246252
private func configureStandardAppearance(tabBar: UITabBar, props: TabViewProps) {
@@ -281,6 +287,10 @@ private func configureStandardAppearance(tabBar: UITabBar, props: TabViewProps)
281287
appearance.inlineLayoutAppearance = itemAppearance
282288
appearance.compactInlineLayoutAppearance = itemAppearance
283289

290+
if let borderColor = props.borderColor {
291+
appearance.shadowColor = borderColor
292+
}
293+
284294
// Apply final appearance
285295
tabBar.standardAppearance = appearance
286296
if #available(iOS 15.0, *) {
@@ -364,6 +374,9 @@ extension View {
364374
.onChange(of: props.fontWeight) { newValue in
365375
updateTabBarAppearance(props: props, tabBar: tabBar)
366376
}
377+
.onChange(of: props.borderColor) { newValue in
378+
updateTabBarAppearance(props: props, tabBar: tabBar)
379+
}
367380
}
368381

369382
@ViewBuilder

packages/react-native-bottom-tabs/ios/TabViewProvider.swift

+6
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ public final class TabInfo: NSObject {
136136
}
137137
}
138138

139+
@objc public var borderColor: UIColor? {
140+
didSet {
141+
props.borderColor = borderColor
142+
}
143+
}
144+
139145
@objc public var fontFamily: NSString? {
140146
didSet {
141147
props.fontFamily = fontFamily as? String

packages/react-native-bottom-tabs/src/TabView.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ interface Props<Route extends BaseRoute> {
5151
* Describes the appearance attributes for the tabBar to use when an observable scroll view is scrolled to the bottom. (iOS only)
5252
*/
5353
scrollEdgeAppearance?: 'default' | 'opaque' | 'transparent';
54+
/**
55+
* Color of the tab bar top border.
56+
*/
57+
borderColor?: ColorValue;
5458
/**
5559
* Active tab color.
5660
*/

packages/react-native-bottom-tabs/src/TabViewNativeComponent.ts

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export interface TabViewProps extends ViewProps {
5050
ignoresTopSafeArea?: WithDefault<boolean, true>;
5151
disablePageAnimations?: boolean;
5252
activeIndicatorColor?: ColorValue;
53+
borderColor?: ColorValue;
5354
hapticFeedbackEnabled?: boolean;
5455
fontFamily?: string;
5556
fontWeight?: string;

0 commit comments

Comments
 (0)