* new themes and theme type updates * update theme processing port newer functionality from webapp * update theme UI including new svg-based thumbnail * lint fixes * update snapshots and tests * update theme tile border approach * remove unused path component * remove old variable typo * remove old variable type from theme type * lint and snapshot updates * update snapshots
162 lines
5.1 KiB
JavaScript
162 lines
5.1 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import PropTypes from 'prop-types';
|
|
import React from 'react';
|
|
import {intlShape} from 'react-intl';
|
|
import {Text, View} from 'react-native';
|
|
import {SafeAreaView} from 'react-native-safe-area-context';
|
|
|
|
import FormattedText from '@components/formatted_text';
|
|
import StatusBar from '@components/status_bar';
|
|
import Preferences from '@mm-redux/constants/preferences';
|
|
import Section from '@screens/settings/section';
|
|
import SectionItem from '@screens/settings/section_item';
|
|
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
|
|
|
|
import ThemeTile from './theme_tile';
|
|
|
|
export default class Theme extends React.PureComponent {
|
|
static propTypes = {
|
|
actions: PropTypes.shape({
|
|
savePreferences: PropTypes.func.isRequired,
|
|
}).isRequired,
|
|
allowedThemes: PropTypes.arrayOf(PropTypes.object),
|
|
customTheme: PropTypes.object,
|
|
isLandscape: PropTypes.bool.isRequired,
|
|
isTablet: PropTypes.bool.isRequired,
|
|
teamId: PropTypes.string.isRequired,
|
|
theme: PropTypes.object.isRequired,
|
|
userId: PropTypes.string.isRequired,
|
|
};
|
|
|
|
static contextTypes = {
|
|
intl: intlShape.isRequired,
|
|
};
|
|
|
|
state = {
|
|
customTheme: null,
|
|
};
|
|
|
|
static getDerivedStateFromProps(props, state) {
|
|
if (!state.customTheme && props.customTheme) {
|
|
return {
|
|
customTheme: props.customTheme,
|
|
};
|
|
}
|
|
return null;
|
|
}
|
|
|
|
setTheme = (key) => {
|
|
const {
|
|
userId,
|
|
teamId,
|
|
allowedThemes,
|
|
actions: {savePreferences},
|
|
} = this.props;
|
|
const {customTheme} = this.state;
|
|
const selectedTheme = allowedThemes.concat(customTheme).find((theme) => theme.key === key);
|
|
|
|
savePreferences(userId, [{
|
|
user_id: userId,
|
|
category: Preferences.CATEGORY_THEME,
|
|
name: teamId,
|
|
value: JSON.stringify(selectedTheme),
|
|
}]);
|
|
};
|
|
|
|
renderAllowedThemeTiles = () => {
|
|
const {theme, allowedThemes, isLandscape, isTablet} = this.props;
|
|
|
|
return allowedThemes.map((allowedTheme) => (
|
|
<ThemeTile
|
|
key={allowedTheme.key}
|
|
label={(
|
|
<Text>
|
|
{allowedTheme.type}
|
|
</Text>
|
|
)}
|
|
action={this.setTheme}
|
|
actionValue={allowedTheme.key}
|
|
selected={allowedTheme.type.toLowerCase() === theme.type.toLowerCase()}
|
|
tileTheme={allowedTheme}
|
|
activeTheme={theme}
|
|
isLandscape={isLandscape}
|
|
isTablet={isTablet}
|
|
/>
|
|
));
|
|
};
|
|
|
|
renderCustomThemeRow = ({item}) => {
|
|
const {theme} = this.props;
|
|
|
|
return (
|
|
<SectionItem
|
|
label={(
|
|
<FormattedText
|
|
id='user.settings.display.custom_theme'
|
|
defaultMessage={'Custom Theme'}
|
|
/>
|
|
)}
|
|
action={this.setTheme}
|
|
actionType='select'
|
|
actionValue={item.key}
|
|
selected={item.type.toLowerCase() === theme.type.toLowerCase()}
|
|
theme={theme}
|
|
/>
|
|
);
|
|
};
|
|
|
|
render() {
|
|
const {theme} = this.props;
|
|
const {customTheme} = this.state;
|
|
const style = getStyleSheet(theme);
|
|
return (
|
|
<View style={style.container}>
|
|
<StatusBar/>
|
|
<View style={style.wrapper}>
|
|
<View style={style.tilesContainer}>
|
|
{this.renderAllowedThemeTiles()}
|
|
</View>
|
|
{customTheme &&
|
|
<SafeAreaView
|
|
edges={['left', 'right']}
|
|
style={style.container}
|
|
>
|
|
<Section
|
|
disableHeader={true}
|
|
theme={theme}
|
|
>
|
|
{this.renderCustomThemeRow({item: customTheme})}
|
|
</Section>
|
|
</SafeAreaView>
|
|
}
|
|
</View>
|
|
</View>
|
|
);
|
|
}
|
|
}
|
|
|
|
const getStyleSheet = makeStyleSheetFromTheme((theme) => {
|
|
return {
|
|
container: {
|
|
flex: 1,
|
|
},
|
|
wrapper: {
|
|
backgroundColor: changeOpacity(theme.centerChannelColor, 0.06),
|
|
flex: 1,
|
|
paddingTop: 35,
|
|
},
|
|
tilesContainer: {
|
|
marginBottom: 30,
|
|
paddingLeft: 8,
|
|
flexDirection: 'row',
|
|
flexWrap: 'wrap',
|
|
backgroundColor: theme.centerChannelBg,
|
|
borderTopWidth: 1,
|
|
borderBottomWidth: 1,
|
|
borderTopColor: changeOpacity(theme.centerChannelColor, 0.1),
|
|
borderBottomColor: changeOpacity(theme.centerChannelColor, 0.1),
|
|
},
|
|
};
|
|
});
|