SwipeUI

Header collapsing

Large title folds into a compact title with UI-thread scroll.

npx @swipeui/cli add header-collapsing
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When 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.tsx and 3 shared helpers.
  • Installs react-native-reanimated, uniwind, react-native-worklets, clsx, tailwind-merge. In Expo apps it uses npx expo install so versions match your SDK.

Usage

app/library.tsx
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:

app/library.tsx
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

PropTypeDefaultDescription
titlestring—

The title, shown and spoken in full.

subtitle?string—

A line under the title. By default it fades away as the header collapses.

subtitleCollapse?"fade" | "keep"'fade'

What the subtitle does as the header collapses: fade away, or keep it under the compact title.

scrollYSharedValue<number>—

The scrollY returned by useHeaderScroll.

collapseDistance?number96

How far the content scrolls, in points, before the title is fully compact.

largeTitle?booleantrue

Starts with the large title. Turn it off for a header that is always compact.

divider?booleanfalse

Fades in a hairline under the header once it has collapsed.

insetTop?number0

Space above the header, in points, usually the top safe-area inset.

leading?ReactNode—

Content before the title, such as a back button.

trailing?ReactNode—

Content after the title, such as actions.

motion?MotionOverridethe app feel

Local motion feel or spring override.

className?string—

Classes merged over the header.

style?StyleProp<ViewStyle>—

Style escape hatch for the header.

testID?string—

The header gets testID, the divider ${testID}-divider.

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 morph motion role, so it follows your app's feel. Pass motion to 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 onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items