Overview
TheuseThemeColor hook provides theme-aware color values that automatically adapt to the device’s color scheme (light or dark mode). It allows components to specify custom colors for each theme or fall back to predefined theme colors.
Signature
Parameters
The name of the color from the theme palette. Available color names:
text- Primary text colorbackground- Background colortint- Tint/accent coloricon- Icon colortabIconDefault- Default tab icon colortabIconSelected- Selected tab icon color
Return Value
Returns a string containing the appropriate color value based on the current color scheme. If a custom color is provided inprops for the current theme, it returns that; otherwise, it returns the color from the theme palette.
Theme Colors
The default theme colors are defined inconstants/theme.ts:
Light Mode
text:#11181Cbackground:#ffftint:#0a7ea4icon:#687076tabIconDefault:#687076tabIconSelected:#0a7ea4
Dark Mode
text:#ECEDEEbackground:#151718tint:#ffficon:#9BA1A6tabIconDefault:#9BA1A6tabIconSelected:#fff
Usage Examples
Using Theme Defaults
Using Custom Colors
Themed Text Component
Accessing Multiple Colors
Implementation Details
- Uses
useColorSchemefrom React Native to detect the current color scheme - Falls back to
'light'if the color scheme cannot be determined - Custom colors in
propstake precedence over theme defaults - Works seamlessly with React Native’s automatic dark mode support
Related Hooks
useColorScheme- From React Native, returns the current color scheme ('light'or'dark')
Source
Defined inhooks/use-theme-color.ts:9