Skip to main content
Home pageReact NativeTheming

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:

  1. Merges your color overrides with the defaults from tokens.config.json
  2. Generates a full OKLCH palette for each color using culori (pure JS — works in Hermes and JSC, no native deps)
  3. Builds tint/shade steps, contrast-aware text-on-fill colors, and interactive state fills
  4. Resolves semantic tokens for both light and dark schemes
  5. Memoizes the result — regeneration only happens when config changes 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:

KeyWhat it holds
colorsFull color palettes with tint/shade steps
spacingSpacing scale in pixels (0–25)
borderradius, width, focusRingWidth, and radiusScale (xs/sm/md/lg/xl/full)
typographyfontFamily and scale (15 type variants from display-2xl to label)
durationAnimation durations: instant, fast, moderate, slow (in ms)
easeEasing functions for Animated: standard, emphasized
elevationShadow presets (levels 0–5) as native shadow properties
layoutMobile constants: screenPadding, cardPadding, sectionGap, minTouchTarget
stateOpacity tokens: disabledOpacity, pressedOpacity, scrimOpacity
semanticRole-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​

WebReact Native
Entry pointconfigure() or createStyleSheet()LattyProvider config prop
Token formatCSS custom propertiesJavaScript objects with numeric values
Font loadingURL auto-import in configure()Use expo-font or native linking
ShadowsCSS box-shadowNative shadow props + Android elevation
Spacingrem values (var(--lt-spacing-4))Pixel numbers (theme.spacing['4'])
CSS overrides:root with --lt-* overridesNot applicable — use config prop

Next steps​

Components — browse the full React Native component catalog

Web theming — compare with the web configure() API