Overview
TheuseThemeColor hook automatically selects the appropriate color based on the current color scheme (light or dark mode). It allows you to override default theme colors or use colors from your theme configuration.
Import
Usage
Using Default Theme Colors
Custom Color Overrides
Fromsrc/components/themed-view.tsx:
Text Styling
Fromsrc/components/themed-text.tsx:
Background Color Only
Fromsrc/components/parallax-scroll-view.tsx:
Parameters
An object containing optional color overrides for light and dark modes.
The name of the color from your theme configuration. Must exist in both light and dark theme objects.Available color names (based on
@/constants/theme):'text'- Primary text color'background'- Background color'tint'- Tint/accent color'icon'- Icon color'tabIconDefault'- Default tab icon color'tabIconSelected'- Selected tab icon color
Return Value
Returns astring containing the hex color value appropriate for the current color scheme.
Type Definition
How It Works
- Detects the current color scheme using
useColorScheme - Defaults to
'light'if no scheme is detected - Checks if a custom color override is provided for the current scheme
- Returns the custom color if provided, otherwise returns the color from the theme configuration
Theme Configuration
The hook uses color definitions from@/constants/theme:
Best Practices
Use Empty Object for Default Colors
When you don’t need custom overrides, pass an empty object:Provide Both Light and Dark Overrides
When overriding colors, provide both light and dark values for consistency:Create Themed Components
Use this hook to create reusable themed components:Related Hooks
useColorScheme- Get the current color scheme preference