Skip to main content

Vortex Provider

Vortex Provider is a root wrapper that sets up Vortex Native for your app, such as its theme and color mode.

Import

import { VortexProvider } from '@vortexlabs/vortex-native';
import type { VortexProviderProps } from '@vortexlabs/vortex-native';

Other links

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

const App = () => {
  return (
    <VortexProvider theme={vortexTheme}>
      <Root />
    </VortexProvider>
  );
};

export default App;

Features

  • Supports themes and theme overrides.
  • Supports light, dark, and system color mode preferences.
  • Supports controlled and uncontrolled color modes.
  • Follows device color scheme changes while the app runs.

Themes

theme takes a generated native theme, or a base theme followed by overrides. To switch themes, pass a different value.

import astraTheme from "@vortexlabs/vortex-themes/themes/overrides/astra/native";
import vortexTheme from "@vortexlabs/vortex-themes/themes/vortex/native";

<VortexProvider theme={[vortexTheme, astraTheme]}>
  <Root />
</VortexProvider>

System Color Mode

The provider starts in light. Set defaultColorMode="system" to follow the device setting, including changes while the app runs.

<VortexProvider theme={vortexTheme} defaultColorMode="system">
  <Panel title="Follows the device" />
</VortexProvider>

Controlled Color Mode

Pass colorMode to own the mode in your state. onColorModeChange receives the resolved mode when Vortex requests a change, such as from useTheme.

import { type ColorMode, Stack, Text, VortexProvider } from "@vortexlabs/vortex-native";
import vortexTheme from "@vortexlabs/vortex-themes/themes/vortex/native";
import React from "react";
import { Switch } from "react-native";

const App = () => {
  const [colorMode, setColorMode] = React.useState<ColorMode>("light");

  return (
    <VortexProvider theme={vortexTheme} colorMode={colorMode}>
      <Panel title="Controlled">
        <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>
      </Panel>
    </VortexProvider>
  );
};

Persisted Color Mode

Vortex doesn't save the color mode. Store the preference in your app's storage, restore it before the first render, and save it from onColorModePreferenceChange. It receives system rather than the resolved mode, so a saved system keeps following the device.

const App = () => {
  const [preference, setPreference] = React.useState<ColorModePreference>();

  React.useEffect(() => {
    storage.getItem("app:color-mode").then((stored) => {
      setPreference(stored === "light" || stored === "dark" ? stored : "system");
    });
  }, []);

  // Render nothing, or the splash screen, until the stored value loads.
  if (!preference) return null;

  return (
    <VortexProvider
      theme={vortexTheme}
      defaultColorMode={preference}
      onColorModePreferenceChange={(next) => storage.setItem("app:color-mode", next)}
    >
      <Root />
    </VortexProvider>
  );
};

App Surfaces

VortexProvider themes Vortex components only. Your app owns the root background, status bar, and safe areas. A color mode that differs from the device also doesn't reach platform UI such as alerts, pickers, and the keyboard; call React Native Appearance.setColorScheme to match it.

Accessibility

Description
VortexProvider renders no view and adds no accessibility behavior.
Following the device color scheme respects the user's system setting; save an explicit choice so it survives restarts.