Reference version

This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 54).

ColorPicker

A SwiftUI ColorPicker component for selecting colors.

iOS

Expo UI ColorPicker matches the official SwiftUI ColorPicker API and allows app users to select colors from a palette.

Installation

Terminal
npx expo install @expo/ui

If you are installing this in an existing React Native app, make sure to install expo in your project.

Usage

Basic color picker

ColorPickerExample.tsx
import { useState } from 'react'; import { Host, ColorPicker } from '@expo/ui/swift-ui'; export default function ColorPickerExample() { const [color, setColor] = useState('#FF6347'); return ( <Host matchContents> <ColorPicker label="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'; export default function ColorPickerOpacityExample() { const [color, setColor] = useState('#FF634780'); return ( <Host matchContents> <ColorPicker label="Select a color with opacity" selection={color} onSelectionChange={setColor} supportsOpacity /> </Host> ); }

API

Component

ColorPicker

iOS

Type: React.Element<ColorPickerProps>

Renders a ColorPicker component using SwiftUI.

ColorPickerProps

label

iOS
Optional • Type: string

A label displayed on the ColorPicker.

onSelectionChange

iOS
Optional • Type: (value: string) => void

Callback function that is called when a new color is selected.

selection

iOS
Literal type: union

The currently selected color in the format #RRGGBB or #RRGGBBAA.

Acceptable values are: string | null

supportsOpacity

iOS
Optional • Type: boolean

Whether the color picker should support opacity.