···233233 },
234234 ],
235235 }))
236236- const pendingHeaderHeight = React.useRef<null | number>(null)
236236+ const headerRef = React.useRef(null)
237237 return (
238238 <Animated.View
239239 pointerEvents="box-none"
240240 style={[styles.tabBarMobile, headerTransform]}>
241241- <View
242242- pointerEvents="box-none"
243243- collapsable={false}
244244- onLayout={e => {
245245- if (isHeaderReady) {
246246- onHeaderOnlyLayout(e.nativeEvent.layout.height)
247247- pendingHeaderHeight.current = null
248248- } else {
249249- // Stash it away for when `isHeaderReady` turns `true` later.
250250- pendingHeaderHeight.current = e.nativeEvent.layout.height
251251- }
252252- }}>
241241+ <View ref={headerRef} pointerEvents="box-none" collapsable={false}>
253242 {renderHeader?.()}
254243 {
255255- // When `isHeaderReady` turns `true`, we want to send the parent layout.
256256- // However, if that didn't lead to a layout change, parent `onLayout` wouldn't get called again.
257257- // We're conditionally rendering an empty view so that we can send the last measurement.
244244+ // It wouldn't be enough to place `onLayout` on the parent node because
245245+ // this would risk measuring before `isHeaderReady` has turned `true`.
246246+ // Instead, we'll render a brand node conditionally and get fresh layout.
258247 isHeaderReady && (
259248 <View
249249+ // It wouldn't be enough to do this in a `ref` of an effect because,
250250+ // even if `isHeaderReady` might have turned `true`, the associated
251251+ // layout might not have been performed yet on the native side.
260252 onLayout={() => {
261261- // We're assuming the parent `onLayout` already ran (parent -> child ordering).
262262- if (pendingHeaderHeight.current !== null) {
263263- onHeaderOnlyLayout(pendingHeaderHeight.current)
264264- pendingHeaderHeight.current = null
265265- }
253253+ // @ts-ignore
254254+ headerRef.current?.measure(
255255+ (_x: number, _y: number, _width: number, height: number) => {
256256+ onHeaderOnlyLayout(height)
257257+ },
258258+ )
266259 }}
267260 />
268261 )