Repository navigation
fix(ui): stop Screen padding by the status bar under a nav header - #744
Merged
Merged
Conversation
…G-611) #741 swapped Screen's wrapper from React Native's SafeAreaView to react-native-safe-area-context's and passed no `edges`, so all four edges pad additively. React Navigation's header already reserves the status bar (it renders a spacer of insets.top above its content), so every screen with a header gained a second status-bar-high band of dead space beneath the header. The docblock added in #741 claimed the wrapper is position-aware and so could not double-pad. That is not true of safe-area-context 5.x, which reads the nearest provider's insets verbatim and does no frame math against the view's own position — Android resolves findProvider() then getSafeAreaInsets(providerView), iOS reads _providerView.safeAreaInsets, and the Fabric shadow node folds stateData.insets.top in unchanged. Our provider is the root SafeAreaProvider in app.tsx, which spans the window, so `top` is always the full status bar however deep the screen sits. Both platforms are affected; the docblock is corrected here. Drop the top edge when HeaderShownContext says a header is shown above us — the same signal the header itself uses to decide whether to reserve the status bar — and keep all four when there is none, where this wrapper is the only thing holding content clear. Measured on device, both platforms, against the same build with only this commit removed: - Pixel 8 Pro: Home greeting y=526 -> y=375, a delta of 151px, exactly the status bar height. Header icons (y=151) and tab bar (y=2758) unchanged. - iPhone 13 Pro Max: "Send" y=358 -> y=311 and the carousel y=402 -> y=355, a delta of 47pt, exactly the status bar inset. Header icon (y=56) and tab bar (y=851) unchanged. The existing specs could not catch this: one asserts only that the tree contains RNCSafeAreaView, the other renders under a mock fed initialMetrics with no notion of a header above the wrapper. The new spec pins `edges` in both presets and fails 4 of its 6 cases with this fix reverted. @react-navigation/elements moves from a transitive to a declared dependency at the spec already resolved in yarn.lock (^1.3.31); yarn install --frozen-lockfile leaves the lockfile untouched. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Review fixes on ENG-611.
- The 37-line safe-area docblock had ended up as a JSDoc on
`EDGES_BELOW_HEADER`, an array of three strings, because the constant was
inserted between the comment and the function it was written for. Move it
to a file-level banner above the imports and leave a one-line JSDoc on the
constant. `ScreenWithoutScrolling` gets its blank line back.
- Both `unsafe` branches were rewritten to literal `View`s in this PR and
neither was covered here; only the non-scrolling one had a check, in
screen-android.spec.tsx. Add a case to the preset loop asserting no
SafeAreaView is rendered, so a future edit that wires `edges` into the
scrolling `unsafe` path cannot ship silently. Verified it fails for both
presets with the branch mutated.
- The bottom edge has the same double-pad defect: a bottom tab bar pads
itself by `insets.bottom` and sits below the scene in normal flow, so this
wrapper adds it a second time on every tab screen. Not fixed here — the
routes that hide the bar with `tabBarStyle: { display: "none" }` still need
the inset and `BottomTabBarHeightContext` cannot be trusted to read 0 for
them without a device. Filed as ENG-612; documented in the banner, and the
"which no header reserves" spec renamed to "which the header does not
reserve" so the suite stops implying the bottom is settled.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…onour edges
Review fixes for ENG-611.
The banner claimed HeaderShownContext is equivalent to "the header reserves
the status bar". It is not: with headerTransparent the header is rendered
absolutely and reserves nothing (stack CardStack's isFloatHeaderAbsolute,
bottom tabs' styles.absolute on the header) while the context is still true.
No route in the app sets it today, so nothing is broken now — but the banner
is otherwise exhaustive about this mechanism and gave no warning. Record the
exception in the banner and stop the useSafeAreaEdges docblock asserting the
equivalence as fact.
screen.spec.tsx's SafeAreaViewMock still modelled the pre-ENG-611 contract:
it ignored `edges` and padded all four sides unconditionally, so every
assertion in the file stayed green no matter what edges Screen passed —
including `edges={[]}`. Make the mock honour the prop, and add a spec that
renders under HeaderShownContext and asserts the top pad is actually 0 while
the bottom one survives. That spec fails against the old mock.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The banner told the next engineer to pass `unsafe` on a transparent-header route. `unsafe` swaps the whole SafeAreaView for a bare View, so left, right and bottom go with the top, and on an edge-to-edge window the content then runs under the navigation bar — the defect this wrapper exists to prevent. That is the same failure this PR indicts #741 for: a docblock prescribing something the code does not support. Point at what actually works (reinstate the top inset from useSafeAreaInsets() on the route's own content) and warn off `unsafe` explicitly. No API change: no route uses headerTransparent today, so adding an `edges` override for a hypothetical caller would be speculative surface. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes ENG-611. Found on device while testing #743; reported by Jabari as "a large empty space at the top of the home screen ... it seems to be on all screens."
The bug
Every screen with a navigation header carries a status-bar-high band of dead space between the header and its first content. Home, Settings, everything that renders
<Screen>under a header. Both platforms.The top inset is applied twice:
@react-navigation/elementsHeader.tsx:80computesheaderStatusBarHeightand renders a spacerViewof that height (:236).Screenthen pads by it again: the wrapper isSafeAreaViewwith noedgesprop, so all four edges default to additive,topincluded.Introduced by #741 (
2a7cad14b), which changedscreen.tsxfromSafeAreaViewimported fromreact-nativeto the safe-area-context one. React Native's own is a plainViewon Android (zero padding) and genuinely position-aware on iOS via UIKit — so both platforms were correct before. #742 (targetSdk 36) made it visible rather than latent by forcing edge-to-edge. Not in 0.7.2 — this is a 0.7.3 RC regression only.The docblock was wrong, and that's how this got in
#741 added a comment asserting the wrapper "is position-aware: the native view pads only by the part of the window insets it actually overlaps ... screens with headers do not double-pad."
safe-area-context 5.6.2 does not work that way. It reads the nearest provider's insets verbatim and does no frame math against the view's own position — Android resolves
findProvider()thengetSafeAreaInsets(providerView); iOS reads_providerView.safeAreaInsets; the Fabric shadow node foldsstateData.insets.topin unchanged. Our provider is the rootSafeAreaProviderinapp.tsx, which spans the window, sotopis always the full status bar no matter how deep the screen sits. The docblock is replaced with what the library actually does, so this doesn't come back.The fix
Drop the top edge when
HeaderShownContextreports a header above us — the same signal the header itself uses to decide whether to reserve the status bar — and keep all four edges when there is none, where this wrapper is the only thing holding content clear of the status bar. Theunsafebranch now rendersViewexplicitly, sinceedgesis not a validViewprop.Measured on device
Same build, only this commit removed, on both phones against TEST:
Header icons (Pixel y=151, iPhone y=56) and tab bars (y=2758 / y=851) are unchanged on both, so only the duplicate inset went away. Settings shows the same improvement, confirming it is app-wide.
These numbers say nothing about the bottom edge — they measure where the tab bar sits, not the gap above it. See "Bottom edge" below.
Tests
__tests__/components/screen-header-inset.spec.tsxpinsedgesfor both presets, with and without a header, plus theunsafebranch of each (both were rewritten to literalViews here and only the non-scrolling one had prior coverage, inscreen-android.spec.tsx). Every case was mutation-checked rather than assumed: 4 of the 6edgescases fail with this fix reverted, and bothunsafecases fail with the branch flipped.The existing specs could not have caught the original bug:
screen-android.spec.tsxonly asserts the tree containsRNCSafeAreaView, andscreen.spec.tsxrenders under a mock fedinitialMetricswith no notion of a header above the wrapper.Full suite green — 1297, up from 1295 on the parent commit. tsc clean, eslint clean, prettier clean.
Bottom edge — same defect, not fixed here (ENG-612)
bottomstays inEDGES_BELOW_HEADER, and it has the identical double-pad problem from the same origin (#741):@react-navigation/bottom-tabspads the tab bar byinsets.bottom(BottomTabBar.tsx:86) and lays it out below the scene in normal flow (:283), so on every tab screen — Home, Map, Scan, Settings — this wrapper adds that inset a second time. Nothing in the app compensates; there are zerouseBottomTabBarHeight/BottomTabBarHeightContextconsumers.It is deliberately out of scope because it is not a one-line change and cannot be closed without a device:
getTabBarHeight(BottomTabBar.tsx:89) returns a non-zero default fortabBarStyle: { display: "none" }— it only short-circuits on an explicit numericheight, and ourbottomNavigatorStylesetsminHeight.BottomTabBarHeightContextis seeded from that and updated only by the bar'sonLayout, so whether it reads 0 on a hidden bar is unverified.messages(root-navigator.tsx:885) and Scan (:921) — and both still need the bottom inset.app/screens/chat/messages.tsx:88depends on it explicitly:useKeyboardPaddingStyle(insets.bottom)subtracts the insetScreenapplies.Filed as ENG-612 with the full reasoning, documented in the
screen.tsxbanner, and the spec previously named "keeps the side and bottom edges, which no header reserves" renamed to "...which the header does not reserve" so the suite stops implying the bottom is settled.Dependency note
@react-navigation/elementsmoves from a transitive to a declared dependency at^1.3.31— the exact spec already resolved inyarn.lock, soyarn install --frozen-lockfileleaves the lockfile byte-identical. It was already in the tree viabottom-tabsandstack.Unrelated thing worth knowing
npx react-native bundle --assets-dest android/app/src/main/reswrites generated PNGs into that tracked directory and nothing gitignores them, so a local device build leaves ~28 untracked files that are easy to commit by accident. Not fixed here.🤖 Generated with Claude Code