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

Theme switching: Add Theme to User Preferences (No QA) #21666

Merged
merged 30 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f08cbec
add preferences for color theme
Jun 27, 2023
369a9cd
add color theme CONST
Jun 27, 2023
f65fde0
add color theme ONYXKEYS
Jun 27, 2023
e452835
fix ColorThemePage
Jun 27, 2023
b9851a7
remove menu entry for color theme page
Jun 27, 2023
1691b1b
Merge branch 'main' into @chrispader/theme-switching-preferences
Jul 4, 2023
e7f0471
fix: import
Jul 4, 2023
6ed9344
Merge branch 'main' into @chrispader/theme-switching-preferences
Jul 5, 2023
d7d7606
update naming
Jul 5, 2023
aabee1e
update comment
chrispader Jul 5, 2023
91582bc
wrap ThemePage in ScrollView
chrispader Jul 5, 2023
320b140
fix wrong import
chrispader Jul 5, 2023
8171f11
remove ScrollView and fix link
chrispader Jul 5, 2023
6b6a04b
Merge branch 'main' into @chrispader/theme-switching-preferences
Jul 7, 2023
e7fdfe1
update translations
Jul 7, 2023
e018a50
update translations structure
Jul 7, 2023
089aef0
add text to top of ThemePage
Jul 7, 2023
c9ebe91
add missing import
Jul 7, 2023
07b7700
fix: route
Jul 7, 2023
a9b4453
improve List in ThemePage
Jul 7, 2023
c61c357
remove commented line
chrispader Jul 10, 2023
c49c9b7
move default theme to `CONST.THEME`
chrispader Jul 10, 2023
3fd8e05
Merge branch 'main' into @chrispader/theme-switching-preferences
chrispader Jul 11, 2023
0a4a43e
default to "CONST.THEME.DEFAULT" in case onyx key is set to "''"
chrispader Jul 11, 2023
b94ee71
add "persisting" logic
chrispader Jul 11, 2023
0b98862
fix persisting logic
chrispader Jul 11, 2023
deb324c
disable themePage temporarily
chrispader Jul 11, 2023
de96d80
Update src/libs/Navigation/AppNavigator/ModalStackNavigators.js
chrispader Jul 11, 2023
d73e358
Update src/libs/actions/User.js
chrispader Jul 11, 2023
345ad0f
remove unused import
chrispader Jul 11, 2023
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
4 changes: 4 additions & 0 deletions src/CONST.js
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,10 @@ const CONST = {
GSD: 'gsd',
DEFAULT: 'default',
},
COLOR_THEME: {
LIGHT: 'light',
DARK: 'dark',
},
JSON_CODE: {
SUCCESS: 200,
BAD_REQUEST: 400,
Expand Down
3 changes: 3 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ export default {
// Whether the auth token is valid
IS_TOKEN_VALID: 'isTokenValid',

// The color theme setting defined by the user in preferences
COLOR_THEME: 'colorTheme',

// Whether we're checking if the room is public or not
IS_CHECKING_PUBLIC_ROOM: 'isCheckingPublicRoom',

Expand Down
1 change: 1 addition & 0 deletions src/ROUTES.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default {
SETTINGS_PREFERENCES: 'settings/preferences',
SETTINGS_PRIORITY_MODE: 'settings/preferences/priority-mode',
SETTINGS_LANGUAGE: 'settings/preferences/language',
SETTINGS_COLOR_THEME: 'settings/color-theme',
SETTINGS_WORKSPACES: 'settings/workspaces',
SETTINGS_SECURITY: 'settings/security',
SETTINGS_CLOSE: 'settings/security/closeAccount',
Expand Down
11 changes: 11 additions & 0 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,17 @@ export default {
},
},
},
colorThemePage: {
colorTheme: 'Color theme',
colorThemes: {
dark: {
label: 'Dark',
},
light: {
label: 'Light',
},
},
},
signInPage: {
expensifyDotCash: 'New Expensify',
theCode: 'the code',
Expand Down
11 changes: 11 additions & 0 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,17 @@ export default {
},
},
},
colorThemePage: {
colorTheme: 'Tema de color',
colorThemes: {
dark: {
label: 'Oscura',
},
light: {
label: 'Ligera',
},
},
},
signInPage: {
expensifyDotCash: 'Nuevo Expensify',
theCode: 'el código',
Expand Down
7 changes: 7 additions & 0 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,13 @@ const SettingsModalStackNavigator = createModalStackNavigator([
},
name: 'Settings_Preferences_Language',
},
{
getComponent: () => {
const SettingsPreferencesColorThemePage = require('../../../pages/settings/Preferences/ColorThemePage').default;
return SettingsPreferencesColorThemePage;
},
name: 'Settings_Preferences_ColorTheme',
},
{
getComponent: () => {
const SettingsPasswordPage = require('../../../pages/settings/PasswordPage').default;
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Navigation/linkingConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export default {
path: ROUTES.SETTINGS_LANGUAGE,
exact: true,
},
Settings_Preferences_ColorTheme: {
path: ROUTES.SETTINGS_COLOR_THEME,
exact: true,
},
Settings_Close: {
path: ROUTES.SETTINGS_CLOSE,
exact: true,
Expand Down
38 changes: 37 additions & 1 deletion src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,42 @@ function setLocaleAndNavigate(locale) {
Navigation.navigate(ROUTES.SETTINGS_PREFERENCES);
}

/**
* @param {String} colorTheme
*/
// eslint-disable-next-line rulesdir/prefer-early-return
function setColorTheme(colorTheme) {
// If user is not signed in, change just locally.
if (!currentUserAccountID) {
Onyx.set(ONYXKEYS.COLOR_THEME, colorTheme);
return;
}

Onyx.set(ONYXKEYS.COLOR_THEME, colorTheme);

// TODO: Implement this in the backend
// // Optimistically change preferred locale
// const optimisticData = [
// {
// onyxMethod: CONST.ONYX.METHOD.SET,
// key: ONYXKEYS.COLOR_THEME,
// value: colorTheme,
// },
// ];

// API.write('UpdateColorTheme', {
// value: colorTheme,
// }, {optimisticData});
}

/**
* @param {String} colorTheme
*/
function setColorThemeAndNavigate(colorTheme) {
setColorTheme(colorTheme);
Navigation.navigate(ROUTES.SETTINGS_PREFERENCES);
}

function setSidebarLoaded() {
if (isSidebarLoaded) {
return;
Expand Down Expand Up @@ -298,4 +334,4 @@ function openProfile(personalDetails) {
);
}

export {setLocale, setLocaleAndNavigate, setSidebarLoaded, setUpPoliciesAndNavigate, openProfile, openApp, reconnectApp, confirmReadyToOpenApp};
export {setLocale, setLocaleAndNavigate, setSidebarLoaded, setColorThemeAndNavigate, setUpPoliciesAndNavigate, openProfile, openApp, reconnectApp, confirmReadyToOpenApp};
81 changes: 81 additions & 0 deletions src/pages/settings/Preferences/ColorThemePage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import _ from 'underscore';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import HeaderWithBackButton from '../../../components/HeaderWithBackButton';
import ScreenWrapper from '../../../components/ScreenWrapper';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import Navigation from '../../../libs/Navigation/Navigation';
import ROUTES from '../../../ROUTES';
import OptionsList from '../../../components/OptionsList';
import styles from '../../../styles/styles';
import themeColors from '../../../styles/themes/default';
import * as Expensicons from '../../../components/Icon/Expensicons';
import * as App from '../../../libs/actions/App';
import ONYXKEYS from '../../../ONYXKEYS';
import CONST from '../../../CONST';
import compose from '../../../libs/compose';

const greenCheckmark = {src: Expensicons.Checkmark, color: themeColors.success};

const propTypes = {
...withLocalizePropTypes,

/** The color theme of the App */
colorTheme: PropTypes.string,
};

const defaultProps = {
colorTheme: CONST.COLOR_THEME.LIGHT,
};

function ColorThemePage(props) {
const localesToColorThemes = _.map(props.translate('colorThemePage.colorThemes'), (colorTheme, key) => ({
value: key,
text: colorTheme.label,
keyForList: key,

// Include the green checkmark icon to indicate the currently selected value
customIcon: props.colorTheme === key ? greenCheckmark : undefined,

// This property will make the currently selected value have bold text
boldStyle: props.colorTheme === key,
}));

return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
<HeaderWithBackButton
title={props.translate('colorThemePage.colorTheme')}
shouldShowBackButton
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS_PREFERENCES)}
onCloseButtonPress={() => Navigation.dismissModal(true)}
/>
<OptionsList
sections={[{data: localesToColorThemes}]}
onSelectRow={(colorTheme) => App.setColorThemeAndNavigate(colorTheme.value)}
hideSectionHeaders
optionHoveredStyle={{
...styles.hoveredComponentBG,
...styles.mhn5,
...styles.ph5,
}}
shouldHaveOptionSeparator
shouldDisableRowInnerPadding
contentContainerStyles={[styles.ph5]}
/>
</ScreenWrapper>
);
}

ColorThemePage.displayName = 'ColorThemePage';
ColorThemePage.propTypes = propTypes;
ColorThemePage.defaultProps = defaultProps;

export default compose(
withLocalize,
withOnyx({
colorTheme: {
key: ONYXKEYS.COLOR_THEME,
},
}),
)(ColorThemePage);