diff --git a/src/view/com/pager/PagerWithHeader.tsx b/src/view/com/pager/PagerWithHeader.tsx index d3678cde0a..61a30de4a5 100644 --- a/src/view/com/pager/PagerWithHeader.tsx +++ b/src/view/com/pager/PagerWithHeader.tsx @@ -16,7 +16,6 @@ import Animated, { useSharedValue, } from 'react-native-reanimated' -import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' import {ScrollProvider} from '#/lib/ScrollContext' import { Pager, @@ -72,19 +71,19 @@ export function PagerWithHeader({ const headerHeight = headerOnlyHeight + tabBarHeight // capture the header bar sizing - const onTabBarLayout = useNonReactiveCallback((evt: LayoutChangeEvent) => { + const onTabBarLayout = useCallback((evt: LayoutChangeEvent) => { const height = evt.nativeEvent.layout.height if (height > 0) { // The rounding is necessary to prevent jumps on iOS setTabBarHeight(Math.round(height * 2) / 2) } - }) - const onHeaderOnlyLayout = useNonReactiveCallback((height: number) => { + }, []) + const onHeaderOnlyLayout = useCallback((height: number) => { if (height > 0) { // The rounding is necessary to prevent jumps on iOS setHeaderOnlyHeight(Math.round(height * 2) / 2) } - }) + }, []) const renderTabBar = useCallback( (props: RenderTabBarFnProps) => { @@ -270,7 +269,8 @@ let PagerTabBar = ({ ], } }) - const headerRef = useRef(null) + const headerRef = useRef(null) + const fallbackHeaderOnlyHeight = useRef(0) return ( {renderHeader?.({setMinimumHeight: setMinimumHeaderHeight})} @@ -301,10 +303,15 @@ let PagerTabBar = ({ // even if `isHeaderReady` might have turned `true`, the associated // layout might not have been performed yet on the native side. onLayout={() => { - // @ts-ignore headerRef.current?.measure( (_x: number, _y: number, _width: number, height: number) => { - onHeaderOnlyLayout(height) + // sometimes height is `undefined` on Android, see above + if (height !== undefined) { + onHeaderOnlyLayout(height) + } else { + // if measure fails, use the value we got from `onLayout` + onHeaderOnlyLayout(fallbackHeaderOnlyHeight.current) + } }, ) }}