ColorPicker
A SwiftUI ColorPicker component for selecting colors.
Expo UI ColorPicker matches the official SwiftUI ColorPicker API and allows app users to select colors from a palette.
Usage
Basic color picker
import { useState } from 'react';
import { Host, ColorPicker } from '@expo/ui/swift-ui';
export default function ColorPickerExample() {
const [color, setColor] = useState('#FF6347');
// A color picker fills the width it is given, so `matchContents` collapses it.
return (
<Host style={{ flex: 1 }}>
<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.
import { useState } from 'react';
import { Host, ColorPicker } from '@expo/ui/swift-ui';
export default function ColorPickerOpacityExample() {
const [color, setColor] = useState('#FF634780');
return (
<Host style={{ flex: 1 }}>
<ColorPicker
label="Select a color with opacity"
selection={color}
onSelectionChange={setColor}
supportsOpacity
/>
</Host>
);
}API
import { ColorPicker } from '@expo/ui/swift-ui';Component
ColorPicker
Type: React.Element<ColorPickerProps>
Renders a ColorPicker component using SwiftUI.
ColorPickerProps
label
Optional • Type: string
A label displayed on the ColorPicker.
onSelectionChange
Optional • Type: (value: string) => void
Callback function that is called when a new color is selected.
selection
Literal type: union
The currently selected color in the format #RRGGBB or #RRGGBBAA.
Acceptable values are: string | null
supportsOpacity
Optional • Type: boolean
Whether the color picker should support opacity.
Inherited props
Modifiers
Use these modifiers in the modifiers prop of the SwiftUI version.
Modifiers for ColorPicker
Modifiers for any view
accessibilityAddTraitsaccessibilityElementaccessibilityHiddenaccessibilityHintaccessibilityIdentifieraccessibilityInputLabelsaccessibilityLabelaccessibilityRemoveTraitsaccessibilityValueactivityBackgroundTintalignmentGuideallowsTighteninganimationaspectRatiobackgroundbackgroundOverlayblurboldborderbrightnessclippedclipShapecolorInvertcontainerBackgroundcontainerRelativeFrameiOS 17+containerShapecontentShapecontentTransitioniOS 16+contrastcornerRadiuscreateModifierdisableddynamicTypeSizeenvironmentfixedSizefontforegroundColorforegroundStyleframegeometryGroupiOS 17+glassEffectglassEffectIdgrayscalegridCellAnchoriOS 16+gridCellColumnsgridCellUnsizedAxesgridColumnAlignmentiOS 16+hiddenhueRotationidignoreSafeAreaimageScaleinvalidatableContentiOS 17+italickerninglayoutPrioritylineHeightiOS 26+lineLimitlineSpacingluminanceToAlphamaskmatchedGeometryEffectminimumScaleFactormonospacedDigitmultilineTextAlignmentoffsetonAppearonDisappearonGeometryChangeonLongPressGestureonTapGestureopacityoverlaypaddingprivacySensitiveredactedrotation3DEffectrotationEffectsaturationscaleEffectshadowstrikethroughstrokeBordertextCasetinttruncationModeunderlineunredactedwidgetURLzIndex
Sources
The original Expo docs for this page:
- ColorPicker (SwiftUI) (
source-of-truth/versions/v57.0.0/sdk/ui/swift-ui/colorpicker.md)