Refactor some code in App.tsx

This commit is contained in:
Brandon Presley 2023-11-13 19:40:05 +13:00
parent 4b5e7011d6
commit be3af4db22
1 changed files with 22 additions and 24 deletions

46
App.tsx
View File

@ -37,7 +37,7 @@ export const CombinedDarkTheme = {
}; };
const App = () => { const App = () => {
const phoneTheme = useColorScheme(); const systemTheme = useColorScheme();
const [appSettings, setAppSettings] = useState({ const [appSettings, setAppSettings] = useState({
startup: undefined, startup: undefined,
@ -61,29 +61,27 @@ const App = () => {
}, []); }, []);
const paperTheme = useMemo(() => { const paperTheme = useMemo(() => {
const darkTheme = appSettings.darkColor const darkTheme = {
? { ...CombinedDarkTheme,
...CombinedDarkTheme, colors: {
colors: { ...CombinedDarkTheme.colors,
...CombinedDarkTheme.colors, primary: appSettings.darkColor,
primary: appSettings.darkColor, },
}, dark: true,
} };
: CombinedDarkTheme; const lightTheme = {
const lightTheme = appSettings.lightColor ...CombinedDefaultTheme,
? { colors: {
...CombinedDefaultTheme, ...CombinedDefaultTheme.colors,
colors: { primary: appSettings.lightColor,
...CombinedDefaultTheme.colors, },
primary: appSettings.lightColor, dark: false,
}, };
} let theme = systemTheme === "dark" ? darkTheme : lightTheme;
: CombinedDefaultTheme; if (appSettings.theme === "dark") theme = darkTheme;
let value = phoneTheme === "dark" ? darkTheme : lightTheme; else if (appSettings.theme === "light") theme = lightTheme;
if (appSettings.theme === "dark") value = darkTheme; return theme;
else if (appSettings.theme === "light") value = lightTheme; }, [systemTheme, appSettings]);
return value;
}, [phoneTheme, appSettings]);
return ( return (
<PaperProvider <PaperProvider