minor tweak dimensionsChange and setNewTheme

This commit is contained in:
Reinaldo Neto 2022-08-24 16:30:04 -03:00
parent 80dc211911
commit 1c5561255f
2 changed files with 7 additions and 12 deletions

View File

@ -164,23 +164,18 @@ const Root = () => {
}, []); }, []);
// Dimensions update fires twice // Dimensions update fires twice
const onDimensionsChange = useCallback( const onDimensionsChange = debounce(({ window }: { window: IDimensions }) => {
debounce(({ window }: { window: IDimensions }) => { setDimensions(window);
setDimensions(window); setMasterDetail(window.width);
setMasterDetail(window.width); });
}),
[]
);
const setNewTheme = (newThemePreference = {} as IThemePreference) => { const setNewTheme = (newThemePreference?: IThemePreference) => {
const { theme: newTheme, themePreferences: newThemePreferences } = newThemeState(themePreferences, newThemePreference); const { theme: newTheme, themePreferences: newThemePreferences } = newThemeState(themePreferences, newThemePreference);
setThemePreferences(newThemePreferences); setThemePreferences(newThemePreferences);
setTheme(newTheme); setTheme(newTheme);
subscribeTheme(themePreferences, setNewTheme); subscribeTheme(themePreferences, setNewTheme);
}; };
console.count('💸 Root');
return ( return (
<SafeAreaProvider initialMetrics={initialWindowMetrics} style={{ backgroundColor: themes[theme].backgroundColor }}> <SafeAreaProvider initialMetrics={initialWindowMetrics} style={{ backgroundColor: themes[theme].backgroundColor }}>
<Provider store={store}> <Provider store={store}>

View File

@ -36,10 +36,10 @@ export const getTheme = (themePreferences: IThemePreference): TSupportedThemes =
return theme === 'dark' ? darkLevel : 'light'; return theme === 'dark' ? darkLevel : 'light';
}; };
export const newThemeState = (prevthemePreferences: IThemePreference, newTheme: IThemePreference) => { export const newThemeState = (prevThemePreferences: IThemePreference, newTheme?: IThemePreference) => {
// new theme preferences // new theme preferences
const themePreferences = { const themePreferences = {
...prevthemePreferences, ...prevThemePreferences,
...newTheme ...newTheme
}; };
// set new state of themePreferences // set new state of themePreferences