A picker displays one or more scrollable lists of distinct values that people can choose from.
import { Icon } from '@roninoss/icons';
import { Stack } from 'expo-router';
import * as React from 'react';
import { View, Text, ScrollView, Pressable } from 'react-native';
import { Picker, PickerItem } from '~/components/nativewindui/Picker';
import { useColorScheme } from '~/lib/useColorScheme';
export default function PickerScreen() {
const [picker, setPicker] = React.useState('blue');
const { colors } = useColorScheme();
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">
Picker
</Text>
<Picker selectedValue={picker} onValueChange={(itemValue) => setPicker(itemValue)}>
<PickerItem
label="Red"
value="red"
color={colors.foreground}
style={{
backgroundColor: colors.root,
}}
/>
<PickerItem
label="Blue"
value="blue"
color={colors.foreground}
style={{
backgroundColor: colors.root,
}}
/>
<PickerItem
label="Green"
value="green"
color={colors.foreground}
style={{
backgroundColor: colors.root,
}}
/>
</Picker>
</View>
</ScrollView>
</>
);
}
npx nwui-cli@latest add picker
npx expo install @react-native-picker/picker
import { Picker, PickerItem } from '~/components/nativewindui/Picker';
const [picker, setPicker] = React.useState('blue');
return (
<Picker selectedValue={picker} onValueChange={(itemValue) => setPicker(itemValue)}>
<PickerItem
label="Red"
value="red"
color="red"
/>
<PickerItem
label="Blue"
value="blue"
color="blue"
/>
</Picker>
);
Inherits props from @react-native-picker/picker