Skip to content

Build a themed screen

This tutorial adds a real theme contract and uses runtime token resolution in a screen component.

Save this module as theme.css.ts so Metro emits theme data without bundling authoring code.

import { createTheme, createThemeContract } from "@opsydyn/crumbs-css/style"
export const vars = createThemeContract({
color: {
canvas: null,
text: null,
},
space: {
screen: null,
},
})
export const darkTheme = createTheme(vars, {
color: {
canvas: "#0a0a0a",
text: "#f5f5f5",
},
space: {
screen: 24,
},
})
import { style } from "@opsydyn/crumbs-css/style"
import { vars } from "./theme.css"
export const screen = style({
backgroundColor: vars.color.canvas,
flex: 1,
justifyContent: "center",
padding: vars.space.screen,
})
export const title = style({
color: vars.color.text,
fontSize: 24,
fontWeight: 700,
})
import { ThemeProvider } from "@opsydyn/crumbs-css/theme/core"
import { darkTheme } from "./theme.css"
export function App({ children }) {
return <ThemeProvider theme={darkTheme}>{children}</ThemeProvider>
}
import { Text, View } from "react-native"
import { useThemedStyles } from "@opsydyn/crumbs-css/theme/core"
import * as s from "./screen.css"
export function Screen() {
const styles = useThemedStyles(s)
return (
<View style={styles.screen}>
<Text style={styles.title}>Themed screen</Text>
</View>
)
}
  • createThemeContract defines the shape and token names
  • createTheme creates concrete values
  • ThemeProvider exposes the active theme
  • useThemedStyles resolves token references before render

Next: