1import { DarkTheme, DefaultTheme, type Theme } from "@react-navigation/native";
2import { useMemo } from "react";
3
4import { useAppearancePreferences } from "../features/settings/appearance/AppearancePreferencesProvider";
5import { useUniwindTheme } from "./useUniwindTheme";
6
7/**
8 * React Navigation requires a JS theme object. Derive it from the same palette
9 * source as Uniwind instead of subscribing the app root to CSS variables. The
10 * preferences provider applies the registered Uniwind theme first, then
11 * publishes this matching navigation palette through React.
12 */
13export function useMobileNavigationTheme(surface: "screen" | "sidebar" = "screen"): Theme {
14 const { themeAppearance: appearance } = useAppearancePreferences();
15 const variables = useUniwindTheme();
16 return useMemo(() => {
17 const base = appearance === "dark" ? DarkTheme : DefaultTheme;
18 return {
19 ...base,
20 colors: {
21 ...base.colors,
22 primary: variables["--color-primary-text"],
23 background: variables[surface === "sidebar" ? "--color-drawer" : "--color-screen"],
24 card: variables[surface === "sidebar" ? "--color-drawer" : "--color-sheet-solid"],
25 text: variables[
26 surface === "sidebar" ? "--color-drawer-foreground" : "--color-header-foreground"
27 ],
28 border:
29 variables[surface === "sidebar" ? "--color-drawer-border" : "--color-header-border"],
30 notification: variables["--color-danger-foreground"],
31 },
32 };
33 }, [appearance, surface, variables]);
34}