Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tall-donkeys-resize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-native-bottom-tabs': patch
---

Fix Android content not resizing when the tab bar visibility changes (`tabBarHidden`). The layout listener compared the container bounds, which stay the same when only the tab bar is hidden or shown, so the new `layoutHolder` size was never reported to JS and the content kept its stale height.
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,33 @@ class ReactBottomNavigationView(context: Context) : LinearLayout(context) {
uiModeConfiguration = resources.configuration.uiMode

post {
addOnLayoutChangeListener { _, left, top, right, bottom,
addOnLayoutChangeListener { _, _, _, _, _,
_, _, _, _ ->
val newWidth = right - left
val newHeight = bottom - top

// Notify about tab bar height.
onTabBarMeasuredListener?.invoke(Utils.convertPixelsToDp(context, bottomNavigation.height).toInt())

if (newWidth != lastReportedSize?.width || newHeight != lastReportedSize?.height) {
val dpWidth = Utils.convertPixelsToDp(context, layoutHolder.width)
val dpHeight = Utils.convertPixelsToDp(context, layoutHolder.height)

onNativeLayoutListener?.invoke(dpWidth, dpHeight)
lastReportedSize = Size(newWidth, newHeight)
}
reportLayoutHolderSizeIfChanged()
}
// When only the tab bar visibility changes (tabBarHidden), the container keeps
// its bounds so the listener above never fires — only layoutHolder grows or
// shrinks. Observe layoutHolder itself so the new content size reaches JS.
layoutHolder.addOnLayoutChangeListener { _, _, _, _, _,
_, _, _, _ ->
reportLayoutHolderSizeIfChanged()
}
}
}

private fun reportLayoutHolderSizeIfChanged() {
val newWidth = layoutHolder.width
val newHeight = layoutHolder.height

if (newWidth != lastReportedSize?.width || newHeight != lastReportedSize?.height) {
val dpWidth = Utils.convertPixelsToDp(context, newWidth)
val dpHeight = Utils.convertPixelsToDp(context, newHeight)

onNativeLayoutListener?.invoke(dpWidth, dpHeight)
lastReportedSize = Size(newWidth, newHeight)
}
}

Expand Down