Skip to content

Commit 926c361

Browse files
authored
feat(Android, Tabs): add prop to hide the tab bar (#3344)
## Description Adds support for `tabBarHidden` prop in `TabsHost`. https://github.com/user-attachments/assets/35fccc4b-e457-4f53-9a1a-17c3ee188fba ## Changes - handle `tabBarHidden` prop on Android - update SAV interface insets on tab bar visibility change ## Test code and steps to reproduce Run `TestBottomTabs`, add `tabBarHidden` prop, observe dynamic changes. ## Checklist - [x] Included code example that can be used to test this change - [x] Updated TS types - [x] Updated documentation: <!-- For adding new props to native-stack --> - [ ] https://github.com/software-mansion/react-native-screens/blob/main/guides/GUIDE_FOR_LIBRARY_AUTHORS.md - [ ] https://github.com/software-mansion/react-native-screens/blob/main/native-stack/README.md - [ ] https://github.com/software-mansion/react-native-screens/blob/main/src/types.tsx - [ ] https://github.com/software-mansion/react-native-screens/blob/main/src/native-stack/types.tsx - [x] Ensured that CI passes
1 parent b71c766 commit 926c361

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

android/src/main/java/com/swmansion/rnscreens/gamma/tabs/TabsHost.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ class TabsHost(
193193
updateNavigationMenuIfNeeded(oldValue, newValue)
194194
}
195195

196+
var tabBarHidden: Boolean by Delegates.observable(false) { _, oldValue, newValue ->
197+
if (newValue != oldValue) {
198+
updateInterfaceInsets()
199+
updateNavigationMenuIfNeeded(oldValue, newValue)
200+
}
201+
}
202+
196203
private fun <T> updateNavigationMenuIfNeeded(
197204
oldValue: T,
198205
newValue: T,
@@ -491,9 +498,15 @@ class TabsHost(
491498
val newHeight = bottom - top
492499

493500
if (newHeight != oldHeight) {
494-
interfaceInsetsChangeListener?.apply {
495-
this.onInterfaceInsetsChange(EdgeInsets(0.0f, 0.0f, 0.0f, newHeight.toFloat()))
496-
}
501+
updateInterfaceInsets(newHeight)
502+
}
503+
}
504+
505+
private fun updateInterfaceInsets(newHeight: Int? = null) {
506+
val height = if (tabBarHidden) 0 else (newHeight ?: bottomNavigationView.height)
507+
508+
interfaceInsetsChangeListener?.apply {
509+
this.onInterfaceInsetsChange(EdgeInsets(0.0f, 0.0f, 0.0f, height.toFloat()))
497510
}
498511
}
499512

android/src/main/java/com/swmansion/rnscreens/gamma/tabs/TabsHostAppearanceApplicator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TabsHostAppearanceApplicator(
2626
}
2727

2828
fun updateSharedAppearance(tabsHost: TabsHost) {
29-
bottomNavigationView.isVisible = true
29+
bottomNavigationView.isVisible = !tabsHost.tabBarHidden
3030
bottomNavigationView.setBackgroundColor(
3131
tabsHost.tabBarBackgroundColor
3232
?: resolveColorAttr(com.google.android.material.R.attr.colorSurfaceContainer),

android/src/main/java/com/swmansion/rnscreens/gamma/tabs/TabsHostViewManager.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,13 @@ class TabsHostViewManager :
142142
value: String?,
143143
) = Unit
144144

145+
@ReactProp(name = "tabBarHidden")
145146
override fun setTabBarHidden(
146147
view: TabsHost,
147148
value: Boolean,
148-
) = Unit
149+
) {
150+
view.tabBarHidden = value
151+
}
149152

150153
// Android additional
151154

src/components/bottom-tabs/BottomTabs.types.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ export interface BottomTabsProps extends ViewProps {
3838
) => void;
3939
// #endregion Events
4040

41+
// #region General
42+
/**
43+
* @summary Hides the tab bar.
44+
*
45+
* @default false
46+
*/
47+
tabBarHidden?: boolean;
48+
// #endregion General
49+
4150
// #region Android-only appearance
4251
/**
4352
* @summary Specifies the background color for the entire tab bar.
@@ -204,14 +213,6 @@ export interface BottomTabsProps extends ViewProps {
204213
* @supported iOS 18 or higher
205214
*/
206215
tabBarControllerMode?: TabBarControllerMode;
207-
/**
208-
* @summary Hides the tab bar.
209-
*
210-
* @default false
211-
*
212-
* @platform ios
213-
*/
214-
tabBarHidden?: boolean;
215216
// #endregion iOS-only appearance
216217

217218
// #region Experimental support

0 commit comments

Comments
 (0)