Skip to content

fix: measure custom tab bar height with onLayout - #559

Open
mrpmohiburrahman wants to merge 1 commit into
callstack:mainfrom
mrpmohiburrahman:fix/custom-tab-bar-height-absolute-position
Open

mrpmohiburrahman wants to merge 1 commit into
callstack:mainfrom
mrpmohiburrahman:fix/custom-tab-bar-height-absolute-position

Conversation

@mrpmohiburrahman

Copy link
Copy Markdown
Contributor

PR Description

Bug fix. Closes #380.

TabView measured the custom tab bar by calling .measure() on the wrapper View in a useLayoutEffect. Absolutely positioned children don't contribute to their parent's measured size, so for a renderCustomTabBar that returns an absolutely positioned element the wrapper measured 0 and useBottomTabBarHeight() returned 0.

Changes:

  • Removed the ref + useLayoutEffect + .measure() logic.
  • The element returned by renderCustomTabBar is now cloned with an injected onLayout (any onLayout the element already declares is still called), and the wrapper keeps its own onLayout.
  • The reported height is the larger of the two, so regular tab bars keep the wrapper measurement and absolutely positioned ones get the element's own height. Non-element return values (fragments, arrays) still fall back to the wrapper, preserving the previous behaviour.

How to test?

Render a TabView with a custom tab bar that is absolutely positioned, and read the height from a screen:

<TabView
  renderCustomTabBar={() => (
    <View style={{ position: 'absolute', bottom: 0, width: '100%', height: 60, backgroundColor: 'white' }} />
  )}
  // ...
/>
const height = useBottomTabBarHeight(); // 0 before, 60 after

A non-absolutely-positioned custom tab bar should keep reporting the same height as before.

Screenshots

N/A — no visual change to the library itself; the fix affects the value reported by useBottomTabBarHeight().

Absolutely positioned children do not contribute to their parent's
measured size, so measuring the wrapper View reported a height of 0 and
useBottomTabBarHeight returned 0 for absolutely positioned custom tab
bars.

Inject onLayout into the element returned by renderCustomTabBar (keeping
any onLayout it already declares) and use the larger of the element and
wrapper heights, so both regular and absolutely positioned tab bars are
measured correctly.

Fixes callstack#380
@oleksandrzavarzin-callstack

Copy link
Copy Markdown
Contributor

Thanks for the fix. Looks great!
I've tested this PR on iOS 27.0 with a 60 pt custom tab bar:

What tabBar returns useBottomTabBarHeight()
An absolute View 60
A static View 60
An absolute View inside a custom component 0

The PR fixes the case from #380. But the component case is the pattern that our React Navigation guide shows: tabBar={(props) => <MyTabBar {...props} />}. For example:

function CustomBar() {
  return <View style={{ position: 'absolute', bottom: 0, width: '100%', height: 60 }} />;
}

<TabView tabBar={() => <CustomBar />} />

Here cloneElement adds onLayout to <CustomBar />, not to its View. CustomBar does not pass onLayout on to the View, so the height stays 0.

Can you do one of these?

  1. Handle this case in the library.
  2. Add a note to the tabBar docs: if the bar is absolutely positioned, the component must pass onLayout on to its root view.

@oleksandrzavarzin-callstack

Copy link
Copy Markdown
Contributor

Also one more thing.
This PR adds a one-frame jump for static tab bars.

With a static custom bar, the first frame now uses useBottomTabBarHeight() = 0, and the next frame uses 60.

The cause: the old code called measure() in useLayoutEffect, so the height was set before the first frame. onLayout fires after the first layout, so the first frame still has 0.

Here are the results of my testing on iOS 27.0.

Video Frame by frame
380-ios-27-pr559-static-mount.mov
380-ios-27-pr559-static-mount-frames

@mrpmohiburrahman

mrpmohiburrahman commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Also one more thing. This PR adds a one-frame jump for static tab bars.

I will start working on this and the previous one as soon as possible.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Measuring custom tab bar height fails for absolutely‑positioned elements

2 participants