Repository navigation
feat(plugin-basic-ui): prefer --native-safe-area-inset-* over env() #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
946cde3
feat(plugin-basic-ui): prefer --native-safe-area-inset-* over env()
orionmiz 75b9294
docs(plugin-basic-ui): require hosts to keep native insets updated
orionmiz 0a6bf5d
refactor(plugin-basic-ui): resolve safe area insets once on :root
orionmiz 448acdd
docs(plugin-basic-ui): require native inset variables on the root ele…
orionmiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@stackflow/plugin-basic-ui": minor | ||
| --- | ||
|
|
||
| Read safe area insets from the `--native-safe-area-inset-*` CSS variables first, falling back to `env(safe-area-inset-*)` when they are not defined. A host app that injects these variables on the root element before the first render, and updates them whenever the insets change, no longer causes a layout shift in `AppScreen`, `AppBar`, `Modal`, and `BottomSheet`. | ||
|
|
||
| If your host app injects these variables and you set `appBar.minSafeAreaInsetTop` or its CSS variable to a cached inset to avoid that layout shift, remove the override. `AppBar` uses the larger of the two, so a stale cached value still wins over the native variable. Without the native variables, `env()` can still be `0px` on the first render, so a cached override still prevents the shift there. |
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| export * as f from "./f.css"; | ||
| export { safeAreaInset } from "./safeAreaInset.css"; |
32 changes: 32 additions & 0 deletions
32
extensions/plugin-basic-ui/src/styles/safeAreaInset.css.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { globalStyle } from "@vanilla-extract/css"; | ||
|
|
||
| const SIDES = ["top", "right", "bottom", "left"] as const; | ||
|
|
||
| type Side = (typeof SIDES)[number]; | ||
|
|
||
| const property = (side: Side) => | ||
| `--stackflow-plugin-basic-ui-safe-area-inset-${side}`; | ||
|
|
||
| export const safeAreaInset = Object.fromEntries( | ||
| SIDES.map((side) => [side, `var(${property(side)})`]), | ||
| ) as Record<Side, string>; | ||
|
|
||
| const withFallback = (fallback: (side: Side) => string) => | ||
| Object.fromEntries( | ||
| SIDES.map((side) => [ | ||
| property(side), | ||
| `var(--native-safe-area-inset-${side}, ${fallback(side)})`, | ||
| ]), | ||
| ); | ||
|
|
||
| globalStyle(":root", { | ||
| vars: withFallback(() => "0px"), | ||
| "@supports": { | ||
| "(left: constant(safe-area-inset-left))": { | ||
| vars: withFallback((side) => `constant(safe-area-inset-${side})`), | ||
| }, | ||
| "(left: env(safe-area-inset-left))": { | ||
| vars: withFallback((side) => `env(safe-area-inset-${side})`), | ||
| }, | ||
| }, | ||
| }); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.