Theming
Latty's React Native theming uses the same configure() shape as the web — pass a config prop to LattyProvider and the full color pipeline runs at mount time in pure JavaScript.
Brand customization
Override brand colors by passing a config to LattyProvider:
import { LattyProvider } from '@latty-ds/react-native';
<LattyProvider config={{ colors: { primary: '#4F46E5' } }}>
{/* all components now use indigo as primary */}
</LattyProvider>
You can override any named color — primary, secondary, success, warning, error, info, neutral:
<LattyProvider
config={{
colors: {
primary: '#4F46E5',
secondary: '#607D8B',
success: '#16a34a',
},
}}
>
How the color pipeline works
When you provide a config, the provider:
- Merges your color overrides with the defaults from
tokens.config.json - Generates a full OKLCH palette for each color using
culori(pure JS — works in Hermes and JSC, no native deps) - Builds tint/shade steps, contrast-aware text-on-fill colors, and interactive state fills
- Resolves semantic tokens for both light and dark schemes
- Memoizes the result — regeneration only happens when
configchanges by reference
Readable text on fills
Just like on the web, you never have to pick label colors. The theme engine tests white, lightest tint, deepest shade, near-black, and pure black against the fill, and uses the first that clears 3.5:1 contrast. Buttons, badges, alerts, and all other filled surfaces get readable text automatically.
Theme structure
The theme object from useLatty() contains:
| Key | What it holds |
|---|---|
colors | Full color palettes with tint/shade steps |
spacing | Spacing scale in pixels (0–25) |
border | radius, width, focusRingWidth, and radiusScale (xs/sm/md/lg/xl/full) |
typography | fontFamily and scale (15 type variants from display-2xl to label) |
duration | Animation durations: instant, fast, moderate, slow (in ms) |
ease | Easing functions for Animated: standard, emphasized |
elevation | Shadow presets (levels 0–5) as native shadow properties |
layout | Mobile constants: screenPadding, cardPadding, sectionGap, minTouchTarget |
state | Opacity tokens: disabledOpacity, pressedOpacity, scrimOpacity |
semantic | Role-based colors: text, bg, border, interactive — all resolved to hex |
Using theme values in styles
import { StyleSheet, View } from 'react-native';
import { useLatty, Text } from '@latty-ds/react-native';
function Header() {
const { theme } = useLatty();
const styles = StyleSheet.create({
container: {
backgroundColor: theme.semantic.bg.primary,
paddingHorizontal: theme.layout.screenPadding,
paddingVertical: Number(theme.spacing['3']),
},
title: {
color: theme.semantic.text.onPrimary,
},
});
return (
<View style={styles.container}>
<Text variant="h4" style={styles.title}>My App</Text>
</View>
);
}
Elevation and shadows
Elevation tokens resolve to native shadow properties that work on both iOS and Android:
import { View } from 'react-native';
import { useLatty } from '@latty-ds/react-native';
function FloatingCard({ children }) {
const { theme } = useLatty();
return (
<View
style={{
backgroundColor: theme.semantic.bg.surface,
borderRadius: theme.border.radiusScale.lg,
padding: theme.layout.cardPadding,
...theme.elevation[3],
// Spreads: shadowColor, shadowOffset, shadowOpacity, shadowRadius, elevation
}}
>
{children}
</View>
);
}
Dynamic theming
Since config is a prop, you can change the theme at runtime:
const [brand, setBrand] = useState({ colors: { primary: '#4F46E5' } });
<LattyProvider config={brand}>
<Button onPress={() => setBrand({ colors: { primary: '#dc2626' } })}>
Switch to red
</Button>
</LattyProvider>
The theme is memoized — it only regenerates when the config object reference changes. For best performance, define your config outside the component or memoize it with useMemo:
// Good — stable reference
const config = { colors: { primary: '#4F46E5' } };
function App() {
return <LattyProvider config={config}>...</LattyProvider>;
}
Differences from web theming
| Web | React Native | |
|---|---|---|
| Entry point | configure() or createStyleSheet() | LattyProvider config prop |
| Token format | CSS custom properties | JavaScript objects with numeric values |
| Font loading | URL auto-import in configure() | Use expo-font or native linking |
| Shadows | CSS box-shadow | Native shadow props + Android elevation |
| Spacing | rem values (var(--lt-spacing-4)) | Pixel numbers (theme.spacing['4']) |
| CSS overrides | :root with --lt-* overrides | Not applicable — use config prop |
Next steps
Components — browse the full React Native component catalog
Web theming — compare with the web configure() API