Skip to main content

Theme Switching

Your app owns the selected theme. Import the themes you need and pass the current one to VortexProvider.

Switch themes

This example switches between Vortex and Awen:

App.tsx
import { Stack, Text, VortexProvider } from "@vortexlabs/vortex-native";
import awenTheme from "@vortexlabs/vortex-themes/themes/awen/native";
import vortexTheme from "@vortexlabs/vortex-themes/themes/vortex/native";
import { useState } from "react";
import { Switch } from "react-native";

const App = () => {
  const [awen, setAwen] = useState(false);

  return (
    <VortexProvider theme={awen ? awenTheme : vortexTheme} defaultColorMode="system">
      <Stack direction="row" gap={2} align="center">
        <Switch aria-label="Use Awen" value={awen} onValueChange={setAwen} />
        <Text>Use Awen</Text>
      </Stack>
    </VortexProvider>
  );
};

export default App;

Changing the theme keeps the color mode. Load each theme's fonts before using it; see Fonts.

To keep the selection after a restart, save a theme name such as "awen" in your app's storage and map it back to the imported theme.

Switch a scoped theme

Pass a different override to a scope, or undefined to inherit the parent again:

<ThemeScope theme={rounded ? roundedTheme : undefined}>
  {children}
</ThemeScope>

Here, rounded is your app's state, and roundedTheme is an override from Scoped Theming.

Preview token changes

Pass resolved values to ThemeScope to preview a change without regenerating the theme:

const { theme } = useTheme();

<ThemeScope theme={{ borderRadius: { button: theme.borderRadius.full } }}>
  {children}
</ThemeScope>

To keep a change, add it to your config and regenerate the theme.