minor tweak dimensionsChange and setNewTheme
This commit is contained in:
parent
80dc211911
commit
1c5561255f
|
@ -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}>
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue