mattermost-mobile/app/screens/settings/settings_item/index.js
Miguel Alatzar 57d60649f8
[MM-22959] Use Compass icons (#4847)
* Use Compass icons

* Update ChannelInfo and AdvancedSettings

* Fix search modifiers

* Fix Autocomplete item

* Remove VectorIcon component

* Unlink react-native-vector-icons

* Revert ProgressiveImage changes

* Update Mark as Unread icon

* Apply review suggestion

* Replace extension icons

* Update video control button style

* Replace (un)flag with (un)save

* Replace (un)flag with (un)save - take 2

* Use bookmark-outline icon

Co-authored-by: Miguel Alatzar <miguel@Miguels-MacBook-Pro.local>
2020-10-15 15:34:24 -07:00

152 lines
4.2 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React, {PureComponent} from 'react';
import PropTypes from 'prop-types';
import {Text, TouchableOpacity, View} from 'react-native';
import CompassIcon from '@components/compass_icon';
import {paddingRight, paddingLeft} from '@components/safe_area_view/iphone_x_spacing';
import FormattedText from '@components/formatted_text';
import {changeOpacity} from '@utils/theme';
import getStyleSheet from './style';
export default class SettingsItem extends PureComponent {
static propTypes = {
defaultMessage: PropTypes.string.isRequired,
messageValues: PropTypes.object,
i18nId: PropTypes.string,
iconName: PropTypes.string,
isLink: PropTypes.bool,
isDestructor: PropTypes.bool,
centered: PropTypes.bool,
onPress: PropTypes.func,
rightComponent: PropTypes.node,
separator: PropTypes.bool,
showArrow: PropTypes.bool,
theme: PropTypes.object.isRequired,
isLandscape: PropTypes.bool.isRequired,
};
static defaultProps = {
isDestructor: false,
separator: true,
isLandscape: false,
isLink: false,
};
renderText = () => {
const {
centered,
defaultMessage,
messageValues,
i18nId,
isDestructor,
isLink,
theme,
} = this.props;
const style = getStyleSheet(theme);
const textStyle = [style.label];
if (isDestructor) {
textStyle.push(style.destructor);
}
if (centered) {
textStyle.push(style.centerLabel);
}
if (isLink) {
textStyle.push(style.linkContainer);
}
if (!i18nId) {
return <Text style={textStyle}>{defaultMessage}</Text>;
}
return (
<FormattedText
values={messageValues}
id={i18nId}
defaultMessage={defaultMessage}
style={textStyle}
/>
);
};
render() {
const {
iconName,
onPress,
rightComponent,
separator,
showArrow,
theme,
isLandscape,
isDestructor,
} = this.props;
const style = getStyleSheet(theme);
let divider;
if (separator) {
divider = (
<View style={style.dividerContainer}>
<View style={style.divider}/>
</View>
);
}
let icon;
if (iconName) {
const iconStyle = [style.icon, {color: changeOpacity(theme.centerChannelColor, 0.64)}];
if (isDestructor) {
iconStyle.push(style.destructor);
}
icon = (
<CompassIcon
name={iconName}
style={iconStyle}
/>
);
}
let additionalComponent;
if (showArrow) {
additionalComponent = (
<CompassIcon
name='chevron-right'
style={style.arrow}
/>
);
} else if (rightComponent) {
additionalComponent = rightComponent;
}
return (
<TouchableOpacity
onPress={onPress}
>
<View style={[style.container, paddingLeft(isLandscape)]}>
{icon &&
<View style={style.iconContainer}>
{icon}
</View>
}
<View style={style.wrapper}>
<View style={[style.labelContainer, paddingRight(isLandscape)]}>
{this.renderText()}
{Boolean(additionalComponent) &&
<View style={style.arrowContainer}>
{additionalComponent}
</View>
}
</View>
</View>
</View>
{divider}
</TouchableOpacity>
);
}
}