|
1 |
| -import React from 'react'; |
| 1 | +import React, { useLayoutEffect, useRef } from 'react'; |
2 | 2 | import type {
|
3 | 3 | OnNativeLayout,
|
4 | 4 | OnPageSelectedEventData,
|
@@ -195,6 +195,7 @@ const TabView = <Route extends BaseRoute>({
|
195 | 195 | }: Props<Route>) => {
|
196 | 196 | // @ts-ignore
|
197 | 197 | const focusedKey = navigationState.routes[navigationState.index].key;
|
| 198 | + const customTabBarWrapperRef = useRef<View>(null); |
198 | 199 | const [tabBarHeight, setTabBarHeight] = React.useState<number | undefined>(0);
|
199 | 200 | const [measuredDimensions, setMeasuredDimensions] = React.useState<
|
200 | 201 | { width: number; height: number } | undefined
|
@@ -313,6 +314,15 @@ const TabView = <Route extends BaseRoute>({
|
313 | 314 | [setMeasuredDimensions]
|
314 | 315 | );
|
315 | 316 |
|
| 317 | + useLayoutEffect(() => { |
| 318 | + // If we are rendering a custom tab bar, we need to measure it to set the tab bar height. |
| 319 | + if (renderCustomTabBar && customTabBarWrapperRef.current) { |
| 320 | + customTabBarWrapperRef.current.measure((_x, _y, _width, height) => { |
| 321 | + setTabBarHeight(height); |
| 322 | + }); |
| 323 | + } |
| 324 | + }, [renderCustomTabBar]); |
| 325 | + |
316 | 326 | return (
|
317 | 327 | <BottomTabBarHeightContext.Provider value={tabBarHeight}>
|
318 | 328 | <NativeTabView
|
@@ -374,7 +384,9 @@ const TabView = <Route extends BaseRoute>({
|
374 | 384 | );
|
375 | 385 | })}
|
376 | 386 | </NativeTabView>
|
377 |
| - {renderCustomTabBar?.() ?? null} |
| 387 | + {renderCustomTabBar ? ( |
| 388 | + <View ref={customTabBarWrapperRef}>{renderCustomTabBar()}</View> |
| 389 | + ) : null} |
378 | 390 | </BottomTabBarHeightContext.Provider>
|
379 | 391 | );
|
380 | 392 | };
|
|
0 commit comments