Import apps/android/src/ui/theme-context.tsx
This commit is contained in:
parent
f91ad785ab
commit
3880ccbd23
|
|
@ -1,30 +1,42 @@
|
||||||
import { createContext, useContext, useMemo, type ReactNode } from 'react'
|
import { createContext, useContext, useMemo, type ReactNode } from 'react'
|
||||||
import { useColorScheme } from 'react-native'
|
import { useColorScheme } from 'react-native'
|
||||||
import { useAppStore } from '../state/store'
|
import { useAppStore } from '../state/store'
|
||||||
import { colorsForScheme, resolveColorScheme, type ColorScheme, type ThemeColors, type TypographyDensity } from './theme'
|
import {
|
||||||
|
DEFAULT_CHAT_APPEARANCE,
|
||||||
|
resolveColorScheme,
|
||||||
|
resolveThemeColors,
|
||||||
|
type ChatAppearance,
|
||||||
|
type ColorScheme,
|
||||||
|
type ThemeColors,
|
||||||
|
type TypographyDensity,
|
||||||
|
} from './theme'
|
||||||
|
|
||||||
export interface Theme {
|
export interface Theme {
|
||||||
colors: ThemeColors
|
colors: ThemeColors
|
||||||
scheme: ColorScheme
|
scheme: ColorScheme
|
||||||
density: TypographyDensity
|
density: TypographyDensity
|
||||||
|
appearance: ChatAppearance
|
||||||
}
|
}
|
||||||
|
|
||||||
const ThemeContext = createContext<Theme>({
|
const ThemeContext = createContext<Theme>({
|
||||||
colors: colorsForScheme('light'),
|
colors: resolveThemeColors('light', DEFAULT_CHAT_APPEARANCE.accent),
|
||||||
scheme: 'light',
|
scheme: 'light',
|
||||||
density: 'compact',
|
density: 'compact',
|
||||||
|
appearance: DEFAULT_CHAT_APPEARANCE,
|
||||||
})
|
})
|
||||||
|
|
||||||
export function ThemeProvider({ children }: { children: ReactNode }) {
|
export function ThemeProvider({ children }: { children: ReactNode }) {
|
||||||
const themePreference = useAppStore(state => state.themePreference)
|
const themePreference = useAppStore(state => state.themePreference)
|
||||||
const density = useAppStore(state => state.typographyDensity)
|
const density = useAppStore(state => state.typographyDensity)
|
||||||
|
const appearance = useAppStore(state => state.chatAppearance)
|
||||||
const systemScheme = useColorScheme()
|
const systemScheme = useColorScheme()
|
||||||
const scheme = resolveColorScheme(themePreference, systemScheme === 'dark' ? 'dark' : systemScheme === 'light' ? 'light' : undefined)
|
const scheme = resolveColorScheme(themePreference, systemScheme === 'dark' ? 'dark' : systemScheme === 'light' ? 'light' : undefined)
|
||||||
const value = useMemo<Theme>(() => ({
|
const value = useMemo<Theme>(() => ({
|
||||||
colors: colorsForScheme(scheme),
|
colors: resolveThemeColors(scheme, appearance.accent),
|
||||||
scheme,
|
scheme,
|
||||||
density,
|
density,
|
||||||
}), [scheme, density])
|
appearance,
|
||||||
|
}), [scheme, density, appearance])
|
||||||
|
|
||||||
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>
|
return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>
|
||||||
}
|
}
|
||||||
|
|
@ -33,4 +45,4 @@ export function useTheme(): Theme {
|
||||||
return useContext(ThemeContext)
|
return useContext(ThemeContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
export type { ThemeColors, TypographyDensity } from './theme'
|
export type { ChatAppearance, ThemeColors, TypographyDensity } from './theme'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue