Top tabs
Tabs for sections inside a screen: a label strip with icons, badges and an underline or pill indicator, over swipeable pages.
npx @swipeui/cli add top-tabsWhen to use it
- Switching between sibling views inside one screen, such as For you, Following and Trending.
- Category pages in a store, or Overview, Activity and Settings inside a project.
- More tabs than fit across the screen: the strip scrolls sideways and keeps the selected one in view.
- When people expect to swipe left and right between pages as well as tap labels.
When not to use it
- Top-level app sections. Use a bottom tab bar.
- Two or three short options that change one setting. Segmented control is smaller.
- Independent filters that can be combined. Use Chip group or Filter bar.
- Long, unrelated sections. Separate screens are easier to navigate.
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 top-tabs- Adds
components/swipeui/tab-bar/top-tabs.tsxand 11 shared helpers. - Installs react-native-reanimated, clsx, tailwind-merge, class-variance-authority, uniwind, react-native-worklets, expo-haptics, react-native-gesture-handler. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { TopTabs } from '@/components/swipeui/tab-bar/top-tabs';
<TopTabs value={tab} onValueChange={setTab} tabs={tabs} />;API reference
| Prop | Type | Default | Description |
|---|---|---|---|
tabs | | — | Stable unique destinations, in logical reading order. |
value? | | — | The selected tab's value, for controlled use. |
defaultValue? | | | The tab selected first when uncontrolled. |
onValueChange? | | — | Called with the next value when a tab is pressed or a page swipe lands. |
indicator? | | | The mark on the selected tab: a line under it, or a soft capsule behind it. |
fit? | | |
|
lazy? | | | Mounts a page the first time its tab is selected, instead of mounting every page at once. |
swipeEnabled? | | | Lets people swipe between pages. Tabs can always be pressed. |
disabled? | | | Turns off pressing and swiping. |
haptics? | | | Plays a selection tick when the tab changes. |
messages? | | — | Replaces the built-in spoken wording, such as "Active, 2 new". |
motion? | | | Local motion feel or spring override. |
className? | | — | Classes merged over the container. |
style? | | — | Style escape hatch for the container. |
testID? | | — | The container gets |
Composition and behavior
- tabs lists each tab's value, label and page content in reading order.
- A scrollable label strip with a sliding underline sits above the swipeable pages.
- Control it with value and onValueChange, or let it manage itself with defaultValue.
- swipeEnabled turns page swiping on or off; tapping always works.
- Each tab can have an icon and a badge; the badge is spoken with the label.
- indicator draws an underline or a pill; fit sizes tabs to their labels (scroll) or shares the width (equal).
- lazy mounts a page the first time its tab is selected.
Behavior and gestures
- Tap a label to jump to its page; the underline slides to it and you feel a light selection tick.
- Swipe the page area sideways to move to the next or previous tab; the underline follows your finger.
- The label strip scrolls on its own to keep the selected tab visible.
- Turning swipeEnabled off keeps tapping but stops page swipes, which helps when a page has its own horizontal gestures.
- When disabled, neither taps nor swipes change the selection.
Accessibility
- The strip is a tab list; each label is a tab with selected and disabled states.
- Pages you can't see are hidden from screen readers, so only the selected page is read.
- Tapping a label is always available, so swiping is never required.
- In right-to-left languages the tabs and pages follow reading order.
- Give each tab a short label; use accessibilityLabel when the visible text is ambiguous.
Motion
- Uses the
pressandselectmotion roles, so it follows your app's feel. Passmotionto tune this one instance. - The underline tracks the page swipe continuously, then settles with the select spring.
- Under Reduce Motion, pages and the strip jump instead of scrolling smoothly.
Performance
- Paging uses a native horizontal scroll view, and the underline is driven on the UI thread.
- All pages are mounted; keep heavy pages lazy inside your own content if needed.
Notes for AI
- Give every tab a unique value; duplicates throw an error.
- Give the paging area a real height, for example flex: 1 inside a screen.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| Expo Router | Yes |
| React Navigation 7 | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.