A toggle lets people choose between a pair of opposing states, like on and off, using a different appearance to indicate each state.
import { Icon } from '@roninoss/icons';
import { Stack } from 'expo-router';
import * as React from 'react';
import { View, ScrollView, Pressable, Text } from 'react-native';
import { Toggle } from '~/components/nativewindui/Toggle';
import { useColorScheme } from '~/lib/useColorScheme';
export default function TextScreen() {
const { colors } = useColorScheme();
const [switchValue, setSwitchValue] = React.useState(true);
return (
<>
<Stack.Screen
options={{
title: 'NativeWindUI',
headerSearchBarOptions: {
hideWhenScrolling: false,
},
headerLargeTitle: true,
headerRight() {
return (
<Pressable className="opacity-80 active:opacity-40">
<View className="opacity-90">
<Icon name="cog-outline" color={colors.foreground} />
</View>
</Pressable>
);
},
}}
/>
<ScrollView contentInsetAdjustmentBehavior="automatic" className="p-4">
<View className="border-border bg-card gap-4 rounded-xl border p-4 pb-6 shadow-sm shadow-black/10 dark:shadow-none">
<Text className="text-foreground text-center text-sm font-medium tracking-wider opacity-60">
Toggle
</Text>
<View className="items-center">
<Toggle value={switchValue} onValueChange={setSwitchValue} />
</View>
</View>
</ScrollView>
</>
);
}
npx nwui-cli@latest add toggle
import { Toggle } from '~/components/nativewindui/Toggle';
const [switchValue, setSwitchValue] = React.useState(true);
return <Toggle value={switchValue} onValueChange={setSwitchValue} />
Inherits all the props from React Native's Switch component.