From 1c5561255f784d4d1624218b7c0b91f5c9e0c27d Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 24 Aug 2022 16:30:04 -0300 Subject: [PATCH] minor tweak dimensionsChange and setNewTheme --- app/index.tsx | 15 +++++---------- app/lib/methods/helpers/theme.ts | 4 ++-- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/index.tsx b/app/index.tsx index 7c2dfc3e2..0af3fb982 100644 --- a/app/index.tsx +++ b/app/index.tsx @@ -164,23 +164,18 @@ const Root = () => { }, []); // Dimensions update fires twice - const onDimensionsChange = useCallback( - debounce(({ window }: { window: IDimensions }) => { - setDimensions(window); - setMasterDetail(window.width); - }), - [] - ); + const onDimensionsChange = debounce(({ window }: { window: IDimensions }) => { + setDimensions(window); + setMasterDetail(window.width); + }); - const setNewTheme = (newThemePreference = {} as IThemePreference) => { + const setNewTheme = (newThemePreference?: IThemePreference) => { const { theme: newTheme, themePreferences: newThemePreferences } = newThemeState(themePreferences, newThemePreference); setThemePreferences(newThemePreferences); setTheme(newTheme); subscribeTheme(themePreferences, setNewTheme); }; - console.count('💸 Root'); - return ( diff --git a/app/lib/methods/helpers/theme.ts b/app/lib/methods/helpers/theme.ts index 1af65ea6d..bfc8fca3d 100644 --- a/app/lib/methods/helpers/theme.ts +++ b/app/lib/methods/helpers/theme.ts @@ -36,10 +36,10 @@ export const getTheme = (themePreferences: IThemePreference): TSupportedThemes = return theme === 'dark' ? darkLevel : 'light'; }; -export const newThemeState = (prevthemePreferences: IThemePreference, newTheme: IThemePreference) => { +export const newThemeState = (prevThemePreferences: IThemePreference, newTheme?: IThemePreference) => { // new theme preferences const themePreferences = { - ...prevthemePreferences, + ...prevThemePreferences, ...newTheme }; // set new state of themePreferences