Overview
While Uniwind provideslight and dark themes by default, you can create unlimited custom themes for advanced use cases. Custom themes are perfect for branding variations, seasonal themes, accessibility modes, or any scenario where you need more than two color schemes.
Custom themes work exactly like the default themes, with full support for theme switching and CSS variable management.
Creating a Custom Theme
Creating a custom theme involves two steps:- Define theme-specific CSS variables in
global.css - Register the theme in
metro.config.js
Step 1: Define Theme Variables in global.css
Add your custom theme using the@variant directive. All themes must define the same set of variables.
Example: Adding a “Premium” Theme
global.css
Step 2: Register Theme in metro.config.js
Add your custom theme to theextraThemes array in your Metro configuration:
metro.config.js
Step 3: Use Your Custom Theme
Switch to your custom theme programmatically:Complete Example: Multiple Custom Themes
Here’s a complete example with multiple custom themes for different use cases:global.css with Multiple Themes
global.css
metro.config.js with Multiple Themes
metro.config.js
Theme Switcher Component
Create a theme switcher that includes your custom themes:ThemeSwitcher.tsx
Best Practices
Troubleshooting
Theme not appearing
- Check that the theme is registered in
extraThemesarray - Verify all CSS variables are defined in the
@variant - Restart Metro bundler
- Clear Metro cache:
npx expo start --clear
Missing styles
- Ensure all themes define the same set of CSS variables
- Check for typos in variable names
- Look for warnings in
__DEV__mode about missing variables
Related
Theming Basics
Learn the fundamentals of theming in Uniwind
Global CSS
Configure global styles and CSS variables
Update CSS Variables
Dynamically update CSS variables at runtime
useUniwind Hook
Access theme information in your React components
Style Based on Themes
Advanced theme-based styling techniques