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

fix: measure custom tab bar height with onLayout#559
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
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

1 participant