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
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 (
<SafeAreaProvider initialMetrics={initialWindowMetrics} style={{ backgroundColor: themes[theme].backgroundColor }}>
<Provider store={store}>

View File

@ -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