Skip to content
  • Introduction
    nativecn is shadcn for Expo apps: Components you copy into your app and own, built so AI agents can build and verify whole mobile apps.
  • Installation
    Create a new Expo app with nativecn, or add nativecn to an existing one.
  • components.json
    The project file that records your Preset, Structure, aliases and agents.
  • CLI
    Every nativecn-cli command and flag: init, create, add, agents and mcp.
  • Changelog
    What changed in each nativecn release.
  • Theming
    Tokens, Colour Roles, Scale, Scheme, createStyles and fonts.
  • Presets & Styles
    Style, Base Colour, Accent Colour, Radius and fonts: chosen once, baked into your code.
  • Folder structure
    Flat and feature Structures, Destinations and the placement rule.
  • AI agents
    Rules, Skills, the nativecn MCP server, the Plugin and the Visual QA Loop.
  • Alert
    Alert, AlertTitle and AlertDescription: an inline message with Variants (default, destructive, success, warning, info), each with a default icon.
  • Avatar
    Round user image (expo-image) with fallback initials, in sizes sm, md and lg.
  • Badge
    Small status label with Variants default, secondary, outline, destructive, success and warning.
  • Button
    Button with Variants (primary, secondary, outline, ghost, destructive, link), Sizes, an icon slot, loading and status; icon-only requires aria-label.
  • Card
    Card surface with CardHeader, CardTitle, CardDescription, CardContent and CardFooter; onPress makes the whole card pressable.
  • Checkbox
    Checkbox with an optional label, controlled or uncontrolled, an indeterminate (mixed) state and a haptic tick.
  • Chip
    Chip (plain, toggle or removable, with an optional icon) and ChipGroup (single or multiple choice on the SelectionGroup Primitive), with a haptic tick.
  • Container
    Wraps a Screen: safe-area edges, scrolling, keyboard avoidance, Token padding and a max content width.
  • Drawer
    Drawer panel content for Expo Router's drawer (expo-router/drawer): DrawerContent, DrawerHeader, DrawerSection, DrawerItem (label, icon, href, badge; active from the current route) and DrawerFooter.
  • Empty State
    What a Screen or list shows when there is nothing to show yet: an icon, a title, a description and an action.
  • FormField
    Lays out a control with its Label, description and error, and links them for screen readers ("Email, text field, Enter a valid email").
  • Icon
    Every glyph: a Lucide icon at a Token size in a Colour Role, decorative unless labelled.
  • Input
    Single-line text field with Sizes, a leading icon, error/success status, a focus ring and an automatic Show/Hide password toggle.
  • InputOTP
    One-time code field: one hidden input drives N cells; numeric keyboard, SMS/Keychain autofill, paste, onComplete, error/success status and secure.
  • Label
    A field's visible label in the label type Variant, with a required marker read as "required".
  • List
    Settings-style rows: ListSection, ListSectionHeader, ListSectionFooter and ListItem (title, description, icon, trailing, chevron, destructive, onPress); FlashList-safe.
  • Progress
    A horizontal progress bar: a value 0–100 that animates, or indeterminate; role progressbar with its value.
  • RadioGroup
    RadioGroup and RadioGroupItem: a single choice from a list on the SelectionGroup Primitive, vertical or horizontal, with a haptic tick.
  • SchemeSwitcher
    Theme switcher / dark mode toggle: System, Light and Dark as SegmentedTabs, or one icon button cycling through them. Calls setScheme, which persists the choice.
  • SearchField
    Search box with a search icon, an automatic clear (×) button, a loading spinner and onSubmit from the keyboard's Search key.
  • SegmentedTabs
    In-screen tabs (not navigation): segmented or underline Variants, an animated indicator, and only the selected tab's content rendered.
  • Separator
    A hairline divider, horizontal or vertical, decorative by default.
  • Skeleton
    A placeholder shape shown while content loads; pulses unless Reduce Motion is on, hidden from screen readers.
  • Slider
    Pick a number in a range by dragging or tapping (Gesture Handler + Reanimated), snapped to steps with a haptic tick; adjustable for screen readers.
  • Spinner
    An indeterminate loading indicator in a Colour Role, announced as busy; still under Reduce Motion.
  • Switch
    A themed on/off Switch, identical on iOS and Android, with an optional label, a thumb that slides (instant under Reduce Motion) and a haptic tick.
  • TabNavigation
    The bottom tab bar: the custom tabBar of an Expo Router JS Tabs Layout, with classic and floating Variants, per-tab icons and badges from Tabs.Screen options.
  • Text
    All text: the type ramp as Variants, text Colour Roles, alignment and the font-scaling switch.
  • Textarea
    Multi-line text field that grows from minRows to maxRows, with a character counter when maxLength is set.
  • Toast
    Sonner-style Toasts: a <Toaster /> in the root Layout and toast(), toast.success/error/info/warning/dismiss. At most 3 stacked, 4s auto-dismiss, swipe away, announced, above native modals.
  • Profile header + grouped sections
    Drawer panel with a profile header (avatar, name, email, plan Badge), labelled sections (Main, Workspace, Support) and Log out pinned in the footer.
  • SaaS workspace
    Drawer panel for a SaaS workspace: logo and name with a close button, an Accent Colour onboarding item with a 5 Steps Badge, main items, a bottom group (Notifications with a count, Settings, Docs, Help) and a footer with a team switcher and the user's avatar.
  • Cover header
    Drawer panel with a dark cover (large avatar, name, View profile, a bell with a count, an overflow button and a round + action), icon items active in Accent Colour text, a divider and text-only secondary items.
  • Classic centred
    A centred sign-in Screen: logo, email and password, Forgot password, an "or" divider, then Apple and Google, and a Sign up link.
  • Social-first hero
    A social-first sign-in Screen: a dark brand hero (logo, headline, subtitle, centred) above a panel where Apple and Google lead and "Continue with email" reveals the email form.
  • Email-first, two steps
    An email-first sign-in Screen in two steps: the email, then the password, with "Email me a code instead" switching to a 6-digit code (InputOTP). Lucide chevron-left Back buttons.
  • Classic single form
    A classic sign-up Screen on one scroll: Apple and Google on top, "or", then name, email and password, a terms Checkbox with Terms and Privacy Policy links, Create account, and a Sign in link.
  • Step-by-step wizard
    A sign-up wizard, one question per step under a Progress bar: email, name, password, then a 6-digit code (InputOTP). Lucide chevron-left Back buttons; the Continue button rides above the keyboard.
  • Social-first + verify
    A brand-led, passwordless sign-up Screen: the logo and headline centred above Apple and Google; "Sign up with email" reveals the email field, and Send code moves on to a 6-digit code (InputOTP).
  • announce
    Reliable screen-reader announcements on iOS and Android (Button and Input status, Toast, error, success and warning Alerts).
  • FocusChain
    Automatic Next/Done between fields in on-screen order; Done submits the form.
  • FormField context
    Links a field to its label, description and error for screen readers; passes status, disabled and required down.
  • Keyboard
    KeyboardProvider setup, a scroll view that keeps the focused field above the keyboard, and a footer that keeps a form's main button above it.
  • Portal
    Renders content above every Screen (above native modals on iOS), layered and safe-area aware.
  • Pressable
    Pressed look from a Style Slot, tap area extended to 48, no handlers while disabled or loading, optional haptics, role and aria-* states.
  • SelectionGroup
    Single or multiple choice within a group, with radio, tab or checkbox roles and selected states.
  • useControllableState
    One implementation of controlled and uncontrolled values for form controls.
  • useMotion
    Enter/exit animations and timing/spring configs from the motion Tokens; instant when Reduce Motion is on.
  • Theme
    Tokens, Scale, Colour Roles, ThemeProvider, createStyles and the navigation theme.

SegmentedTabs

In-screen tabs (not navigation): segmented or underline Variants, an animated indicator, and only the selected tab's content rendered.

View as Markdown
Componentnavigation
Style

Light

Dark

Your app is ready.

Inter body text, Inter headings.

smmdlgxl
you@example.com
Continue
Default Preset a0: Vega, neutral, neutral accent, default radius, Inter.Change Preset

Installation

$npx nativecn-cli@latest add segmented-tabs

Also installs: theme, selection-group, pressable, text, icon, use-controllable-state, use-motion.

Packages: react-native-reanimated, react-native-worklets, lucide-react-native@^1.51.0, react-native-svg.

Usage

SegmentedTabs demo

Uncontrolled segmented tabs with icons, and controlled underline tabs.

import { Bell, User } from "lucide-react-native";
import { useState } from "react";
import { View } from "react-native";

import {
  SegmentedTabs,
  SegmentedTabsContent,
  SegmentedTabsList,
  SegmentedTabsTrigger,
} from "@/components/segmented-tabs";
import { Text } from "@/components/text";
import { createStyles } from "@/theme";

const useStyles = createStyles((t) => ({ root: { gap: t.spacing[8] } }));

export default function SegmentedTabsDemo() {
  const styles = useStyles();
  const [period, setPeriod] = useState("week");
  return (
    <View style={styles.root}>
      {/* Uncontrolled, segmented (the default Variant), with icons. */}
      <SegmentedTabs defaultValue="account">
        <SegmentedTabsList>
          <SegmentedTabsTrigger value="account" label="Account" icon={User} />
          <SegmentedTabsTrigger value="notifications" label="Notifications" icon={Bell} />
        </SegmentedTabsList>
        <SegmentedTabsContent value="account">
          <Text>Your name, email and password.</Text>
        </SegmentedTabsContent>
        <SegmentedTabsContent value="notifications">
          <Text>Choose what we send you.</Text>
        </SegmentedTabsContent>
      </SegmentedTabs>

      {/* Controlled, underline. */}
      <SegmentedTabs value={period} onValueChange={setPeriod} variant="underline">
        <SegmentedTabsList>
          <SegmentedTabsTrigger value="day" label="Day" />
          <SegmentedTabsTrigger value="week" label="Week" />
          <SegmentedTabsTrigger value="month" label="Month" />
        </SegmentedTabsList>
        <SegmentedTabsContent value="day">
          <Text>Activity today.</Text>
        </SegmentedTabsContent>
        <SegmentedTabsContent value="week">
          <Text>Activity this week.</Text>
        </SegmentedTabsContent>
        <SegmentedTabsContent value="month">
          <Text>Activity this month.</Text>
        </SegmentedTabsContent>
      </SegmentedTabs>
    </View>
  );
}

Props

SegmentedTabs

PropType and description
valuestring: the selected tab's value (controlled)
defaultValuestring: the tab selected first (uncontrolled)
onValueChange(value: string) => void: called when the user picks a tab
variant"segmented" (default) | "underline"
disabledboolean: disables every tab (default false)
styleViewStyle, layout only, merged last

SegmentedTabsList

PropType and description
childrenSegmentedTabsTrigger elements; announced as a tablist
styleViewStyle, layout only, merged last

SegmentedTabsTrigger

PropType and description
valuestring: identifies the tab (required)
labelstring: the visible text and accessible name (required)
iconLucideIcon: shown before the label
disabledboolean: disables this tab (default false)
styleViewStyle, layout only, merged last

SegmentedTabsContent

PropType and description
valuestring: the tab this panel belongs to; rendered only while it is selected
styleViewStyle, merged last

Variants

  • segmented, underline

Accessibility

  • SegmentedTabsList is a tablist; each SegmentedTabsTrigger has role tab with aria-selected.
  • SegmentedTabsContent has role tabpanel.
  • A trigger's label is its accessible name, and its tap area is at least 48.
  • disabled tabs are announced as disabled.
  • The sliding indicator is hidden from screen readers and jumps instantly under Reduce Motion.

Notes

For switching views inside one Screen (Account / Notifications, Day / Week / Month). It is not navigation: never use it in place of Expo Router's Tabs; the bottom tab bar is TabNavigation. Put SegmentedTabsTriggers in a SegmentedTabsList, then one SegmentedTabsContent per tab after it; only the selected Content renders. Works controlled (value + onValueChange) or uncontrolled (defaultValue). Tabs give a light haptic tick when chosen. The indicator slides with the fast motion Token. Styles come from the segmented-tabs.list, segmented-tabs.trigger and segmented-tabs.pressed Style Slots.

Source

The Vega Style's code, exactly as add copies it into your app.

{components}/segmented-tabs.tsx

import type { LucideIcon } from "lucide-react-native";
import {
  createContext,
  use,
  useCallback,
  useEffect,
  useMemo,
  useRef,
  useState,
  type ReactNode,
  type Ref,
} from "react";
import {
  View,
  type GestureResponderEvent,
  type LayoutChangeEvent,
  type StyleProp,
  type ViewProps,
  type ViewStyle,
} from "react-native";
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";

import { Icon } from "@/components/icon";
import { Pressable, type PressableProps } from "@/components/primitives/pressable";
import { SelectionGroup, useSelectionItem } from "@/components/primitives/selection-group";
import { Text } from "@/components/text";
import { useControllableState } from "@/hooks/use-controllable-state";
import { useMotion } from "@/hooks/use-motion";
import { createStyles } from "@/theme";

/**
 * - `segmented`: a filled track with a raised pill under the selected tab (iOS segmented control).
 * - `underline`: tabs on a bottom border with a bar under the selected tab.
 */
const variants = {
  segmented: { list: "segmentedList", trigger: "segmentedTrigger", indicator: "pill" },
  underline: { list: "underlineList", trigger: "underlineTrigger", indicator: "bar" },
} as const;

export type SegmentedTabsVariant = keyof typeof variants;

type SegmentedTabsContextValue = {
  value: string | undefined;
  setValue: (value: string) => void;
  variant: SegmentedTabsVariant;
  disabled: boolean;
};

const SegmentedTabsContext = createContext<SegmentedTabsContextValue | null>(null);

function useSegmentedTabs(part: string): SegmentedTabsContextValue {
  const context = use(SegmentedTabsContext);
  if (!context) throw new Error(`<${part}> must be used inside <SegmentedTabs>.`);
  return context;
}

type TriggerLayout = { x: number; width: number };
type ListContextValue = { reportLayout: (value: string, layout: TriggerLayout) => void };
const ListContext = createContext<ListContextValue | null>(null);

const useStyles = createStyles((t) => {
  const list = {
    height: t.scaleValue(40),
    borderRadius: t.radius.lg,
    padding: t.scaleValue(3),
  };
  const trigger = { borderRadius: t.radius.md };
  return {
    root: { gap: t.spacing[4] },
    segmentedList: {
      ...list,
      flexDirection: "row",
      alignItems: "stretch",
      borderCurve: "continuous",
      backgroundColor: t.colors.muted,
    },
    underlineList: {
      height: list.height,
      flexDirection: "row",
      alignItems: "stretch",
      borderBottomWidth: t.borderWidth.default,
      borderBottomColor: t.colors.border,
    },
    trigger: {
      flex: 1,
      flexDirection: "row",
      alignItems: "center",
      justifyContent: "center",
      gap: t.spacing[2],
      paddingHorizontal: t.spacing[3],
    },
    segmentedTrigger: { ...trigger, borderCurve: "continuous" },
    underlineTrigger: {},
    pressed: { opacity: 0.7 },
    disabled: { opacity: t.opacity.disabled },
    indicator: { position: "absolute", left: 0 },
    pill: {
      top: list.padding,
      bottom: list.padding,
      borderRadius: trigger.borderRadius,
      borderCurve: "continuous",
      backgroundColor: t.colors.background,
      boxShadow: t.elevation.sm,
    },
    bar: {
      bottom: 0,
      height: t.scaleValue(2),
      backgroundColor: t.colors.foreground,
    },
    label: { flexShrink: 1 },
  };
});

export type SegmentedTabsProps = Omit<ViewProps, "children"> & {
  /** The selected tab (controlled). */
  value?: string;
  /** The tab selected first (uncontrolled). */
  defaultValue?: string;
  /** Called with the tab's `value` when the user picks it. */
  onValueChange?: (value: string) => void;
  /** Default `segmented`. */
  variant?: SegmentedTabsVariant;
  /** Disables every tab. */
  disabled?: boolean;
  /** Layout only, merged last onto the root. */
  style?: StyleProp<ViewStyle>;
  ref?: Ref<View>;
  children?: ReactNode;
};

/**
 * In-screen tabs: a SegmentedTabsList of SegmentedTabsTriggers, then one SegmentedTabsContent
 * per tab (only the selected one renders). Not navigation: use TabNavigation for the bottom bar.
 * Works controlled (`value` + `onValueChange`) or uncontrolled (`defaultValue`).
 */
export function SegmentedTabs({
  value: valueProp,
  defaultValue,
  onValueChange,
  variant = "segmented",
  disabled = false,
  style,
  children,
  ...props
}: SegmentedTabsProps) {
  const styles = useStyles();
  const [value, setValue] = useControllableState<string | undefined>({
    value: valueProp,
    defaultValue,
    onChange: onValueChange as ((next: string | undefined) => void) | undefined,
  });
  const context = useMemo<SegmentedTabsContextValue>(
    () => ({ value, setValue, variant, disabled }),
    [value, setValue, variant, disabled],
  );

  return (
    <SegmentedTabsContext value={context}>
      <View style={[styles.root, style]} {...props}>
        {children}
      </View>
    </SegmentedTabsContext>
  );
}

export type SegmentedTabsListProps = Omit<ViewProps, "children" | "role"> & {
  /** Layout only, merged last onto the list. */
  style?: StyleProp<ViewStyle>;
  ref?: Ref<View>;
  children?: ReactNode;
};

/** The row of tabs (`tablist`), with the selected-tab indicator that slides between them. */
export function SegmentedTabsList({ style, children, ...props }: SegmentedTabsListProps) {
  const { value, setValue, variant, disabled } = useSegmentedTabs("SegmentedTabsList");
  const styles = useStyles();
  const motion = useMotion();
  const v = variants[variant];

  const [layouts, setLayouts] = useState<Record<string, TriggerLayout>>({});
  const reportLayout = useCallback((key: string, layout: TriggerLayout) => {
    setLayouts((prev) => {
      const current = prev[key];
      if (current && current.x === layout.x && current.width === layout.width) return prev;
      return { ...prev, [key]: layout };
    });
  }, []);
  const listContext = useMemo(() => ({ reportLayout }), [reportLayout]);

  // The indicator jumps into place the first time, then slides (instantly under Reduce Motion).
  const x = useSharedValue(0);
  const width = useSharedValue(0);
  const visible = useSharedValue(0);
  const placed = useRef(false);
  const target = value === undefined ? undefined : layouts[value];
  useEffect(() => {
    if (!target) {
      visible.value = 0;
      placed.current = false;
      return;
    }
    if (placed.current) {
      const timing = motion.timing("fast");
      x.value = withTiming(target.x, timing);
      width.value = withTiming(target.width, timing);
    } else {
      x.value = target.x;
      width.value = target.width;
      placed.current = true;
    }
    visible.value = 1;
  }, [target, motion, x, width, visible]);

  const indicatorStyle = useAnimatedStyle(() => ({
    width: width.value,
    opacity: visible.value,
    transform: [{ translateX: x.value }],
  }));

  return (
    <ListContext value={listContext}>
      <SelectionGroup
        type="single"
        itemRole="tab"
        value={value ?? ""}
        onValueChange={setValue}
        disabled={disabled}
        style={[styles[v.list], style]}
        {...props}
      >
        <Animated.View
          testID="segmented-tabs-indicator"
          pointerEvents="none"
          aria-hidden
          importantForAccessibility="no-hide-descendants"
          style={[styles.indicator, styles[v.indicator], indicatorStyle]}
        />
        {children}
      </SelectionGroup>
    </ListContext>
  );
}

export type SegmentedTabsTriggerProps = Omit<
  PressableProps,
  "children" | "style" | "pressedStyle" | "role" | "haptic" | "loading"
> & {
  /** Identifies the tab; the matching SegmentedTabsContent shows while it is selected. */
  value: string;
  /** The visible text, which is also the accessible name. */
  label: string;
  /** A Lucide icon component shown before the label. */
  icon?: LucideIcon;
  /** Layout only, merged last onto the tab. */
  style?: StyleProp<ViewStyle>;
};

/** One tab: `role="tab"` with `aria-selected`, a light haptic tick when chosen. */
export function SegmentedTabsTrigger({
  value,
  label,
  icon,
  disabled: ownDisabled = false,
  onPress,
  onLayout,
  style,
  ...props
}: SegmentedTabsTriggerProps) {
  const { variant } = useSegmentedTabs("SegmentedTabsTrigger");
  const list = use(ListContext);
  if (!list) throw new Error("<SegmentedTabsTrigger> must be used inside <SegmentedTabsList>.");
  const styles = useStyles();
  const { selected, disabled, itemProps } = useSelectionItem({ value, disabled: ownDisabled });
  const color = selected ? "foreground" : "mutedForeground";

  const { reportLayout } = list;
  const handleLayout = useCallback(
    (event: LayoutChangeEvent) => {
      onLayout?.(event);
      const { x, width } = event.nativeEvent.layout;
      reportLayout(value, { x, width });
    },
    [onLayout, reportLayout, value],
  );

  const handlePress = (event: GestureResponderEvent) => {
    itemProps.onPress();
    onPress?.(event);
  };

  return (
    <Pressable
      {...props}
      {...itemProps}
      onPress={handlePress}
      onLayout={handleLayout}
      haptic="selection"
      pressedStyle={styles.pressed}
      style={[
        styles.trigger,
        styles[variants[variant].trigger],
        disabled ? styles.disabled : null,
        style,
      ]}
    >
      {icon ? <Icon icon={icon} size="sm" color={color} /> : null}
      <Text variant="label" color={color} numberOfLines={1} style={styles.label}>
        {label}
      </Text>
    </Pressable>
  );
}

export type SegmentedTabsContentProps = Omit<ViewProps, "role"> & {
  /** Shown only while the tab with this `value` is selected. */
  value: string;
  /** Layout only, merged last. */
  style?: StyleProp<ViewStyle>;
  ref?: Ref<View>;
};

/** The panel for one tab (`tabpanel`). Only the selected tab's Content is rendered. */
export function SegmentedTabsContent({ value, style, ...props }: SegmentedTabsContentProps) {
  const { value: selected } = useSegmentedTabs("SegmentedTabsContent");
  if (selected !== value) return null;
  return <View role="tabpanel" style={style} {...props} />;
}