Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

useMobileNavigationTheme.ts

31 lines1.2 KB

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(): 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"],
23 background: variables["--color-screen"],
24 card: variables["--color-sheet-solid"],
25 text: variables["--color-foreground"],
26 border: variables["--color-header-border"],
27 notification: variables["--color-danger-foreground"],
28 },
29 };
30 }, [appearance, variables]);