From 946cde34c5971ea56042ef38883759ab5fa687e3 Mon Sep 17 00:00:00 2001 From: "JH.Lee" Date: Mon, 23 Nov 2026 11:08:55 +0900 Subject: [PATCH 1/4] feat(plugin-basic-ui): prefer --native-safe-area-inset-* over env() AppScreen, AppBar, Modal, and BottomSheet now read the native inset variables first and fall back to env(safe-area-inset-*). A host app that injects them before the first render avoids the initial layout shift without caching the inset. Co-Authored-By: Claude Opus 5.5 --- .changeset/native-safe-area-insets.md | 7 ++++++ .../plugins/plugin-basic-ui.en.mdx | 8 +++++-- .../plugins/plugin-basic-ui.ko.mdx | 8 +++++-- .../src/components/AppBar.css.ts | 14 ++++-------- .../src/components/AppScreen.css.ts | 14 ++++-------- .../src/components/BottomSheet.css.ts | 17 ++++---------- .../src/components/Modal.css.ts | 22 +++++-------------- .../plugin-basic-ui/src/styles/index.ts | 1 + .../src/styles/safeAreaInset.ts | 9 ++++++++ 9 files changed, 46 insertions(+), 54 deletions(-) create mode 100644 .changeset/native-safe-area-insets.md create mode 100644 extensions/plugin-basic-ui/src/styles/safeAreaInset.ts diff --git a/.changeset/native-safe-area-insets.md b/.changeset/native-safe-area-insets.md new file mode 100644 index 000000000..5f6e940ba --- /dev/null +++ b/.changeset/native-safe-area-insets.md @@ -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 before the first render no longer causes a layout shift in `AppScreen`, `AppBar`, `Modal`, and `BottomSheet`. + +If 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. diff --git a/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx b/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx index e2a9fe04f..60cf5fcb3 100644 --- a/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx +++ b/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx @@ -89,12 +89,16 @@ Include `viewport-fit=cover` in the viewport meta tag so the browser exposes the ``` +Each inset reads the `--native-safe-area-inset-top`, `--native-safe-area-inset-right`, `--native-safe-area-inset-bottom`, and `--native-safe-area-inset-left` CSS variables first, and falls back to `env(safe-area-inset-*)` when a variable is not defined. A host app can inject these variables before the first render to avoid the layout shift that occurs while `env()` values are not yet available. + +If you set `appBar.minSafeAreaInsetTop` or its CSS variable to a previously measured inset to work around that layout shift, remove the override. `AppBar` uses the larger of `minSafeAreaInsetTop` and the current inset, so a stale value still wins after the inset changes, for example after a rotation. + To extend media or other content to the screen edges, wrap it in a block element and cancel the insets with negative margins on the wrapper: ```css copy .full-bleed { - margin-left: calc(-1 * env(safe-area-inset-left, 0px)); - margin-right: calc(-1 * env(safe-area-inset-right, 0px)); + margin-left: calc(-1 * var(--native-safe-area-inset-left, env(safe-area-inset-left, 0px))); + margin-right: calc(-1 * var(--native-safe-area-inset-right, env(safe-area-inset-right, 0px))); } ``` diff --git a/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx b/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx index c56112244..0cf35d956 100644 --- a/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx +++ b/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx @@ -87,12 +87,16 @@ const Something = () => { ``` +각 Inset은 `--native-safe-area-inset-top`, `--native-safe-area-inset-right`, `--native-safe-area-inset-bottom`, `--native-safe-area-inset-left` CSS 변수를 먼저 사용하고, 변수가 정의되지 않은 환경에서는 `env(safe-area-inset-*)`를 사용해요. 호스트 앱이 첫 렌더링 전에 이 변수를 주입하면 `env()` 값이 늦게 반영되면서 생기는 레이아웃 시프트를 막을 수 있어요. + +이 레이아웃 시프트를 피하려고 이전에 측정한 Inset 값을 `appBar.minSafeAreaInsetTop`이나 해당 CSS 변수에 넣고 있다면 제거해 주세요. `AppBar`는 `minSafeAreaInsetTop`과 현재 Inset 중 큰 값을 사용하기 때문에, 화면 회전 등으로 Inset이 바뀌어도 이전 값이 계속 적용돼요. + 이미지 등 본문 요소를 화면 끝까지 넓히려면 블록 요소로 감싸고, 감싼 요소에 음수 마진을 지정해 Inset을 상쇄해 주세요. ```css copy .full-bleed { - margin-left: calc(-1 * env(safe-area-inset-left, 0px)); - margin-right: calc(-1 * env(safe-area-inset-right, 0px)); + margin-left: calc(-1 * var(--native-safe-area-inset-left, env(safe-area-inset-left, 0px))); + margin-right: calc(-1 * var(--native-safe-area-inset-right, env(safe-area-inset-right, 0px))); } ``` diff --git a/extensions/plugin-basic-ui/src/components/AppBar.css.ts b/extensions/plugin-basic-ui/src/components/AppBar.css.ts index 142390231..ce5ae454f 100644 --- a/extensions/plugin-basic-ui/src/components/AppBar.css.ts +++ b/extensions/plugin-basic-ui/src/components/AppBar.css.ts @@ -2,7 +2,7 @@ import { style } from "@vanilla-extract/css"; import { recipe } from "@vanilla-extract/recipes"; import { android, cupertino, globalVars } from "../basicUIPlugin.css"; -import { f } from "../styles"; +import { f, safeAreaInset } from "../styles"; import { enterActive, enterDone, @@ -186,7 +186,7 @@ export const appBar = recipe({ export const safeArea = style({ height: [ `max(${globalVars.appBar.minSafeAreaInsetTop}, constant(safe-area-inset-top))`, - `max(${globalVars.appBar.minSafeAreaInsetTop}, env(safe-area-inset-top))`, + `max(${globalVars.appBar.minSafeAreaInsetTop}, ${safeAreaInset.top})`, ], }); @@ -196,14 +196,8 @@ export const container = style([ appBarOverflow, { height: globalVars.appBar.height, - marginLeft: [ - "constant(safe-area-inset-left)", - "env(safe-area-inset-left, 0px)", - ], - marginRight: [ - "constant(safe-area-inset-right)", - "env(safe-area-inset-right, 0px)", - ], + marginLeft: ["constant(safe-area-inset-left)", safeAreaInset.left], + marginRight: ["constant(safe-area-inset-right)", safeAreaInset.right], transition: transitions({ height: globalVars.appBar.heightTransitionDuration, }), diff --git a/extensions/plugin-basic-ui/src/components/AppScreen.css.ts b/extensions/plugin-basic-ui/src/components/AppScreen.css.ts index 746729bcd..ce6bd4284 100644 --- a/extensions/plugin-basic-ui/src/components/AppScreen.css.ts +++ b/extensions/plugin-basic-ui/src/components/AppScreen.css.ts @@ -2,7 +2,7 @@ import { createThemeContract, style } from "@vanilla-extract/css"; import { recipe } from "@vanilla-extract/recipes"; import { android, cupertino, globalVars } from "../basicUIPlugin.css"; -import { f } from "../styles"; +import { f, safeAreaInset } from "../styles"; export const vars = createThemeContract({ transitionDuration: null, @@ -70,7 +70,7 @@ export const appScreen = recipe({ "(padding: max(0px)) and (padding: env(safe-area-inset-top))": { vars: { [vars.appBar.topMargin]: - `calc(${globalVars.appBar.height} + max(${globalVars.appBar.minSafeAreaInsetTop}, env(safe-area-inset-top)))`, + `calc(${globalVars.appBar.height} + max(${globalVars.appBar.minSafeAreaInsetTop}, ${safeAreaInset.top}))`, }, }, }, @@ -174,14 +174,8 @@ export const paperContent = recipe({ f.posAbsFull, f.borderBox, { - paddingLeft: [ - "constant(safe-area-inset-left)", - "env(safe-area-inset-left, 0px)", - ], - paddingRight: [ - "constant(safe-area-inset-right)", - "env(safe-area-inset-right, 0px)", - ], + paddingLeft: ["constant(safe-area-inset-left)", safeAreaInset.left], + paddingRight: ["constant(safe-area-inset-right)", safeAreaInset.right], overflowY: "scroll", WebkitOverflowScrolling: "touch", "::-webkit-scrollbar": { diff --git a/extensions/plugin-basic-ui/src/components/BottomSheet.css.ts b/extensions/plugin-basic-ui/src/components/BottomSheet.css.ts index 07fc7c500..979bb83e2 100644 --- a/extensions/plugin-basic-ui/src/components/BottomSheet.css.ts +++ b/extensions/plugin-basic-ui/src/components/BottomSheet.css.ts @@ -2,7 +2,7 @@ import { createThemeContract, style } from "@vanilla-extract/css"; import { recipe } from "@vanilla-extract/recipes"; import { globalVars } from "../basicUIPlugin.css"; -import { f } from "../styles"; +import { f, safeAreaInset } from "../styles"; export const vars = createThemeContract({ transitionDuration: null, @@ -60,18 +60,9 @@ export const paper = style([ f.overflowHidden, allTransitions, { - paddingRight: [ - "constant(safe-area-inset-right)", - "env(safe-area-inset-right, 0px)", - ], - paddingBottom: [ - "constant(safe-area-inset-bottom)", - "env(safe-area-inset-bottom, 0px)", - ], - paddingLeft: [ - "constant(safe-area-inset-left)", - "env(safe-area-inset-left, 0px)", - ], + paddingRight: ["constant(safe-area-inset-right)", safeAreaInset.right], + paddingBottom: ["constant(safe-area-inset-bottom)", safeAreaInset.bottom], + paddingLeft: ["constant(safe-area-inset-left)", safeAreaInset.left], backgroundColor: globalVars.backgroundColor, backgroundImage: globalVars.backgroundImage, width: "100%", diff --git a/extensions/plugin-basic-ui/src/components/Modal.css.ts b/extensions/plugin-basic-ui/src/components/Modal.css.ts index 657a07a5a..f7258d710 100644 --- a/extensions/plugin-basic-ui/src/components/Modal.css.ts +++ b/extensions/plugin-basic-ui/src/components/Modal.css.ts @@ -2,7 +2,7 @@ import { createThemeContract, style } from "@vanilla-extract/css"; import { recipe } from "@vanilla-extract/recipes"; import { globalVars } from "../basicUIPlugin.css"; -import { f } from "../styles"; +import { f, safeAreaInset } from "../styles"; export const vars = createThemeContract({ transitionDuration: null, @@ -43,22 +43,10 @@ export const dim = style([ f.flexJustifyCenter, allTransitions, { - paddingTop: [ - "constant(safe-area-inset-top)", - "env(safe-area-inset-top, 0px)", - ], - paddingRight: [ - "constant(safe-area-inset-right)", - "env(safe-area-inset-right, 0px)", - ], - paddingBottom: [ - "constant(safe-area-inset-bottom)", - "env(safe-area-inset-bottom, 0px)", - ], - paddingLeft: [ - "constant(safe-area-inset-left)", - "env(safe-area-inset-left, 0px)", - ], + paddingTop: ["constant(safe-area-inset-top)", safeAreaInset.top], + paddingRight: ["constant(safe-area-inset-right)", safeAreaInset.right], + paddingBottom: ["constant(safe-area-inset-bottom)", safeAreaInset.bottom], + paddingLeft: ["constant(safe-area-inset-left)", safeAreaInset.left], backgroundColor: globalVars.dimBackgroundColor, zIndex: vars.zIndexes.dim, opacity: 0, diff --git a/extensions/plugin-basic-ui/src/styles/index.ts b/extensions/plugin-basic-ui/src/styles/index.ts index 773ae6c30..0f0f962dd 100644 --- a/extensions/plugin-basic-ui/src/styles/index.ts +++ b/extensions/plugin-basic-ui/src/styles/index.ts @@ -1 +1,2 @@ export * as f from "./f.css"; +export { safeAreaInset } from "./safeAreaInset"; diff --git a/extensions/plugin-basic-ui/src/styles/safeAreaInset.ts b/extensions/plugin-basic-ui/src/styles/safeAreaInset.ts new file mode 100644 index 000000000..aa62dda01 --- /dev/null +++ b/extensions/plugin-basic-ui/src/styles/safeAreaInset.ts @@ -0,0 +1,9 @@ +const inset = (side: "top" | "right" | "bottom" | "left") => + `var(--native-safe-area-inset-${side}, env(safe-area-inset-${side}, 0px))`; + +export const safeAreaInset = { + top: inset("top"), + right: inset("right"), + bottom: inset("bottom"), + left: inset("left"), +}; From 75b92940d6ab6ee1e0437fa62a1beb36bc6e0acb Mon Sep 17 00:00:00 2001 From: "JH.Lee" Date: Mon, 23 Nov 2026 12:37:14 +0900 Subject: [PATCH 2/4] docs(plugin-basic-ui): require hosts to keep native insets updated Hosts must update --native-safe-area-inset-* when insets change, since a defined variable always wins over env(). Only advise dropping a cached minSafeAreaInsetTop override when the host injects the variables. Co-Authored-By: Claude Opus 5.5 --- .changeset/native-safe-area-insets.md | 4 ++-- docs/pages/api-references/plugins/plugin-basic-ui.en.mdx | 4 ++-- docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.changeset/native-safe-area-insets.md b/.changeset/native-safe-area-insets.md index 5f6e940ba..456677668 100644 --- a/.changeset/native-safe-area-insets.md +++ b/.changeset/native-safe-area-insets.md @@ -2,6 +2,6 @@ "@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 before the first render no longer causes a layout shift in `AppScreen`, `AppBar`, `Modal`, and `BottomSheet`. +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 before the first render, and updates them whenever the insets change, no longer causes a layout shift in `AppScreen`, `AppBar`, `Modal`, and `BottomSheet`. -If 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. +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. diff --git a/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx b/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx index 60cf5fcb3..3ab3ab820 100644 --- a/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx +++ b/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx @@ -89,9 +89,9 @@ Include `viewport-fit=cover` in the viewport meta tag so the browser exposes the ``` -Each inset reads the `--native-safe-area-inset-top`, `--native-safe-area-inset-right`, `--native-safe-area-inset-bottom`, and `--native-safe-area-inset-left` CSS variables first, and falls back to `env(safe-area-inset-*)` when a variable is not defined. A host app can inject these variables before the first render to avoid the layout shift that occurs while `env()` values are not yet available. +Each inset reads the `--native-safe-area-inset-top`, `--native-safe-area-inset-right`, `--native-safe-area-inset-bottom`, and `--native-safe-area-inset-left` CSS variables first, and falls back to `env(safe-area-inset-*)` when a variable is not defined. A host app can inject these variables before the first render to avoid the layout shift that occurs while `env()` values are not yet available. The host app must also update the variables whenever the insets change, for example after a rotation or when a foldable device unfolds. A defined variable always takes precedence over `env()`, so a value that is never updated stays stale. To fall back to `env()`, remove the variables. -If you set `appBar.minSafeAreaInsetTop` or its CSS variable to a previously measured inset to work around that layout shift, remove the override. `AppBar` uses the larger of `minSafeAreaInsetTop` and the current inset, so a stale value still wins after the inset changes, for example after a rotation. +If your host app injects these variables and you set `appBar.minSafeAreaInsetTop` or its CSS variable to a previously measured inset to work around that layout shift, remove the override. `AppBar` uses the larger of `minSafeAreaInsetTop` and the current inset, so a stale value still wins after the inset changes, for example after a rotation. To extend media or other content to the screen edges, wrap it in a block element and cancel the insets with negative margins on the wrapper: diff --git a/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx b/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx index 0cf35d956..c90e9401f 100644 --- a/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx +++ b/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx @@ -87,9 +87,9 @@ const Something = () => { ``` -각 Inset은 `--native-safe-area-inset-top`, `--native-safe-area-inset-right`, `--native-safe-area-inset-bottom`, `--native-safe-area-inset-left` CSS 변수를 먼저 사용하고, 변수가 정의되지 않은 환경에서는 `env(safe-area-inset-*)`를 사용해요. 호스트 앱이 첫 렌더링 전에 이 변수를 주입하면 `env()` 값이 늦게 반영되면서 생기는 레이아웃 시프트를 막을 수 있어요. +각 Inset은 `--native-safe-area-inset-top`, `--native-safe-area-inset-right`, `--native-safe-area-inset-bottom`, `--native-safe-area-inset-left` CSS 변수를 먼저 사용하고, 변수가 정의되지 않은 환경에서는 `env(safe-area-inset-*)`를 사용해요. 호스트 앱이 첫 렌더링 전에 이 변수를 주입하면 `env()` 값이 늦게 반영되면서 생기는 레이아웃 시프트를 막을 수 있어요. 화면 회전이나 폴더블 기기를 펼칠 때처럼 Inset이 바뀌면 호스트 앱이 변수도 함께 갱신해야 해요. 정의된 변수는 항상 `env()`보다 우선하기 때문에, 갱신하지 않으면 이전 값이 계속 적용돼요. `env()`로 돌아가려면 변수를 제거해 주세요. -이 레이아웃 시프트를 피하려고 이전에 측정한 Inset 값을 `appBar.minSafeAreaInsetTop`이나 해당 CSS 변수에 넣고 있다면 제거해 주세요. `AppBar`는 `minSafeAreaInsetTop`과 현재 Inset 중 큰 값을 사용하기 때문에, 화면 회전 등으로 Inset이 바뀌어도 이전 값이 계속 적용돼요. +호스트 앱이 이 변수를 주입하는 환경에서, 레이아웃 시프트를 피하려고 이전에 측정한 Inset 값을 `appBar.minSafeAreaInsetTop`이나 해당 CSS 변수에 넣고 있다면 제거해 주세요. `AppBar`는 `minSafeAreaInsetTop`과 현재 Inset 중 큰 값을 사용하기 때문에, 화면 회전 등으로 Inset이 바뀌어도 이전 값이 계속 적용돼요. 이미지 등 본문 요소를 화면 끝까지 넓히려면 블록 요소로 감싸고, 감싼 요소에 음수 마진을 지정해 Inset을 상쇄해 주세요. From 0a6bf5d8118c85bfcfa35d5efc1a15c3a271ebc0 Mon Sep 17 00:00:00 2001 From: "JH.Lee" Date: Mon, 23 Nov 2026 12:50:16 +0900 Subject: [PATCH 3/4] refactor(plugin-basic-ui): resolve safe area insets once on :root Define --stackflow-plugin-basic-ui-safe-area-inset-* on :root with the same precedence as @seed-design/css: --native-safe-area-inset-*, then env() or constant() behind @supports, then 0px. Components reference the variable, which drops the per-property constant() fallbacks and keeps the constant() fallback working on iOS 11.0-11.1. Co-Authored-By: Claude Opus 5.5 --- .../src/components/AppBar.css.ts | 9 ++---- .../src/components/AppScreen.css.ts | 15 +++------ .../src/components/BottomSheet.css.ts | 6 ++-- .../src/components/Modal.css.ts | 8 ++--- .../plugin-basic-ui/src/styles/index.ts | 2 +- .../src/styles/safeAreaInset.css.ts | 32 +++++++++++++++++++ .../src/styles/safeAreaInset.ts | 9 ------ 7 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 extensions/plugin-basic-ui/src/styles/safeAreaInset.css.ts delete mode 100644 extensions/plugin-basic-ui/src/styles/safeAreaInset.ts diff --git a/extensions/plugin-basic-ui/src/components/AppBar.css.ts b/extensions/plugin-basic-ui/src/components/AppBar.css.ts index ce5ae454f..e265373f5 100644 --- a/extensions/plugin-basic-ui/src/components/AppBar.css.ts +++ b/extensions/plugin-basic-ui/src/components/AppBar.css.ts @@ -184,10 +184,7 @@ export const appBar = recipe({ }); export const safeArea = style({ - height: [ - `max(${globalVars.appBar.minSafeAreaInsetTop}, constant(safe-area-inset-top))`, - `max(${globalVars.appBar.minSafeAreaInsetTop}, ${safeAreaInset.top})`, - ], + height: `max(${globalVars.appBar.minSafeAreaInsetTop}, ${safeAreaInset.top})`, }); export const container = style([ @@ -196,8 +193,8 @@ export const container = style([ appBarOverflow, { height: globalVars.appBar.height, - marginLeft: ["constant(safe-area-inset-left)", safeAreaInset.left], - marginRight: ["constant(safe-area-inset-right)", safeAreaInset.right], + marginLeft: safeAreaInset.left, + marginRight: safeAreaInset.right, transition: transitions({ height: globalVars.appBar.heightTransitionDuration, }), diff --git a/extensions/plugin-basic-ui/src/components/AppScreen.css.ts b/extensions/plugin-basic-ui/src/components/AppScreen.css.ts index ce6bd4284..c2b303144 100644 --- a/extensions/plugin-basic-ui/src/components/AppScreen.css.ts +++ b/extensions/plugin-basic-ui/src/components/AppScreen.css.ts @@ -55,19 +55,12 @@ export const appScreen = recipe({ [vars.appBar.topMargin]: globalVars.appBar.height, }, /** - * When `max()` and `env()` (or `constant()`) supported + * When `max()` supported * - * - https://caniuse.com/css-env-function * - https://caniuse.com/css-math-functions */ "@supports": { - "(padding: max(0px)) and (padding: constant(safe-area-inset-top))": { - vars: { - [vars.appBar.topMargin]: - `calc(${globalVars.appBar.height} + max(${globalVars.appBar.minSafeAreaInsetTop}, constant(safe-area-inset-top)))`, - }, - }, - "(padding: max(0px)) and (padding: env(safe-area-inset-top))": { + "(padding: max(0px))": { vars: { [vars.appBar.topMargin]: `calc(${globalVars.appBar.height} + max(${globalVars.appBar.minSafeAreaInsetTop}, ${safeAreaInset.top}))`, @@ -174,8 +167,8 @@ export const paperContent = recipe({ f.posAbsFull, f.borderBox, { - paddingLeft: ["constant(safe-area-inset-left)", safeAreaInset.left], - paddingRight: ["constant(safe-area-inset-right)", safeAreaInset.right], + paddingLeft: safeAreaInset.left, + paddingRight: safeAreaInset.right, overflowY: "scroll", WebkitOverflowScrolling: "touch", "::-webkit-scrollbar": { diff --git a/extensions/plugin-basic-ui/src/components/BottomSheet.css.ts b/extensions/plugin-basic-ui/src/components/BottomSheet.css.ts index 979bb83e2..2864dd5dc 100644 --- a/extensions/plugin-basic-ui/src/components/BottomSheet.css.ts +++ b/extensions/plugin-basic-ui/src/components/BottomSheet.css.ts @@ -60,9 +60,9 @@ export const paper = style([ f.overflowHidden, allTransitions, { - paddingRight: ["constant(safe-area-inset-right)", safeAreaInset.right], - paddingBottom: ["constant(safe-area-inset-bottom)", safeAreaInset.bottom], - paddingLeft: ["constant(safe-area-inset-left)", safeAreaInset.left], + paddingRight: safeAreaInset.right, + paddingBottom: safeAreaInset.bottom, + paddingLeft: safeAreaInset.left, backgroundColor: globalVars.backgroundColor, backgroundImage: globalVars.backgroundImage, width: "100%", diff --git a/extensions/plugin-basic-ui/src/components/Modal.css.ts b/extensions/plugin-basic-ui/src/components/Modal.css.ts index f7258d710..811d36d6d 100644 --- a/extensions/plugin-basic-ui/src/components/Modal.css.ts +++ b/extensions/plugin-basic-ui/src/components/Modal.css.ts @@ -43,10 +43,10 @@ export const dim = style([ f.flexJustifyCenter, allTransitions, { - paddingTop: ["constant(safe-area-inset-top)", safeAreaInset.top], - paddingRight: ["constant(safe-area-inset-right)", safeAreaInset.right], - paddingBottom: ["constant(safe-area-inset-bottom)", safeAreaInset.bottom], - paddingLeft: ["constant(safe-area-inset-left)", safeAreaInset.left], + paddingTop: safeAreaInset.top, + paddingRight: safeAreaInset.right, + paddingBottom: safeAreaInset.bottom, + paddingLeft: safeAreaInset.left, backgroundColor: globalVars.dimBackgroundColor, zIndex: vars.zIndexes.dim, opacity: 0, diff --git a/extensions/plugin-basic-ui/src/styles/index.ts b/extensions/plugin-basic-ui/src/styles/index.ts index 0f0f962dd..3f71fd511 100644 --- a/extensions/plugin-basic-ui/src/styles/index.ts +++ b/extensions/plugin-basic-ui/src/styles/index.ts @@ -1,2 +1,2 @@ export * as f from "./f.css"; -export { safeAreaInset } from "./safeAreaInset"; +export { safeAreaInset } from "./safeAreaInset.css"; diff --git a/extensions/plugin-basic-ui/src/styles/safeAreaInset.css.ts b/extensions/plugin-basic-ui/src/styles/safeAreaInset.css.ts new file mode 100644 index 000000000..b9cf29b7d --- /dev/null +++ b/extensions/plugin-basic-ui/src/styles/safeAreaInset.css.ts @@ -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; + +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})`), + }, + }, +}); diff --git a/extensions/plugin-basic-ui/src/styles/safeAreaInset.ts b/extensions/plugin-basic-ui/src/styles/safeAreaInset.ts deleted file mode 100644 index aa62dda01..000000000 --- a/extensions/plugin-basic-ui/src/styles/safeAreaInset.ts +++ /dev/null @@ -1,9 +0,0 @@ -const inset = (side: "top" | "right" | "bottom" | "left") => - `var(--native-safe-area-inset-${side}, env(safe-area-inset-${side}, 0px))`; - -export const safeAreaInset = { - top: inset("top"), - right: inset("right"), - bottom: inset("bottom"), - left: inset("left"), -}; From 448acdd36e9f9d59716b8916a61a681c4c77466c Mon Sep 17 00:00:00 2001 From: "JH.Lee" Date: Mon, 23 Nov 2026 12:55:35 +0900 Subject: [PATCH 4/4] docs(plugin-basic-ui): require native inset variables on the root element The inset variables resolve on :root, so --native-safe-area-inset-* set on body or a wrapper is ignored. Say so in the docs and changeset. Co-Authored-By: Claude Opus 5.5 --- .changeset/native-safe-area-insets.md | 2 +- docs/pages/api-references/plugins/plugin-basic-ui.en.mdx | 2 +- docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.changeset/native-safe-area-insets.md b/.changeset/native-safe-area-insets.md index 456677668..994235914 100644 --- a/.changeset/native-safe-area-insets.md +++ b/.changeset/native-safe-area-insets.md @@ -2,6 +2,6 @@ "@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 before the first render, and updates them whenever the insets change, no longer causes a layout shift in `AppScreen`, `AppBar`, `Modal`, and `BottomSheet`. +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. diff --git a/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx b/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx index 3ab3ab820..cff6d85bb 100644 --- a/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx +++ b/docs/pages/api-references/plugins/plugin-basic-ui.en.mdx @@ -89,7 +89,7 @@ Include `viewport-fit=cover` in the viewport meta tag so the browser exposes the ``` -Each inset reads the `--native-safe-area-inset-top`, `--native-safe-area-inset-right`, `--native-safe-area-inset-bottom`, and `--native-safe-area-inset-left` CSS variables first, and falls back to `env(safe-area-inset-*)` when a variable is not defined. A host app can inject these variables before the first render to avoid the layout shift that occurs while `env()` values are not yet available. The host app must also update the variables whenever the insets change, for example after a rotation or when a foldable device unfolds. A defined variable always takes precedence over `env()`, so a value that is never updated stays stale. To fall back to `env()`, remove the variables. +Each inset reads the `--native-safe-area-inset-top`, `--native-safe-area-inset-right`, `--native-safe-area-inset-bottom`, and `--native-safe-area-inset-left` CSS variables first, and falls back to `env(safe-area-inset-*)` when a variable is not defined. A host app can inject these variables on the root element (`document.documentElement`) before the first render to avoid the layout shift that occurs while `env()` values are not yet available. The host app must also update the variables whenever the insets change, for example after a rotation or when a foldable device unfolds. A defined variable always takes precedence over `env()`, so a value that is never updated stays stale. To fall back to `env()`, remove the variables. Variables set on any other element, such as `body`, are ignored. If your host app injects these variables and you set `appBar.minSafeAreaInsetTop` or its CSS variable to a previously measured inset to work around that layout shift, remove the override. `AppBar` uses the larger of `minSafeAreaInsetTop` and the current inset, so a stale value still wins after the inset changes, for example after a rotation. diff --git a/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx b/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx index c90e9401f..dc0e8068c 100644 --- a/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx +++ b/docs/pages/api-references/plugins/plugin-basic-ui.ko.mdx @@ -87,7 +87,7 @@ const Something = () => { ``` -각 Inset은 `--native-safe-area-inset-top`, `--native-safe-area-inset-right`, `--native-safe-area-inset-bottom`, `--native-safe-area-inset-left` CSS 변수를 먼저 사용하고, 변수가 정의되지 않은 환경에서는 `env(safe-area-inset-*)`를 사용해요. 호스트 앱이 첫 렌더링 전에 이 변수를 주입하면 `env()` 값이 늦게 반영되면서 생기는 레이아웃 시프트를 막을 수 있어요. 화면 회전이나 폴더블 기기를 펼칠 때처럼 Inset이 바뀌면 호스트 앱이 변수도 함께 갱신해야 해요. 정의된 변수는 항상 `env()`보다 우선하기 때문에, 갱신하지 않으면 이전 값이 계속 적용돼요. `env()`로 돌아가려면 변수를 제거해 주세요. +각 Inset은 `--native-safe-area-inset-top`, `--native-safe-area-inset-right`, `--native-safe-area-inset-bottom`, `--native-safe-area-inset-left` CSS 변수를 먼저 사용하고, 변수가 정의되지 않은 환경에서는 `env(safe-area-inset-*)`를 사용해요. 호스트 앱이 첫 렌더링 전에 루트 요소(`document.documentElement`)에 이 변수를 주입하면 `env()` 값이 늦게 반영되면서 생기는 레이아웃 시프트를 막을 수 있어요. 화면 회전이나 폴더블 기기를 펼칠 때처럼 Inset이 바뀌면 호스트 앱이 변수도 함께 갱신해야 해요. 정의된 변수는 항상 `env()`보다 우선하기 때문에, 갱신하지 않으면 이전 값이 계속 적용돼요. `env()`로 돌아가려면 변수를 제거해 주세요. `body` 등 다른 요소에 설정한 변수는 사용되지 않아요. 호스트 앱이 이 변수를 주입하는 환경에서, 레이아웃 시프트를 피하려고 이전에 측정한 Inset 값을 `appBar.minSafeAreaInsetTop`이나 해당 CSS 변수에 넣고 있다면 제거해 주세요. `AppBar`는 `minSafeAreaInsetTop`과 현재 Inset 중 큰 값을 사용하기 때문에, 화면 회전 등으로 Inset이 바뀌어도 이전 값이 계속 적용돼요.