From be3af4db22eca91d42b4ad971df3d938d5943efa Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Mon, 13 Nov 2023 19:40:05 +1300 Subject: [PATCH] Refactor some code in App.tsx --- App.tsx | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/App.tsx b/App.tsx index 92fdfee..d0d89b6 100644 --- a/App.tsx +++ b/App.tsx @@ -37,7 +37,7 @@ export const CombinedDarkTheme = { }; const App = () => { - const phoneTheme = useColorScheme(); + const systemTheme = useColorScheme(); const [appSettings, setAppSettings] = useState({ startup: undefined, @@ -61,29 +61,27 @@ const App = () => { }, []); const paperTheme = useMemo(() => { - const darkTheme = appSettings.darkColor - ? { - ...CombinedDarkTheme, - colors: { - ...CombinedDarkTheme.colors, - primary: appSettings.darkColor, - }, - } - : CombinedDarkTheme; - const lightTheme = appSettings.lightColor - ? { - ...CombinedDefaultTheme, - colors: { - ...CombinedDefaultTheme.colors, - primary: appSettings.lightColor, - }, - } - : CombinedDefaultTheme; - let value = phoneTheme === "dark" ? darkTheme : lightTheme; - if (appSettings.theme === "dark") value = darkTheme; - else if (appSettings.theme === "light") value = lightTheme; - return value; - }, [phoneTheme, appSettings]); + const darkTheme = { + ...CombinedDarkTheme, + colors: { + ...CombinedDarkTheme.colors, + primary: appSettings.darkColor, + }, + dark: true, + }; + const lightTheme = { + ...CombinedDefaultTheme, + colors: { + ...CombinedDefaultTheme.colors, + primary: appSettings.lightColor, + }, + dark: false, + }; + let theme = systemTheme === "dark" ? darkTheme : lightTheme; + if (appSettings.theme === "dark") theme = darkTheme; + else if (appSettings.theme === "light") theme = lightTheme; + return theme; + }, [systemTheme, appSettings]); return (