Header search
A top bar with a centred title and a glass search button that stretches into a live field; on scroll it turns into a blur.
npx @swipeui/cli add header-searchWhen to use it
- Feeds and libraries where search is one tap away from anywhere, as in social and media apps.
- A compact top bar with a menu or back button on one side and a create button on the other.
- Apps that want a glass search capsule that opens in place instead of pushing a search screen.
- When you show recent searches or live results under the bar while it's open.
When not to use it
- Search as the main purpose of the screen. Keep a full Search field always visible.
- Native stack headers with system search bars.
- A large title that collapses on scroll. Use Collapsing header.
- Expanding a search icon inline in a toolbar. Use Expanding search.
Installation
Installs with a Pro licence
Everything on this page is public except the source. Founder pre-sale opens around 5 January 2027.
Usage
import {
HeaderSearch,
HeaderSearchButton,
headerSearchHeight,
} from '@/components/swipeui/header/header-search';
import { useHeaderScroll } from '@/components/swipeui/header/header-collapsing';
const insets = useSafeAreaInsets();
const header = useHeaderScroll();
const [query, setQuery] = useState('');
<View style={{ flex: 1 }}>
<Animated.ScrollView
onScroll={header.onScroll}
scrollEventThrottle={16}
contentContainerStyle={{ paddingTop: headerSearchHeight(insets.top) }}
>
{content}
</Animated.ScrollView>
<HeaderSearch
title="Library"
insetTop={insets.top}
scrollY={header.scrollY}
leading={<HeaderSearchButton icon={<BackIcon />} accessibilityLabel="Back" onPress={goBack} />}
searchProps={{ placeholder: 'Search library', value: query, onValueChange: setQuery }}
style={{ position: 'absolute', top: 0, left: 0, right: 0 }}
/>
</View>API reference
| Prop | Type | Default | Description |
|---|---|---|---|
material? | | | Preferred material; unsupported choices fall back. |
glassStyle? | | | Native glass style. |
blurTarget? | | — | Android requires a BlurTargetView ref for real blur. |
blurIntensity? | | | Blur strength. |
title? | | — | The title, centred in the bar. It fades away once the content scrolls and while searching. |
leading? | | — | Before everything else, such as a back or menu button. Use |
searchProps? | | — | The field: its placeholder, value and callbacks. |
active? | | — | Controlled searching state: |
defaultActive? | | | Opens as a field. |
onActiveChange? | | — | Called when search opens or closes. Show suggestions or results while it's |
hideLeadingWhileActive? | | | Moves the leading button out of the way while searching, so the field takes the row. |
clearOnClose? | | | Clears the query when the close button is pressed. |
closeOnEmptyBlur? | | | Closes search when the field loses focus with nothing typed. |
scrollY? | | — | The content's vertical scroll offset, from |
collapseDistance? | | | How far the content scrolls before the header is fully collapsed. |
backdrop? | | | What the collapsed header shows behind its buttons: a blur of the content under it, or the solid background.
Reduce Transparency, and Android without a |
insetTop? | | | Extra space above the row, usually the top safe-area inset. |
haptics? | | | Plays a light tap when search opens and closes. |
messages? | | — | Replaces the built-in wording. |
motion? | | | Local motion feel or spring override. |
className? | | — | Classes merged over the header. |
style? | | — | Style escape hatch for the header. Position it absolutely over the content so the blur has something to show. |
testID? | | — | The header gets |
Composition and behavior
- A centred title, an optional leading button and a round glass search button on the trailing side. HeaderSearchButton draws a matching glass circle.
- Tap search and it stretches across the bar into a live field: the title fades, the leading button shrinks away, the keyboard comes up and a round close button takes the trailing corner.
- Close clears the query (clearOnClose) and brings everything back. hideLeadingWhileActive set to false keeps the leading button.
- Leaving the field empty closes search (closeOnEmptyBlur); with a query it stays open, so results stay on screen.
- With scrollY from useHeaderScroll, the title fades as the content scrolls and the bar turns into a blur of what is under it; back at the top the title returns. backdrop set to solid keeps the background, and collapseDistance sets how far the content scrolls first.
- Float the header over the content and pad the content by headerSearchHeight(insets.top), so the blur has something to show.
- active, defaultActive and onActiveChange let you show suggestions or results while it's open. The query and the search itself stay yours.
- Glass is never faded: the pieces move by size and scale with the morph spring, and the blur fades by its intensity. Reduce Motion makes opening and closing instant.
Behavior and gestures
- At rest the bar shows a centred title, an optional leading button and a round glass search button.
- Tap search and it stretches across the bar into a field: the title fades, the leading button shrinks away, the keyboard comes up and a round close button takes the trailing corner.
- Close clears the query (unless clearOnClose={false}), dismisses the keyboard and brings everything back.
- Leaving the field empty closes search; with a query it stays open so results stay on screen.
- As the content scrolls, the title fades and the bar turns into a blur of what is under it, keeping its buttons; back at the top the title returns.
Accessibility
- At rest the capsule is a button named after the field, and it reads the current query.
- While searching, the field is focused and the close button is labelled "Close search".
- Side buttons leave the accessibility tree while they are hidden.
- When the field is disabled or read-only, the capsule is disabled too.
Motion
- Uses the
morphandpressmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - One morph spring stretches the search button into the field, shrinks the leading button and grows the close button, on the UI thread.
- The collapse follows the scroll position; the blur fades by its intensity, never by opacity.
- Reduce Motion makes opening and closing instant.
Performance
- The morph runs from one shared value; opening and closing re-render once each, and scrolling never re-renders.
Notes for AI
- Pass the query and handlers through searchProps; your app runs the search.
- Use HeaderSearchButton for the leading button so it matches the search button.
- Show suggestions or results while onActiveChange reports true.
- Pass useHeaderScroll().scrollY so the bar collapses into a blur.
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.