// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. import React from 'react'; import {View, FlatList} from 'react-native'; import PropTypes from 'prop-types'; import {intlShape} from 'react-intl'; import StatusBar from 'app/components/status_bar'; import Section from 'app/screens/settings/section'; import SectionItem from 'app/screens/settings/section_item'; import FormattedText from 'app/components/formatted_text'; import {changeOpacity, makeStyleSheetFromTheme} from 'app/utils/theme'; import Preferences from 'mattermost-redux/constants/preferences'; export default class Theme extends React.PureComponent { static propTypes = { teamId: PropTypes.string.isRequired, theme: PropTypes.object.isRequired, userId: PropTypes.string.isRequired, actions: PropTypes.shape({ savePreferences: PropTypes.func.isRequired, }).isRequired, allowedThemes: PropTypes.arrayOf(PropTypes.object), customTheme: PropTypes.object, }; 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, actions: {savePreferences}, allowedThemes} = 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), }]); } renderThemeRow = ({item, title}) => { const {theme} = this.props; const style = getStyleSheet(theme); return ( )} action={this.setTheme} actionType='select' actionValue={item.key} selected={item.type.toLowerCase() === theme.type.toLowerCase()} theme={theme} /> ); }; keyExtractor = (item) => item.key; render() { const {theme, allowedThemes} = this.props; const {customTheme} = this.state; const style = getStyleSheet(theme); return (
{customTheme &&
{this.renderThemeRow({item: customTheme, title: 'Custom'})}
}
); } } const getStyleSheet = makeStyleSheetFromTheme((theme) => { return { container: { flex: 1, backgroundColor: theme.centerChannelBg, }, wrapper: { backgroundColor: changeOpacity(theme.centerChannelColor, 0.06), flex: 1, paddingTop: 35, }, divider: { backgroundColor: changeOpacity(theme.centerChannelColor, 0.1), height: 1, }, }; });