Skip to main content

Color Modes

Every theme defines light and dark colors under theme.color.light and theme.color.dark. Changing the color mode keeps the selected theme.

Set the initial mode

Set defaultColorMode on VortexProvider:

import { VortexProvider } from "@vortexlabs/vortex-native";
import vortexTheme from "@vortexlabs/vortex-themes/themes/vortex/native";

<VortexProvider theme={vortexTheme} defaultColorMode="dark">
  {children}
</VortexProvider>

defaultColorMode sets the initial preference and defaults to "light".

Follow the system

Set defaultColorMode="system" to follow the device's appearance, including changes while your app is open:

<VortexProvider theme={vortexTheme} defaultColorMode="system">
  {children}
</VortexProvider>

Use setColorMode("system") from useTheme to resume following the device after an explicit selection. colorModePreference reports "system", while colorMode resolves to "light" or "dark".

In Expo, set userInterfaceStyle to automatic in app.json; see the Expo guide.

Switch modes

Render this toggle inside your provider:

src/DarkModeSwitch.tsx
import { Stack, Text, useTheme } from "@vortexlabs/vortex-native";
import { Switch } from "react-native";

export const DarkModeSwitch = () => {
  const { colorMode, setColorMode } = useTheme();

  return (
    <Stack direction="row" gap={2} align="center">
      <Switch
        aria-label="Dark mode"
        value={colorMode === "dark"}
        onValueChange={(dark) => setColorMode(dark ? "dark" : "light")}
      />
      <Text>Dark mode</Text>
    </Stack>
  );
};

setColorMode("light"), setColorMode("dark"), and invertColorMode() stop following the device. These setters change the mode for the whole provider, even when called inside a ThemeScope. To keep one section dark or inverted, use Scoped Theming.

Theme the screen background

The provider doesn't paint a background or style the status bar. Apply the resolved mode to your app's outer view:

src/AppSurface.tsx
import { useTheme } from "@vortexlabs/vortex-native";
import type { ReactNode } from "react";
import { StatusBar, View } from "react-native";

export const AppSurface = ({ children }: { children: ReactNode }) => {
  const { theme, colorMode } = useTheme();

  return (
    <View style={{ flex: 1, backgroundColor: theme.color[colorMode].backgroundDefault }}>
      <StatusBar barStyle={colorMode === "dark" ? "light-content" : "dark-content"} />
      {children}
    </View>
  );
};

Place it inside VortexProvider, around your screens. Keep the background on the outer view and apply safe-area insets inside it, so the areas behind the status bar and home indicator match. If you use a navigator, theme it with the React Navigation guide.

Control the mode

If your app owns the resolved mode, pass colorMode and handle change requests through onColorModeChange:

<VortexProvider
  theme={vortexTheme}
  colorMode={colorMode}
  onColorModeChange={setColorMode}
>
  {children}
</VortexProvider>

Here, colorMode and setColorMode are your app's state and setter. The controlled colorMode prop accepts only "light" or "dark".

Remember the preference

Use onColorModePreferenceChange to save the preference in your app's storage. Restore a validated "light", "dark", or "system" value as savedPreference before rendering the provider:

<VortexProvider
  theme={vortexTheme}
  defaultColorMode={savedPreference}
  onColorModePreferenceChange={savePreference}
>
  {children}
</VortexProvider>

Vortex doesn't persist or restore preferences. Device appearance changes don't call onColorModePreferenceChange, so a saved "system" stays "system".