ThemedView
TheThemedView component is a wrapper around React Native’s View component that automatically applies theme-aware background colors.
Import
Props
The component extends all standard React NativeViewProps and adds the following:
Custom background color to use in light mode. If not provided, uses the theme’s default background color.
Custom background color to use in dark mode. If not provided, uses the theme’s default background color.
Usage
Basic Usage
Custom Theme Colors
With Additional Styles
Combining with Layout Styles
How Theme Colors Work
The component uses theuseThemeColor hook to automatically select the appropriate background color based on the current theme:
- If
lightColorordarkColorare provided, those are used for the respective themes - Otherwise, it falls back to the theme’s default
backgroundcolor - The background color automatically updates when the user switches between light and dark mode
- Additional styles from the
styleprop are merged with the background color
Styling
The component accepts all standard React NativeView styles through the style prop. The background color from the theme is applied first, then your custom styles are merged on top, allowing you to override or extend the default styling.
Source Code
Location:src/components/ThemedView.tsx:10
