diff options
author | Hailey <me@haileyok.com> | 2024-02-06 11:43:51 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-06 11:43:51 -0800 |
commit | ec86282403ea34704d0faab7b04ca033bd3a0650 (patch) | |
tree | ca5881ada59d7ad634bd799efe3c751a4c5509d2 /src/lib | |
parent | 856f80fc6df731b1dbe9efa289ad6a4f728d4e0d (diff) | |
download | voidsky-ec86282403ea34704d0faab7b04ca033bd3a0650.tar.zst |
Options for selecting dark theme, fix some white flashes when in dark mode (#2722)
* add dark theme selection to settings/schema * use `useThemePrefs` where needed * adjust theme providers to support various themes * update storybook * handle web themes * better themeing for web * dont show dark theme prefs when color mode is light * drop the inverted text change on oled theme * get the color mode inside of `useColorModeTheme` * use `ThemeName` type everywhere * typo * use dim/dark instead of dark/oled * prevent any fickers on web * fix styles * use `dim` for dark default * more cleanup * 🤔 * set system background color * ts
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/ThemeContext.tsx | 28 | ||||
-rw-r--r-- | src/lib/themes.ts | 13 |
2 files changed, 28 insertions, 13 deletions
diff --git a/src/lib/ThemeContext.tsx b/src/lib/ThemeContext.tsx index 38bd199cb..63e2beeb1 100644 --- a/src/lib/ThemeContext.tsx +++ b/src/lib/ThemeContext.tsx @@ -1,11 +1,7 @@ import React, {ReactNode, createContext, useContext} from 'react' -import { - TextStyle, - useColorScheme, - ViewStyle, - ColorSchemeName, -} from 'react-native' -import {darkTheme, defaultTheme} from './themes' +import {TextStyle, ViewStyle} from 'react-native' +import {darkTheme, defaultTheme, dimTheme} from './themes' +import {ThemeName} from '#/alf/themes' export type ColorScheme = 'light' | 'dark' @@ -84,23 +80,31 @@ export interface Theme { export interface ThemeProviderProps { children?: ReactNode - theme?: 'light' | 'dark' | 'system' + theme: ThemeName } export const ThemeContext = createContext<Theme>(defaultTheme) export const useTheme = () => useContext(ThemeContext) -function getTheme(theme: ColorSchemeName) { - return theme === 'dark' ? darkTheme : defaultTheme +function getTheme(theme: ThemeName) { + switch (theme) { + case 'light': + return defaultTheme + case 'dim': + return dimTheme + case 'dark': + return darkTheme + default: + return defaultTheme + } } export const ThemeProvider: React.FC<ThemeProviderProps> = ({ theme, children, }) => { - const colorScheme = useColorScheme() - const themeValue = getTheme(theme === 'system' ? colorScheme : theme) + const themeValue = getTheme(theme) return ( <ThemeContext.Provider value={themeValue}>{children}</ThemeContext.Provider> diff --git a/src/lib/themes.ts b/src/lib/themes.ts index 2d4515c77..9a3880b92 100644 --- a/src/lib/themes.ts +++ b/src/lib/themes.ts @@ -2,7 +2,7 @@ import {Platform} from 'react-native' import type {Theme} from './ThemeContext' import {colors} from './styles' -import {darkPalette, lightPalette} from '#/alf/themes' +import {darkPalette, lightPalette, dimPalette} from '#/alf/themes' export const defaultTheme: Theme = { colorScheme: 'light', @@ -336,3 +336,14 @@ export const darkTheme: Theme = { }, }, } + +export const dimTheme: Theme = { + ...darkTheme, + palette: { + ...darkTheme.palette, + default: { + ...darkTheme.palette.default, + background: dimPalette.black, + }, + }, +} |