Repository navigation
fix: keep percentage and auto styles in SafeAreaView on web - #793
Open
mkantautas wants to merge 1 commit into
Open
mkantautas wants to merge 1 commit into
mkantautas wants to merge 1 commit into
Conversation
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.
|
@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
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.
Summary
On web,
SafeAreaViewadds each inset to the matching padding or margin in JS. React Native styles also accept percentages andauto, which are strings, so the addition concatenates:style={{ padding: '5%' }}with a 44px top inset givespaddingTop: '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', andmarginHorizontal: 'auto'loses its centering.Percentages are now combined with the inset in CSS:
calc(5% + 44px)for additive edges andmax(5%, 44px)for maximum edges. Plain number strings use the existing numeric arithmetic. CSS cannot combineautowith a length, so withmode="margin"anautomargin staysautoand 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 throughSafeAreaProviderand the webSafeAreaView(percentage padding, percentage padding with a maximum edge, plain number strings, auto margins). All four fail onmainand pass with this change.padding: '5%':mainrenders 0px padding on every edge; this branch renderscalc(5% + 44px)and so on. With zero insets it renders the same 5% as a plainView.marginHorizontal: 'auto'on a 200px wide view:mainrenders it at the left edge; this branch keeps it centered.nullandundefinedvalues, style arrays, edge arrays andoffedges render the same as onmain.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 packwithnode scripts/check-package.mjs, andyarn buildindocsandwebsitepass with Node 22.13.0. I did not runformat:spotless:check; no Android files changed.