Header collapsing
Large title folds into a compact title with UI-thread scroll.
npx @swipeui/cli add header-collapsingWhen to use it
- Inbox, library or settings screens with a big bold title that shrinks into a compact bar as you scroll.
- Custom headers in apps that don't use the native stack header.
- Screens that need leading and trailing actions next to a title that responds to scroll.
- Matching the iOS large-title feel on Android with your own theme tokens.
When not to use it
- When the native stack's large title is enough. Header large title preset uses the system header.
- Headers with a photo behind them. Collapsing hero header adds the image.
- Headers with a search field. Search header handles folding search away.
- Modal screens with a short title; a fixed header is simpler.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add header-collapsing- Adds
components/swipeui/header/header-collapsing.tsxand 3 shared helpers. - Installs react-native-reanimated, uniwind, react-native-worklets, clsx, tailwind-merge. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { HeaderCollapsing, useHeaderScroll } from '@/components/swipeui/header/header-collapsing';
const header = useHeaderScroll();
<HeaderCollapsing title="Library" scrollY={header.scrollY} />
<Animated.ScrollView onScroll={header.onScroll} scrollEventThrottle={16}>{content}</Animated.ScrollView>For plain content, HeaderCollapsingScrollView is the header and the scroll view in one, already wired:
import { HeaderCollapsingScrollView } from '@/components/swipeui/header/header-collapsing';
<HeaderCollapsingScrollView title="Library" subtitle="128 albums" insetTop={insets.top}>
{content}
</HeaderCollapsingScrollView>Keep HeaderCollapsing with useHeaderScroll when the content is a FlatList or another list, so the list keeps recycling its rows.
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
title | | — | The title, shown and spoken in full. |
subtitle? | | — | A line under the title. By default it fades away as the header collapses. |
subtitleCollapse? | | | What the subtitle does as the header collapses: |
scrollY | | — | The |
collapseDistance? | | | How far the content scrolls, in points, before the title is fully compact. |
largeTitle? | | | Starts with the large title. Turn it off for a header that is always compact. |
divider? | | | Fades in a hairline under the header once it has collapsed. |
insetTop? | | | Space above the header, in points, usually the top safe-area inset. |
leading? | | — | Content before the title, such as a back button. |
trailing? | | — | Content after the title, such as actions. |
motion? | | | Local motion feel or spring override. |
className? | | — | Classes merged over the header. |
style? | | — | Style escape hatch for the header. |
testID? | | — | The header gets |
Composition and behavior
- title shrinks from the large-title size to the title-3 size as scrollY grows.
- leading and trailing sit on either side of the title.
- useHeaderScroll() gives you scrollY and an onScroll handler to attach to your list.
- collapseDistance sets how far you scroll before it's fully compact.
- The title is scaled from its leading edge, so the text is laid out once.
- subtitle adds a line that fades out as it collapses, or stays under the compact title with subtitleCollapse set to keep; divider fades in a hairline once collapsed.
- insetTop pads for the safe area; largeTitle set to false keeps the header compact.
- HeaderCollapsingScrollView takes the same header props (without scrollY), plus children, contentContainerStyle, scrollViewProps and headerClassName.
- See Liquid Glass and fallbacks and navigation patterns.
Behavior and gestures
- As you scroll down, the title shrinks from large to compact over the first 96 points (change it with collapseDistance).
- Scrolling back to the top grows the title back to full size.
- Leading and trailing slots hold your own buttons, such as Back or Edit.
Accessibility
- The title is marked as a header, so screen reader users can jump to it.
- The full title is always present in both sizes; nothing is truncated for assistive tech.
- Under Reduce Motion the title stays large until you've scrolled the full distance, then switches to compact in one step.
- Keep leading and trailing buttons at least 44 points and give icon buttons labels.
Motion
- Uses the
morphmotion role, so it follows your app's feel. Passmotionto tune this one instance. - Font size, line height and padding follow the scroll position directly on the UI thread.
- Reduce Motion, or the none feel, replaces the gradual shrink with a single switch.
Performance
- Driven by a Reanimated scroll handler, so scrolling never re-renders React.
- Sizes come from your type tokens, read once.
Notes for AI
- Call useHeaderScroll(), pass its onScroll to an Animated.ScrollView or FlatList and its scrollY to the header.
- Put buttons in leading and trailing, not in title.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.