-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
ThemePage.js
72 lines (63 loc) · 2.35 KB
/
ThemePage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import PropTypes from 'prop-types';
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import Text from '@components/Text';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import * as User from '@userActions/User';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
const propTypes = {
...withLocalizePropTypes,
/** The theme of the app */
preferredTheme: PropTypes.string,
};
const defaultProps = {
preferredTheme: CONST.THEME.DEFAULT,
};
function ThemePage(props) {
const styles = useThemeStyles();
const localesToThemes = _.map(_.values(_.omit(CONST.THEME, 'DEFAULT')), (theme) => ({
value: theme,
text: props.translate(`themePage.themes.${theme}.label`),
keyForList: theme,
isSelected: (props.preferredTheme || CONST.THEME.DEFAULT) === theme,
}));
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={ThemePage.displayName}
>
<HeaderWithBackButton
title={props.translate('themePage.theme')}
shouldShowBackButton
onBackButtonPress={() => Navigation.navigate(ROUTES.SETTINGS_PREFERENCES)}
onCloseButtonPress={() => Navigation.dismissModal(true)}
/>
<Text style={[styles.mh5, styles.mv4]}>{props.translate('themePage.chooseThemeBelowOrSync')}</Text>
<SelectionList
sections={[{data: localesToThemes}]}
onSelectRow={(theme) => User.updateTheme(theme.value)}
initiallyFocusedOptionKey={_.find(localesToThemes, (theme) => theme.isSelected).keyForList}
/>
</ScreenWrapper>
);
}
ThemePage.displayName = 'ThemePage';
ThemePage.propTypes = propTypes;
ThemePage.defaultProps = defaultProps;
export default compose(
withLocalize,
withOnyx({
preferredTheme: {
key: ONYXKEYS.PREFERRED_THEME,
},
}),
)(ThemePage);