Skip to content

fix: keep percentage and auto styles in SafeAreaView on web - #793

Open
mkantautas wants to merge 1 commit into
appandflow:mainfrom
mkantautas:fix/web-safe-area-view-css-values
Open

mkantautas wants to merge 1 commit into
appandflow:mainfrom
mkantautas:fix/web-safe-area-view-css-values

Conversation

@mkantautas

Copy link
Copy Markdown

Summary

On web, SafeAreaView adds each inset to the matching padding or margin in JS. React Native styles also accept percentages and auto, which are strings, so the addition concatenates: style={{ padding: '5%' }} with a 44px top inset gives paddingTop: '5%44'. The browser rejects that value, so the view loses both its own padding and the safe area inset on that edge. With zero insets, as on desktop, '5%' becomes '5%0' and the padding is gone. A plain number string such as '0' becomes '044', and marginHorizontal: 'auto' loses its centering.

Percentages are now combined with the inset in CSS: calc(5% + 44px) for additive edges and max(5%, 44px) for maximum edges. Plain number strings use the existing numeric arithmetic. CSS cannot combine auto with a length, so with mode="margin" an auto margin stays auto and takes the place of the inset on that edge; the docs note this. Numeric styles and native platforms are unchanged.

Test Plan

  • src/__tests__/SafeAreaView.web-test.tsx: four cases through SafeAreaProvider and the web SafeAreaView (percentage padding, percentage padding with a maximum edge, plain number strings, auto margins). All four fail on main and pass with this change.
  • In Chromium 151 with react-native-web 0.21.4 and React 19.2.3, with safe area insets of 44/34/10/20 emulated through the DevTools protocol:
    • padding: '5%': main renders 0px padding on every edge; this branch renders calc(5% + 44px) and so on. With zero insets it renders the same 5% as a plain View.
    • marginHorizontal: 'auto' on a 200px wide view: main renders it at the left edge; this branch keeps it centered.
    • Numeric padding and margin, null and undefined values, style arrays, edge arrays and off edges render the same as on main.
  • yarn format:prettier:check, yarn format:clang:check, yarn validate:eslint (no errors, the three existing deep-import warnings), yarn validate:typescript, yarn validate:jest (6 suites, 38 tests), node --test scripts/*.test.mjs, npm pack with node scripts/check-package.mjs, and yarn build in docs and website pass with Node 22.13.0. I did not run format:spotless:check; no Android files changed.

The web SafeAreaView added each inset to the matching padding or margin
in JS. A percentage such as '5%' became '5%44', which the browser
rejects, so both the style and the inset were dropped. A plain number
string such as '0' became '044', and an auto margin was lost the same
way.

Percentages are now combined with the inset through calc() and max(),
plain number strings use the numeric arithmetic, and an auto margin
stays auto.
@vercel

vercel Bot commented Oct 23, 2026

Copy link
Copy Markdown

@mkantautas is attempting to deploy a commit to the appandflow Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

1 participant