GuidesModules

Theme

Wrap the app in ThemeProvider and read colors, spacing and fonts with useAppTheme.

  • Stable unknown
  • Release candidate since 1.16.1-rc.3
  • Development since 1.16.1-dev.2111+9796905

@ovok/native/theme gives every SDK component its colors, spacing, corner radii and fonts. It builds on React Native Paper's Material Design 3 theme and adds color scales, semantic success / warning / error colors and multiplier-based spacing.

Set up the theme

Wrap the app once, outside any SDK screen. ThemeProvider takes the theme configuration, loads the DM Sans fonts and renders nothing until they are ready, so place it above your splash-screen logic.

import { DEFAULT_COLORS, DEFAULT_MULTIPLIERS, ThemeProvider } from "@ovok/native";

const theme = {
  colors: { ...DEFAULT_COLORS, primary: "#2563EB" },
  dark: false,
  spacingMultiplier: DEFAULT_MULTIPLIERS.spacing,
  borderRadiusMultiplier: DEFAULT_MULTIPLIERS.borderRadius,
};

export function AppRoot({ children }: { children: React.ReactNode }) {
  return <ThemeProvider theme={theme}>{children}</ThemeProvider>;
}

Set dark for the dark variant and extraColors / fonts for app-specific colors and font families. Custom colors are used as given; check their contrast in the app.

Use the theme in your own components

import { useAppTheme } from "@ovok/native";

function Badge() {
  const theme = useAppTheme();
  return (
    <View
      style={{
        backgroundColor: theme.colors.green[100],
        padding: theme.spacing(2),
        borderRadius: theme.borderRadius(1),
      }}
    />
  );
}

spacing and borderRadius scale a step by the theme's multipliers, so a whole app can be made denser or rounder by changing spacingMultiplier or borderRadiusMultiplier in one place.

Components

API reference

Every export of @ovok/native/theme, with signatures, props and types, is in the theme API reference.

Last updated on

On this page