Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cancel request where isDarkMode=true #35034 #35301

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions src/hooks/useThemePreference.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import {useContext, useEffect, useState} from 'react';
import {useContext, useMemo} from 'react';
import {useColorScheme} from 'react-native';
import {PreferredThemeContext} from '@components/OnyxProvider';
import type {ThemePreferenceWithoutSystem} from '@styles/theme/types';
import CONST from '@src/CONST';

function useThemePreference() {
const [themePreference, setThemePreference] = useState<ThemePreferenceWithoutSystem>(CONST.THEME.FALLBACK);
const preferredThemeFromStorage = useContext(PreferredThemeContext);
const systemTheme = useColorScheme();

useEffect(() => {
const themePreference = useMemo(() => {
const theme = preferredThemeFromStorage ?? CONST.THEME.DEFAULT;

// If the user chooses to use the device theme settings, we need to set the theme preference to the system theme
if (theme === CONST.THEME.SYSTEM) {
setThemePreference(systemTheme ?? CONST.THEME.FALLBACK);
} else {
setThemePreference(theme);
}
// If the user chooses to use the device theme settings, set the theme preference to the system theme
return theme === CONST.THEME.SYSTEM ? systemTheme ?? CONST.THEME.FALLBACK : theme;
}, [preferredThemeFromStorage, systemTheme]);

return themePreference;
Expand Down
Loading