Skip to content

Commit f915225

Browse files
authored
fix: properly handle labeled false on iOS (#291)
1 parent afc5a3f commit f915225

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

.changeset/dirty-kids-attack.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'react-native-bottom-tabs': patch
3+
---
4+
5+
fix: properly handle labeled={false} on iOS

apps/example/src/App.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ const FourTabsActiveIndicatorColor = () => {
6666
return <FourTabs activeIndicatorColor={'#87CEEB'} />;
6767
};
6868

69+
const UnlabeledTabs = () => {
70+
return <LabeledTabs showLabels={false} />;
71+
};
72+
6973
const examples = [
7074
{
7175
component: ThreeTabs,
@@ -77,7 +81,8 @@ const examples = [
7781
name: 'SF Symbols',
7882
screenOptions: { headerShown: false },
7983
},
80-
{ component: LabeledTabs, name: 'Labeled Tabs', platform: 'android' },
84+
{ component: LabeledTabs, name: 'Labeled Tabs' },
85+
{ component: UnlabeledTabs, name: 'Unlabeled Tabs' },
8186
{
8287
component: NativeBottomTabsEmbeddedStacks,
8388
name: 'Embedded stacks',

apps/example/src/Examples/Labeled.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { Albums } from '../Screens/Albums';
55
import { Contacts } from '../Screens/Contacts';
66
import { Chat } from '../Screens/Chat';
77

8-
export default function LabeledTabs() {
8+
export default function LabeledTabs({
9+
showLabels = true,
10+
}: {
11+
showLabels: boolean;
12+
}) {
913
const [index, setIndex] = useState(0);
1014
const [routes] = useState([
1115
{
@@ -41,7 +45,7 @@ export default function LabeledTabs() {
4145

4246
return (
4347
<TabView
44-
labeled
48+
labeled={showLabels}
4549
navigationState={{ index, routes }}
4650
onIndexChange={setIndex}
4751
renderScene={renderScene}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TabViewProps: ObservableObject {
99
@Published var selectedPage: String?
1010
@Published var icons: [Int: PlatformImage] = [:]
1111
@Published var sidebarAdaptable: Bool?
12-
@Published var labeled: Bool?
12+
@Published var labeled: Bool = false
1313
@Published var scrollEdgeAppearance: String?
1414
@Published var barTintColor: PlatformColor?
1515
@Published var activeTintColor: PlatformColor?

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public final class TabInfo: NSObject {
7979
}
8080
}
8181

82-
@objc public var labeled: Bool = true {
82+
@objc public var labeled: Bool = false {
8383
didSet {
8484
props.labeled = labeled
8585
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ const TabView = <Route extends BaseRoute>({
175175
getActiveTintColor = ({ route }: { route: Route }) => route.activeTintColor,
176176
getTestID = ({ route }: { route: Route }) => route.testID,
177177
hapticFeedbackEnabled = false,
178+
// Android's native behavior is to show labels when there are less than 4 tabs. We leave it as undefined to use the platform default behavior.
179+
labeled = Platform.OS !== 'android' ? true : undefined,
178180
tabBar: renderCustomTabBar,
179181
tabBarStyle,
180182
tabLabelStyle,
@@ -300,6 +302,7 @@ const TabView = <Route extends BaseRoute>({
300302
inactiveTintColor={inactiveTintColor}
301303
barTintColor={tabBarStyle?.backgroundColor}
302304
rippleColor={rippleColor}
305+
labeled={labeled}
303306
>
304307
{trimmedRoutes.map((route) => {
305308
if (getLazy({ route }) !== false && !loaded.includes(route.key)) {

0 commit comments

Comments
 (0)