TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/EvanBacon/expo-apple-targets/llms.txt
Use this file to discover all available pages before exploring further.
colors property in your target configuration allows you to define custom color assets that are added to the target’s Assets.xcassets. These colors can be used in your Swift code and support both light and dark mode.
Basic Usage
Define colors in yourexpo-target.config.js:
Color Formats
Simple Colors
Provide a CSS color string for a color that looks the same in light and dark mode:- Hex:
"#FF0000","#F00" - RGB:
"rgb(255, 0, 0)" - RGBA:
"rgba(255, 0, 0, 0.5)" - Named colors:
"red","blue","steelblue", etc.
Dynamic Colors
Provide separate colors for light and dark appearance:The color to use in light mode.
The color to use in dark mode. If omitted, the
light color is used in both modes.Using Colors in Swift
Colors are accessible as named assets in SwiftUI and UIKit:- SwiftUI
- UIKit
Special Color Names
Certain color names have special meanings and are mapped to Xcode build settings:| Name | Build Setting | Purpose |
|---|---|---|
$accent | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME | Sets the global accent color. In widgets, this is used for the tint color of buttons when editing the widget. |
$widgetBackground | ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME | Sets the background color of the widget. |
$accent
The global accent color is used throughout your extension. For widgets, it’s particularly important as it tints interactive elements in the widget configuration interface.$widgetBackground
The widget background color sets the default background for your widget. This is primarily used by widget configuration interfaces.Color Assets Generation
When you runexpo prebuild, the plugin automatically:
- Creates an
Assets.xcassetsdirectory in your target - Generates a
.colorsetsubdirectory for each color - Creates a
Contents.jsonfile with the color definitions - Converts CSS color strings to display-P3 color space
- Configures the appropriate Xcode build settings for special colors
Color Space
Colors are generated using the display-P3 color space by default, which provides a wider color gamut than sRGB and is the standard for Apple devices. The conversion from CSS colors to display-P3 is handled automatically. Colors are defined with RGBA components ranging from 0.0 to 1.0.TypeScript Type Definitions
Complete Example
Here’s a complete example showing how to define and use colors in a widget:- Config
- Swift
Best Practices
Always Support Dark Mode
Provide dark mode variants for better user experience:Use Semantic Names
Name colors based on their purpose, not their appearance:Maintain Contrast
Ensure sufficient contrast between foreground and background colors for accessibility:Set Widget Colors
Always define$accent and $widgetBackground for widgets:
Troubleshooting
Colors not showing up
- Make sure you’ve run
expo prebuildafter adding colors - Check that the color name is correctly spelled in Swift
- Verify the
Assets.xcassetsdirectory exists in your target folder
Colors look wrong in dark mode
- Ensure you’ve provided a
darkvariant - Test on an actual device or simulator with dark mode enabled
- Check the color values in the generated
Contents.jsonfiles
Accent color not working
- Make sure you’re using
$accent(with the$prefix) - Verify the
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAMEbuild setting is set - Check that the colorset was generated in
Assets.xcassets