From a4bbfc1e109ee088f65260e33acad227570fcf66 Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Wed, 9 Aug 2023 09:30:00 +0500 Subject: [PATCH] mobile: fix theme gets reset on opening share extension --- apps/mobile/share/store.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/apps/mobile/share/store.js b/apps/mobile/share/store.js index 2d2f0b2b7..c638b9f57 100644 --- a/apps/mobile/share/store.js +++ b/apps/mobile/share/store.js @@ -42,20 +42,23 @@ let appSettings = MMKV.getString(StorageKeys.appSettings); if (appSettings) { appSettings = JSON.parse(appSettings); } -const theme = - Appearance.getColorScheme() !== "dark" - ? appSettings?.darkThem - : appSettings?.lightTheme; -useThemeEngineStore - .getState() - .setTheme( - theme || (Appearance.getColorScheme() === "dark" ? ThemeDark : ThemeLight) - ); +const systemColorScheme = Appearance.getColorScheme(); +const appColorScheme = appSettings.colorScheme; +const useSystemTheme = appSettings.useSystemTheme; +const currentColorScheme = useSystemTheme ? systemColorScheme : appColorScheme; + +const theme = currentColorScheme + ? appSettings?.darkTheme + : appSettings?.lightTheme; + +const currentTheme = + theme || (currentColorScheme === "dark" ? ThemeDark : ThemeLight); + +useThemeEngineStore.getState().setTheme(currentTheme); export const useShareStore = create((set) => ({ - theme: - theme || (Appearance.getColorScheme() === "dark" ? ThemeDark : ThemeLight), + theme: currentTheme, appendNote: null, setAppendNote: (note) => { MMKV.setItem(StorageKeys.appendNote, JSON.stringify(note));