Concepts
A theme is a set of semantic color tokens with a light and a dark palette. Every Nativra component reads them, so one command restyles your whole UI.
Every component reads its colors from one file: lib/themes/theme.ts. It is installed with the zinc theme the first time you add a component, and holds a light and a dark palette of the same semantic tokens.
bg-primary, text-muted-foreground) backed by CSS variables in global.css.// lib/themes/theme.ts — installed with your first component
export const zinc = { background: "#ffffff", primary: "#18181b", /* … */ } as const;
export const zincDark = { background: "#09090b", primary: "#fafafa", /* … */ } as const;
// What every component reads (through useThemeColors / the CSS variables)
export const themeColors = { light: zinc, dark: zincDark } as const;Replace the theme file with another preset. Every installed component picks up the new palette:
npx nativra-cli theme add midnight --overwrite --apply-css--overwrite replaces theme.ts (the old one is backed up — undo with nativra rollback midnight). --apply-css rewrites the CSS variables for NativeWind; it is harmless with StyleSheet.
Each token has a matching -foreground where text sits on it (for example primary-foreground for text on a primary button).
Colors are half the look. The other half is the style in lib/themes/style.ts: corner radii by role, a type scale, density, how cards and inputs are drawn, shadows and press feedback. It is independent of the theme, so any of the 10 color themes works with any style. Every component reads it, so one command changes the whole UI's character:
npx nativra-cli style add iosChoose one at npx nativra-cli init (or --style crisp); it is saved in nativra.json and installed with your first component. Try them all in any component's live preview with the style picker.
import { Pressable, Text } from "react-native";
import { pressedStyle, sp, surface, themeStyle, ts, useThemeColors } from "@/hooks/use-theme-colors";
export function PromoCard({ onPress }: { onPress: () => void }) {
const c = useThemeColors();
return (
<Pressable
onPress={onPress}
style={({ pressed }) => [
surface(c),
{ borderRadius: themeStyle.radius.card, padding: sp(20) },
pressedStyle(pressed),
]}
>
<Text style={{ color: c.foreground, fontSize: ts(16), fontWeight: themeStyle.fontWeight.title }}>
Matches the installed style
</Text>
</Pressable>
);
}NativeWind components use classes for the same tokens: rounded-card and the other radius roles, type-sm … type-4xl, weight-heading, weight-title, weight-label, surface, field, h-control, px-control, and density-aware spacing (sp-p-4, sp-gap-2, … mirror Tailwind's p-4 and gap-2, scaled by the style's density, while Tailwind's own classes stay unchanged for the rest of your app). The CLI generates them into global.css from the installed style, together with the color variables, and rewrites them when you switch styles.
Use the same hook in your own screens so they match the components:
import { View, Text } from "react-native";
import { useThemeColors } from "@/hooks/use-theme-colors";
export function Banner() {
const c = useThemeColors(); // follows the device's light/dark setting
return (
<View style={{ backgroundColor: c.muted, borderColor: c.border, borderWidth: 1 }}>
<Text style={{ color: c.foreground }}>Same tokens as the components</Text>
</View>
);
}When you add a component and global.css has no theme yet, the CLI writes the theme's variables there between marker comments (later --apply-css runs replace the block). The values are RGB channels so opacity modifiers like bg-primary/10 work:
:root {
--color-success: 21 128 61;
--color-success-foreground: 255 255 255;
--color-warning: 180 83 9;
--color-warning-foreground: 255 255 255;
--color-info: 3 105 161;
--color-info-foreground: 255 255 255;
--color-background: 255 255 255;
/* … */
}Map them once in your Tailwind config. add and doctor warn when this is missing, and doctor --fix includes it when it scaffolds a new config:
// tailwind.config.js — theme.extend
colors: {
border: "rgb(var(--color-border) / <alpha-value>)",
input: "rgb(var(--color-input) / <alpha-value>)",
ring: "rgb(var(--color-ring) / <alpha-value>)",
background: "rgb(var(--color-background) / <alpha-value>)",
foreground: "rgb(var(--color-foreground) / <alpha-value>)",
primary: { DEFAULT: "rgb(var(--color-primary) / <alpha-value>)", foreground: "rgb(var(--color-primary-foreground) / <alpha-value>)" },
secondary: { DEFAULT: "rgb(var(--color-secondary) / <alpha-value>)", foreground: "rgb(var(--color-secondary-foreground) / <alpha-value>)" },
muted: { DEFAULT: "rgb(var(--color-muted) / <alpha-value>)", foreground: "rgb(var(--color-muted-foreground) / <alpha-value>)" },
accent: { DEFAULT: "rgb(var(--color-accent) / <alpha-value>)", foreground: "rgb(var(--color-accent-foreground) / <alpha-value>)" },
destructive: { DEFAULT: "rgb(var(--color-destructive) / <alpha-value>)", foreground: "rgb(var(--color-destructive-foreground) / <alpha-value>)" },
success: { DEFAULT: "rgb(var(--color-success) / <alpha-value>)", foreground: "rgb(var(--color-success-foreground) / <alpha-value>)" },
warning: { DEFAULT: "rgb(var(--color-warning) / <alpha-value>)", foreground: "rgb(var(--color-warning-foreground) / <alpha-value>)" },
info: { DEFAULT: "rgb(var(--color-info) / <alpha-value>)", foreground: "rgb(var(--color-info-foreground) / <alpha-value>)" },
card: { DEFAULT: "rgb(var(--color-card) / <alpha-value>)", foreground: "rgb(var(--color-card-foreground) / <alpha-value>)" },
popover: { DEFAULT: "rgb(var(--color-popover) / <alpha-value>)", foreground: "rgb(var(--color-popover-foreground) / <alpha-value>)" },
},