diff --git a/.changeset/tall-donkeys-resize.md b/.changeset/tall-donkeys-resize.md new file mode 100644 index 00000000..0e3ab9ec --- /dev/null +++ b/.changeset/tall-donkeys-resize.md @@ -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. diff --git a/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabView.kt b/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabView.kt index 3c3d4bdb..f7fb62f0 100644 --- a/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabView.kt +++ b/packages/react-native-bottom-tabs/android/src/main/java/com/rcttabview/RCTTabView.kt @@ -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) } }