Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<html>`, `<body>` 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.
Expand Down
30 changes: 30 additions & 0 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<html>` or
`<body>`. 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
<StackflowProvider appShell header={<AppHeader />} footer={<TabBar />}>
{children}
</StackflowProvider>

// Or bars owned by each page
<StackflowProvider appShell scrollTarget="[data-page-scroll]">
{children}
</StackflowProvider>
// app/detail/page.tsx
<div style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>
<header style={{ flex: 'none' }}>…</header>
<main data-page-scroll style={{ flex: 1, minHeight: 0 }}>…</main>
</div>
```

Without `appShell`, window mode also hides the native scrollbar on `<html>`
and `<body>` 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.
Expand Down
9 changes: 7 additions & 2 deletions examples/next-app/app/stays/stays.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/next-app/app/with/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const modalRoutes = stays.map(stay => `/with/stay/${stay.id}/book`);
export default function WithLayout({children}: {children: ReactNode}) {
return <ModeProvider mode="with">
<div className="stays-app">
<StackflowProvider swipeBack waitForPage locale="ko" modalRoutes={modalRoutes} header={<AppHeader />} footer={<TabBar />}>
<StackflowProvider appShell swipeBack waitForPage locale="ko" modalRoutes={modalRoutes} header={<AppHeader />} footer={<TabBar />}>
{children}
</StackflowProvider>
</div>
Expand Down
11 changes: 9 additions & 2 deletions src/next/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <html> or <body>; 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. */
Expand Down Expand Up @@ -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<HTMLDivElement>(null);
const scrollbar = useRef<HTMLDivElement>(null);
const fixed = useRef<readonly FixedTarget[]>([]);
Expand Down Expand Up @@ -140,7 +147,7 @@ export function StackflowProvider({children,header,footer,persistent,animation='
{footer && <div className="stackflow-next-footer">{footer}</div>}
</>;
return <Context.Provider value={engine}><LoadingContext.Provider value={loading === undefined ? fallback : loading}>
<div className={`stackflow-next ${className}`} data-stackflow-scroll-mode={scrollMode} style={style}>
<div className={`stackflow-next ${className}`} data-stackflow-scroll-mode={scrollMode} data-stackflow-app-shell={appShell ? '' : undefined} style={style}>
{header && <div className="stackflow-next-header">{header}</div>}
<div className="stackflow-next-viewport">
<div ref={viewport} className="stackflow-next-content">{children}</div>
Expand Down
13 changes: 11 additions & 2 deletions src/next/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 <body> (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}
Expand Down
Loading