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

SignInPage always dark mode #31636

Merged
merged 16 commits into from
Nov 27, 2023
Merged
16 changes: 14 additions & 2 deletions src/pages/signin/SignInModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import Navigation from '@libs/Navigation/Navigation';
import ThemeProvider from '@styles/themes/ThemeProvider';
import ThemeStylesProvider from '@styles/ThemeStylesProvider';
import useThemeStyles from '@styles/useThemeStyles';
import * as Session from '@userActions/Session';
import SignInPage from './SignInPage';
Expand All @@ -10,7 +12,7 @@ const propTypes = {};

const defaultProps = {};

function SignInModal() {
function SignInModalInner() {
const styles = useThemeStyles();
if (!Session.isAnonymousUser()) {
// Sign in in RHP is only for anonymous users
Expand All @@ -23,14 +25,24 @@ function SignInModal() {
style={[styles.highlightBG]}
includeSafeAreaPaddingBottom={false}
shouldEnableMaxHeight
testID={SignInModal.displayName}
testID={SignInModalInner.displayName}
>
<HeaderWithBackButton onBackButtonPress={Navigation.dismissModal} />
<SignInPage isInModal />
</ScreenWrapper>
);
}

function SignInModal() {
return (
<ThemeProvider theme="dark">
chrispader marked this conversation as resolved.
Show resolved Hide resolved
<ThemeStylesProvider>
<SignInModalInner />
</ThemeStylesProvider>
</ThemeProvider>
);
}

SignInModal.propTypes = propTypes;
SignInModal.defaultProps = defaultProps;
SignInModal.displayName = 'SignInModal';
Expand Down
4 changes: 1 addition & 3 deletions src/styles/ThemeStylesProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import {stylesGenerator} from './styles';
import useTheme from './themes/useTheme';
import ThemeStylesContext from './ThemeStylesContext';

type ThemeStylesProviderProps = {
children: React.ReactNode;
};
type ThemeStylesProviderProps = React.PropsWithChildren;

function ThemeStylesProvider({children}: ThemeStylesProviderProps) {
const theme = useTheme();
Expand Down
11 changes: 8 additions & 3 deletions src/styles/themes/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@ import CONST from '@src/CONST';
import darkTheme from './default';
import lightTheme from './light';
import ThemeContext from './ThemeContext';
import {ThemePreferenceWithoutSystem} from './types';
import useThemePreference from './useThemePreference';

const propTypes = {
/** Rendered child component */
children: PropTypes.node.isRequired,
};

function ThemeProvider(props: React.PropsWithChildren) {
type ThemeProviderProps = React.PropsWithChildren & {
theme?: ThemePreferenceWithoutSystem;
};

function ThemeProvider({children, theme: themePreferenceProp}: ThemeProviderProps) {
const themePreference = useThemePreference();

const theme = useMemo(() => (themePreference === CONST.THEME.LIGHT ? lightTheme : darkTheme), [themePreference]);
const theme = useMemo(() => ((themePreferenceProp ?? themePreference) === CONST.THEME.LIGHT ? lightTheme : darkTheme), [themePreference, themePreferenceProp]);
chrispader marked this conversation as resolved.
Show resolved Hide resolved

return <ThemeContext.Provider value={theme}>{props.children}</ThemeContext.Provider>;
return <ThemeContext.Provider value={theme}>{children}</ThemeContext.Provider>;
}

ThemeProvider.propTypes = propTypes;
Expand Down
7 changes: 6 additions & 1 deletion src/styles/themes/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import CONST from '@src/CONST';

type Color = string;

type ThemePreference = (typeof CONST.THEME)[keyof typeof CONST.THEME];
type ThemePreferenceWithoutSystem = Exclude<ThemePreference, 'system'>;

type ThemeColors = {
// Figma keys
appBG: Color;
Expand Down Expand Up @@ -86,4 +91,4 @@ type ThemeColors = {
PAGE_BACKGROUND_COLORS: Record<string, Color>;
};

export {type ThemeColors, type Color};
export {type ThemePreference, type ThemePreferenceWithoutSystem, type ThemeColors, type Color};
5 changes: 2 additions & 3 deletions src/styles/themes/useThemePreference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import {useContext, useEffect, useState} from 'react';
import {Appearance, ColorSchemeName} from 'react-native';
import {PreferredThemeContext} from '@components/OnyxProvider';
import CONST from '@src/CONST';

type ThemePreference = typeof CONST.THEME.LIGHT | typeof CONST.THEME.DARK;
import {ThemePreferenceWithoutSystem} from './types';

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

Expand Down
Loading