React Native Theme TransitionReact Native Theme Transition

Exported Types

All TypeScript types available as named imports.

import type {
  ThemeDefinition,
  ThemeTransitionConfig,
  ThemeTransitionAPI,
  UseThemeResult,
  ThemeSelectionResult,
  SystemThemeMap,
  SetThemeOptions,
  ThemeNames,
  TokenNames,
} from 'react-native-theme-transition';

Types

ThemeDefinition

type ThemeDefinition = Record<string, string>;

A flat record where keys are token names and values are color strings.

ThemeNames<T>

type ThemeNames<T extends Record<string, ThemeDefinition>> = keyof T & string;

Union of theme name strings from your theme map.

TokenNames<T>

type TokenNames<T extends Record<string, ThemeDefinition>> =
  keyof T[ThemeNames<T>] & string;

Union of token name strings shared across all themes.

SystemThemeMap<Names>

type SystemThemeMap<Names extends string> = Record<'light' | 'dark', Names>;

Maps OS color schemes to theme names. Both keys required.

ThemeTransitionConfig<T>

Configuration for createThemeTransition. See API Reference.

FieldTypeDescription
themesTAll themes keyed by name
durationnumber?Cross-fade duration (default 350)
darkThemesThemeNames<T>[]?Themes using dark color scheme for native UI sync
systemThemeMapSystemThemeMap?OS appearance mapping
onTransitionStart(name) => voidAnimated transition start
onTransitionEnd(name) => voidAnimated transition end
onThemeChange(name) => voidAny theme change

ThemeTransitionAPI<T>

Return type of createThemeTransition. Contains ThemeTransitionProvider and useTheme.

UseThemeResult<Tokens, Names>

Base return type of useTheme().

FieldTypeDescription
colorsRecord<Tokens, string>Current color values
nameNamesActive theme name (never 'system')
setTheme(name | 'system', opts?) => booleanTrigger transition
isTransitioningbooleanCross-fade in progress

ThemeSelectionResult<Names>

Extra fields returned by useTheme({ initialSelection }).

FieldTypeDescription
selectedNames | 'system'Currently selected option
select(option) => voidSelect with transition-safe timing

SetThemeOptions<Names>

Options for setTheme.

FieldTypeDefaultDescription
animatedbooleantrueUse animation
onTransitionStart(name) => voidPer-call start callback
onTransitionEnd(name) => voidPer-call end callback

Type inference example

const light = { bg: '#fff', text: '#000' };
const dark  = { bg: '#000', text: '#fff' };

const api = createThemeTransition({ themes: { light, dark } });

const { colors, name, setTheme } = api.useTheme();

colors.bg         // type: string, autocomplete: 'bg' | 'text'
colors.foo        // TypeScript error
name              // type: 'light' | 'dark'
setTheme('dark')  // ok
setTheme('ocean') // TypeScript error
setTheme('system')// always valid

On this page