import{ useState }from'react';import{Host,Picker,Text}from'@expo/ui/swift-ui';import{ pickerStyle, tag }from'@expo/ui/swift-ui/modifiers';const options =['Apple','Banana','Orange'];exportdefaultfunctionSegmentedPickerExample(){const[selectedTag, setSelectedTag]=useState(options[0]);// Segmented and wheel pickers stretch to the width they are given, so they// collapse under `matchContents`.return(<Hoststyle={{ flex:1}}><Pickermodifiers={[pickerStyle('segmented')]}label="Select a fruit"selection={selectedTag}onSelectionChange={selection =>{setSelectedTag(selection);}}>{options.map(option =>(<Textkey={option}modifiers={[tag(option)]}>{option}</Text>))}</Picker></Host>);}
Menu picker
MenuPickerExample.tsx
import{ useState }from'react';import{Host,Picker,Text}from'@expo/ui/swift-ui';import{ pickerStyle, tag }from'@expo/ui/swift-ui/modifiers';const options =['Apple','Banana','Orange'];exportdefaultfunctionMenuPickerExample(){const[selectedTag, setSelectedTag]=useState(options[0]);return(<Hoststyle={{ flex:1}}><Pickermodifiers={[pickerStyle('menu')]}label="Select a fruit"selection={selectedTag}onSelectionChange={selection =>{setSelectedTag(selection);}}>{options.map(option =>(<Textkey={option}modifiers={[tag(option)]}>{option}</Text>))}</Picker></Host>);}
Wheel picker
The wheel variant is not available on Apple TV.
WheelPickerExample.tsx
import{ useState }from'react';import{Host,Picker,Text}from'@expo/ui/swift-ui';import{ pickerStyle, tag }from'@expo/ui/swift-ui/modifiers';const options =['Apple','Banana','Orange'];exportdefaultfunctionWheelPickerExample(){const[selectedTag, setSelectedTag]=useState(options[0]);return(<Hoststyle={{ flex:1}}><Pickermodifiers={[pickerStyle('wheel')]}label="Select a fruit"selection={selectedTag}onSelectionChange={selection =>{setSelectedTag(selection);}}>{options.map(option =>(<Textkey={option}modifiers={[tag(option)]}>{option}</Text>))}</Picker></Host>);}