From 949fc78b1d4c01de9da6e08e684ad4aec082d637 Mon Sep 17 00:00:00 2001 From: codexy Date: Thu, 26 Nov 2026 11:06:31 +0900 Subject: [PATCH] feat: appShell mode and native scrollbars hidden everywhere appShell makes the provider fill the viewport and stops the document from scrolling, so and never show a browser scrollbar and only the content area (or each page's scrollTarget) scrolls. It implies scrollMode="container"; header and footer stay optional. Window mode and appShell now hide the native scrollbar on as well as (scrollbar-width and ::-webkit-scrollbar), checked in Chrome and iOS Safari 27 (simulator): only the drawn scrollbar appears. Demo: /with uses appShell (fixed header and tab bar, content-only scroll); /without scrolls the whole document like a plain Next.js page. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 ++ docs/REFERENCE.md | 30 +++++++++++++++++++++++++++ examples/next-app/app/stays/stays.css | 9 ++++++-- examples/next-app/app/with/layout.tsx | 2 +- src/next/index.tsx | 11 ++++++++-- src/next/style.css | 13 ++++++++++-- 6 files changed, 60 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 09c8b78..181e63c 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ An unofficial add-on for the Next.js App Router. It draws slide transitions betw - Edge-swipe Back (`swipeBack`) with a preview of the previous screen. - Scroll offset restored per history entry (`preserveScroll`). - Document scrolling by default (`window.scrollTo`, `window.scrollY` keep working); an independent scroll container also works (`scrollTarget`). +- `appShell`: the provider fills the viewport, the document never scrolls, and only the content area (or each page's `scrollTarget`) scrolls. Header and footer slots are optional. +- The browser's own scrollbar is hidden on ``, `` and the scroll areas; the drawn scrollbar replaces it. - A vertical scrollbar drawn with [OverlayScrollbars](https://github.com/KingSora/OverlayScrollbars): its track stays between fixed headers, footers and tab bars, follows whichever scroller is moving, and can be dragged or clicked. - `edgeBounce`: optional touch bounce at scroll boundaries on non-Apple touch devices. - `skipSlideQueryKeys`: skip the page slide when only a popup query parameter changes. diff --git a/docs/REFERENCE.md b/docs/REFERENCE.md index a2d9ec2..9ec5242 100644 --- a/docs/REFERENCE.md +++ b/docs/REFERENCE.md @@ -303,6 +303,36 @@ The scroll offset and native scroll range stay at the boundary. The effect respects reduced motion. Keep fixed bars outside the moving surface, for example as siblings of `scrollTarget` or in the provider slots. +### Run as an app shell + +Set `appShell` to make the provider fill the viewport like a native app. The +document stops scrolling, so the browser never shows a scrollbar on `` or +``. The `header`, `persistent` and `footer` slots stay put, and only the +content area between them scrolls, with the drawn scrollbar inside that area. +Leave out `header` and `footer` and let each page render its own bars, then +point `scrollTarget` at the page's scrolling area. `appShell` implies +`scrollMode="container"`. + +```tsx +// Shared bars from the layout +} footer={}> + {children} + + +// Or bars owned by each page + + {children} + +// app/detail/page.tsx +
+
…
+
…
+
+``` + +Without `appShell`, window mode also hides the native scrollbar on `` +and `` and draws its own, but the document itself keeps scrolling. + ### Use an independent scroll container Set `scrollMode="container"` to keep scrolling inside a bounded provider. diff --git a/examples/next-app/app/stays/stays.css b/examples/next-app/app/stays/stays.css index fc963d4..64820ce 100644 --- a/examples/next-app/app/stays/stays.css +++ b/examples/next-app/app/stays/stays.css @@ -17,8 +17,13 @@ .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; } -.plain-shell { display: flex; flex-direction: column; height: 100%; } -.plain-body { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; } +/* Plain Next.js: the whole document scrolls, so the browser scrollbar runs the + full height of the window, past the header and the tab bar. */ +.stays-app:has(> .plain-shell) { height: auto; min-height: 100dvh; } +.plain-shell { display: flex; flex-direction: column; min-height: 100dvh; } +.plain-shell > .app-header { position: sticky; top: 0; z-index: 2; } +.plain-body { flex: 1 0 auto; } +.plain-shell > .app-tabs { position: sticky; bottom: 0; z-index: 2; } .app-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; diff --git a/examples/next-app/app/with/layout.tsx b/examples/next-app/app/with/layout.tsx index d6e2813..08b3ef8 100644 --- a/examples/next-app/app/with/layout.tsx +++ b/examples/next-app/app/with/layout.tsx @@ -10,7 +10,7 @@ const modalRoutes = stays.map(stay => `/with/stay/${stay.id}/book`); export default function WithLayout({children}: {children: ReactNode}) { return
- } footer={}> + } footer={}> {children}
diff --git a/src/next/index.tsx b/src/next/index.tsx index bbf0bed..9b601b7 100644 --- a/src/next/index.tsx +++ b/src/next/index.tsx @@ -44,6 +44,12 @@ export interface StackflowProviderProps { preserveScroll?: boolean; /** Scroll the browser document or a provider-owned container. Defaults to 'window'. */ scrollMode?: 'container' | 'window'; + /** + * Fill the viewport like a native app. The document stops scrolling, so no + * browser scrollbar appears on or ; each page scrolls its own + * `scrollTarget` area. Implies `scrollMode="container"`. Defaults to false. + */ + appShell?: boolean; /** Select a scroll container, or the scrollbar's display area in window mode. */ scrollTarget?: string; /** Add touch-only bounce where Apple-style native rubber-banding is unavailable. */ @@ -72,7 +78,8 @@ export interface StackflowProviderProps { className?: string; style?: CSSProperties; } -export function StackflowProvider({children,header,footer,persistent,animation='ios',preserveScroll=true,scrollMode='window',scrollTarget,edgeBounce=false,fixedTargets,modalRoutes,transitionRoutes,skipSlideQueryKeys,transitionTarget,swipeBack=false,maxEntries=32,navigationTimeout=4000,waitForPage=false,skeletonRoutes,loading,locale,className='',style}: StackflowProviderProps) { +export function StackflowProvider({children,header,footer,persistent,animation='ios',preserveScroll=true,scrollMode: requestedScrollMode='window',appShell=false,scrollTarget,edgeBounce=false,fixedTargets,modalRoutes,transitionRoutes,skipSlideQueryKeys,transitionTarget,swipeBack=false,maxEntries=32,navigationTimeout=4000,waitForPage=false,skeletonRoutes,loading,locale,className='',style}: StackflowProviderProps) { + const scrollMode = appShell ? 'container' : requestedScrollMode; const viewport=useRef(null); const scrollbar = useRef(null); const fixed = useRef([]); @@ -140,7 +147,7 @@ export function StackflowProvider({children,header,footer,persistent,animation=' {footer &&
{footer}
} ; return -
+
{header &&
{header}
}
{children}
diff --git a/src/next/style.css b/src/next/style.css index 3ff17f2..3dee7dc 100644 --- a/src/next/style.css +++ b/src/next/style.css @@ -85,8 +85,17 @@ html[data-stackflow-direction][data-stackflow-modal=exit]::view-transition-new(s } .stackflow-next-viewport{position:relative;flex:1;min-height:0;overflow:clip}.stackflow-next-header,.stackflow-next-footer,.stackflow-next-persistent{flex:none} -html:has(.stackflow-next[data-stackflow-scroll-mode=window]){scrollbar-width:none} -html:has(.stackflow-next[data-stackflow-scroll-mode=window])::-webkit-scrollbar{display:none} +/* The drawn scrollbar replaces the browser's. Hide the native one on the + document and on (some apps scroll the body) on every engine. */ +html:has(.stackflow-next:is([data-stackflow-scroll-mode=window],[data-stackflow-app-shell])), +html:has(.stackflow-next:is([data-stackflow-scroll-mode=window],[data-stackflow-app-shell])) > body{scrollbar-width:none} +html:has(.stackflow-next:is([data-stackflow-scroll-mode=window],[data-stackflow-app-shell]))::-webkit-scrollbar, +html:has(.stackflow-next:is([data-stackflow-scroll-mode=window],[data-stackflow-app-shell])) > body::-webkit-scrollbar{display:none;width:0;height:0} +/* App shell: the provider fills the viewport and the document never scrolls. + Each page scrolls its own scrollTarget area. */ +html:has(.stackflow-next[data-stackflow-app-shell]), +html:has(.stackflow-next[data-stackflow-app-shell]) > body{height:100%;overflow:hidden;overscroll-behavior:none} +.stackflow-next[data-stackflow-app-shell]{position:fixed;inset:0;height:auto} .stackflow-next[data-stackflow-scroll-mode=window]{height:auto;min-height:100dvh;--stackflow-slide-y:0 100dvh} [data-stackflow-scroll-mode=window] > .stackflow-next-viewport{display:flex;flex-direction:column;flex:1 0 auto;overflow:visible} [data-stackflow-scroll-mode=window] .stackflow-next-content:not([data-stackflow-slide-snapshot]){flex:1 0 auto;height:auto;overflow:visible;overscroll-behavior:auto}