Segmented Control

A segmented control is a linear set of two or more segments, each of which functions as a button.

Pro component

Requires all-access to use the source code

Apple
Apple
import * as React from 'react';
import { View } from 'react-native';

import { SegmentedControl } from '@/components/nativewindui/SegmentedControl';
import { Text } from '@/components/nativewindui/Text';

const VALUES = ['Week', 'Month', 'Year'];

const weekIndex = 0;
const monthIndex = 1;
const yearIndex = 2;

const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];

const currentDate = new Date();
const currentDay = currentDate.getDate();
const currentMonth = MONTHS[currentDate.getMonth()];
const currentYear = currentDate.getFullYear();

export default function Screen() {
  const [selectedIndex, setSelectedIndex] = React.useState(0);
  return (
    <View className="flex-1 p-4">
      <SegmentedControl
        values={VALUES}
        selectedIndex={selectedIndex}
        onIndexChange={(index) => {
          setSelectedIndex(index);
        }}
      />
      <View className="flex-1 py-8">
        {selectedIndex === weekIndex && <WeekContent />}
        {selectedIndex === monthIndex && <MonthContent />}
        {selectedIndex === yearIndex && <YearContent />}
      </View>
    </View>
  );
}

function WeekContent() {
  return (
    <View className="flex-1 gap-4">
      <Text variant="largeTitle" className="font-bold">
        {currentMonth} {currentDay}
      </Text>
      <View className="border-border bg-card gap-2 rounded-lg border p-4">
        <Text className="text-muted-foreground font-medium">Total sales</Text>
        <Text variant="title1" className="font-bold">
          $100,000
        </Text>
      </View>
    </View>
  );
}

function MonthContent() {
  return (
    <View className="flex-1 gap-4">
      <Text variant="largeTitle" className="font-bold">
        {currentMonth} {currentYear}
      </Text>
      <View className="border-border bg-card gap-2 rounded-lg border p-4">
        <Text className="text-muted-foreground font-medium">Total sales</Text>
        <Text variant="title1" className="font-bold">
          $500,000
        </Text>
      </View>
    </View>
  );
}

function YearContent() {
  return (
    <View className="flex-1 gap-4">
      <Text variant="largeTitle" className="font-bold">
        {currentYear}
      </Text>
      <View className="border-border bg-card gap-2 rounded-lg border p-4">
        <Text className="text-muted-foreground font-medium">Total sales</Text>
        <Text variant="title1" className="font-bold">
          $1,000,000
        </Text>
      </View>
    </View>
  );
}
Logo

Unlock All Pro Templates & Components

Elevate your app with powerful, native-feeling components and templates. Build faster with beautiful ready-to-use designs.

Get all-access

Usage

import { SegmentedControl } from '@/components/nativewindui/SegmentedControl';
const [selectedIndex, setSelectedIndex] = React.useState(0);

return (
  <SegmentedControl
    values={['One', 'Two', 'Three', 'Four']}
    selectedIndex={selectedIndex}
    onIndexChange={(index) => {
      setSelectedIndex(index);
    }}
  />
);

Props

SegmentedControl

Inherits all the props from React Native's TextInput component.

PropTypeDefaultDescription
enabledbooleantrueDetermines if the segment control is enabled.
onIndexChange(index: number) => voidCallback function triggered when the selected index changes.
onValueChange(value: string) => voidCallback function triggered when the selected value changes.
selectedIndexnumberThe currently selected index.
valuesstring[]Array of strings representing the segment values.
materialTextClassNamestringClass name for the text style of the segments.
iosMomentarybooleanIf true, selection won't persist visually, but the callback will still work.
© Ronin Technologies LLC 2025