Usage
Wrap your app in LattyProvider
Every Latty component reads its theme from context. Wrap your root component in LattyProvider:
App.tsx
import { LattyProvider } from '@latty-ds/react-native';
export default function App() {
return (
<LattyProvider>
{/* your app */}
</LattyProvider>
);
}
With React Navigation:
App.tsx
import { LattyProvider } from '@latty-ds/react-native';
import { NavigationContainer } from '@react-navigation/native';
export default function App() {
return (
<LattyProvider>
<NavigationContainer>
{/* navigators and screens */}
</NavigationContainer>
</LattyProvider>
);
}
Using components
Import components directly from the package:
import { Button, Text, Textfield, Badge, Surface } from '@latty-ds/react-native';
function SignUp() {
return (
<Surface elevation={1} style={{ padding: 24 }}>
<Text variant="h3">Create account</Text>
<Textfield label="Email" size="md" />
<Button variant="primary" onPress={() => {}}>
Sign up
</Button>
<Badge variant="success">New</Badge>
</Surface>
);
}
Accessing the theme
Use the useLatty() hook inside any component under the provider to read theme values directly:
import { View } from 'react-native';
import { useLatty, Text } from '@latty-ds/react-native';
function Card({ children }: { children: React.ReactNode }) {
const { theme, colorScheme } = useLatty();
return (
<View
style={{
backgroundColor: theme.semantic.bg.surface,
borderRadius: theme.border.radiusScale.md,
padding: theme.layout.cardPadding,
...theme.elevation[2],
}}
>
{children}
</View>
);
}
useLatty() returns:
theme — the fully resolved LattyTheme for the active color schemecolorScheme — the resolved scheme: 'light' or 'dark'Color scheme
By default, LattyProvider follows the device's system preference. Pin it to a specific scheme with the colorScheme prop:
// Always dark
<LattyProvider colorScheme="dark">
// Always light
<LattyProvider colorScheme="light">
// Follow device (default)
<LattyProvider colorScheme="system">
Typography
Use the Text component with a variant prop for consistent type hierarchy:
import { Text } from '@latty-ds/react-native';
<Text variant="display-xl">Hero</Text>
<Text variant="h1">Page Title</Text>
<Text variant="body">Paragraph text</Text>
<Text variant="caption">Fine print</Text>
<Text variant="overline">Section Label</Text>
Available variants: display-2xl, display-xl, display-lg, h1–h6, lead, body, body-sm, caption, overline, label.
Next steps
Theming — customize brand colors and the color pipeline
Components — browse the full component catalog