{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "theme",
  "title": "Theme",
  "type": "registry:lib",
  "files": [
    {
      "path": "packages/registry-native/bootstrap/theme/theme.tsx",
      "content": "import * as React from 'react'\nimport { Appearance, Platform } from 'react-native'\nimport AsyncStorage from '@react-native-async-storage/async-storage'\nimport { useColorScheme as useNWColorScheme } from 'nativewind'\n\nexport type Theme = 'light' | 'dark' | 'system'\n\nexport interface ThemeContextValue {\n  theme: Theme\n  resolvedTheme: 'light' | 'dark'\n  setTheme: (theme: Theme) => void\n  /** False until the persisted preference has been read (or reading failed). */\n  hydrated: boolean\n}\n\nexport interface ThemeProviderProps {\n  children: React.ReactNode\n  defaultTheme?: Theme\n  storageKey?: string\n  colorOverrides?: ThemeColorOverrides\n}\n\n/**\n * Concrete sRGB mirrors of the CSS tokens for native host props that cannot\n * read CSS variables (Switch track/thumb colors, ActivityIndicator, icon\n * `color` props, placeholder text, shadow color). Keep the shared semantic\n * values in step with global.css.\n * Consumers using a brand preset can override the host color props directly.\n */\nexport const themeColors = {\n  light: {\n    background: '#ffffff',\n    foreground: '#0a0a0a',\n    primary: '#171717',\n    primaryForeground: '#fafafa',\n    secondaryForeground: '#171717',\n    mutedForeground: '#6e6e6e',\n    destructive: '#e7000b',\n    destructiveForeground: '#fafafa',\n    success: '#0a7e3a',\n    warning: '#a95a00',\n    warningForeground: '#fafafa',\n    chart2: '#0d9488',\n    shadow: '#000000',\n    input: '#e5e5e5',\n    switchThumb: '#ffffff',\n    switchThumbChecked: '#fafafa',\n  },\n  dark: {\n    background: '#0a0a0a',\n    foreground: '#fafafa',\n    primary: '#e5e5e5',\n    primaryForeground: '#171717',\n    secondaryForeground: '#fafafa',\n    mutedForeground: '#a1a1a1',\n    destructive: '#ff6467',\n    destructiveForeground: '#0a0a0a',\n    success: '#53be70',\n    warning: '#f5ae39',\n    warningForeground: '#0a0a0a',\n    chart2: '#2dd4bf',\n    shadow: '#000000',\n    input: 'rgba(255, 255, 255, 0.15)',\n    switchThumb: '#fafafa',\n    switchThumbChecked: '#171717',\n  },\n} as const\n\nexport type ThemeColors = { [Key in keyof (typeof themeColors)['light']]: string }\ntype ThemeColorOverrides = Partial<Record<'light' | 'dark', Partial<ThemeColors>>>\n\nconst ThemeColorsContext = React.createContext<ThemeColors | null>(null)\n\nexport function useThemeColors(): ThemeColors {\n  const colors = React.useContext(ThemeColorsContext)\n  const { colorScheme } = useNWColorScheme()\n  return colors ?? themeColors[colorScheme === 'dark' ? 'dark' : 'light']\n}\n\nconst ThemeContext = React.createContext<ThemeContextValue | null>(null)\n\nfunction isTheme(value: string | null): value is Theme {\n  return value === 'light' || value === 'dark' || value === 'system'\n}\n\nfunction systemScheme(): 'light' | 'dark' {\n  return Appearance.getColorScheme() === 'dark' ? 'dark' : 'light'\n}\n\nexport function ThemeProvider({\n  children,\n  defaultTheme = 'system',\n  storageKey = 'uipkge-theme',\n  colorOverrides,\n}: ThemeProviderProps) {\n  const { colorScheme, setColorScheme } = useNWColorScheme()\n  const [theme, setThemeState] = React.useState<Theme>(defaultTheme)\n  const [hydrated, setHydrated] = React.useState(false)\n  const userSelectedRef = React.useRef(false)\n\n  const applyTheme = React.useCallback(\n    (next: Theme) => {\n      setThemeState(next)\n      // NativeWind clears the native appearance override in System mode.\n      // The web preview still needs a concrete scheme to update its dark class.\n      setColorScheme(Platform.OS === 'web' && next === 'system' ? systemScheme() : next)\n    },\n    [setColorScheme],\n  )\n\n  React.useEffect(() => {\n    if (Platform.OS !== 'web' || theme !== 'system') return\n    const subscription = Appearance.addChangeListener(({ colorScheme: scheme }) => {\n      setColorScheme(scheme === 'dark' ? 'dark' : 'light')\n    })\n    return () => subscription.remove()\n  }, [theme, setColorScheme])\n\n  const setTheme = React.useCallback(\n    (next: Theme) => {\n      userSelectedRef.current = true\n      applyTheme(next)\n      void AsyncStorage.setItem(storageKey, next).catch(() => undefined)\n    },\n    [applyTheme, storageKey],\n  )\n\n  React.useEffect(() => {\n    let cancelled = false\n\n    async function restoreTheme() {\n      try {\n        const stored = await AsyncStorage.getItem(storageKey)\n        if (!cancelled && !userSelectedRef.current) applyTheme(isTheme(stored) ? stored : defaultTheme)\n      } catch {\n        if (!cancelled && !userSelectedRef.current) applyTheme(defaultTheme)\n      } finally {\n        if (!cancelled) setHydrated(true)\n      }\n    }\n\n    void restoreTheme()\n    return () => {\n      cancelled = true\n    }\n  }, [applyTheme, defaultTheme, storageKey])\n\n  const resolvedTheme = theme === 'system' ? (colorScheme ?? 'light') : theme\n  const value = React.useMemo(\n    () => ({ theme, resolvedTheme, setTheme, hydrated }),\n    [theme, resolvedTheme, setTheme, hydrated],\n  )\n  const colors = React.useMemo(() => {\n    const overrides = colorOverrides?.[resolvedTheme]\n    return overrides ? { ...themeColors[resolvedTheme], ...overrides } : themeColors[resolvedTheme]\n  }, [colorOverrides, resolvedTheme])\n  return (\n    <ThemeContext.Provider value={value}>\n      <ThemeColorsContext.Provider value={colors}>{children}</ThemeColorsContext.Provider>\n    </ThemeContext.Provider>\n  )\n}\n\nexport function useTheme(): ThemeContextValue {\n  const ctx = React.useContext(ThemeContext)\n  if (!ctx) throw new Error('useTheme must be used inside <ThemeProvider>')\n  return ctx\n}\n",
      "type": "registry:lib",
      "target": "~/lib/theme.tsx"
    }
  ],
  "dependencies": [
    "@react-native-async-storage/async-storage",
    "nativewind@^4.2.7"
  ],
  "devDependencies": [],
  "registryDependencies": [],
  "description": "ThemeProvider + useTheme for React Native. Persists light/dark/system with AsyncStorage, drives NativeWind colorScheme, and exposes host-component color mirrors."
}