import{ useState }from'react';import{Host,ColorPicker}from'@expo/ui/swift-ui';exportdefaultfunctionColorPickerExample(){const[color, setColor]=useState('#FF6347');// A color picker fills the width it is given, so `matchContents` collapses it.return(<Hoststyle={{ flex:1}}><ColorPickerlabel="Select a color"selection={color}onSelectionChange={setColor}/></Host>);}
Color picker with opacity support
Use the supportsOpacity prop to allow users to select colors with alpha transparency.
ColorPickerOpacityExample.tsx
import{ useState }from'react';import{Host,ColorPicker}from'@expo/ui/swift-ui';exportdefaultfunctionColorPickerOpacityExample(){const[color, setColor]=useState('#FF634780');return(<Hoststyle={{ flex:1}}><ColorPickerlabel="Select a color with opacity"selection={color}onSelectionChange={setColor}supportsOpacity/></Host>);}