Newer
Older
View, Linking, ScrollView, AsyncStorage, SafeAreaView, Switch
import { toggleMarkdown as toggleMarkdownAction } from '../../actions/markdown';
import { COLOR_DANGER, COLOR_SUCCESS } from '../../constants/colors';
import { DrawerButton } from '../../containers/HeaderButton';
import StatusBar from '../../containers/StatusBar';
import ListItem from '../../containers/ListItem';
import { DisclosureImage } from '../../containers/DisclosureIndicator';
import Separator from '../../containers/Separator';
import I18n from '../../i18n';
import { MARKDOWN_KEY } from '../../lib/rocketchat';
import { getReadableVersion, getDeviceModel, isAndroid } from '../../utils/deviceInfo';
import openLink from '../../utils/openLink';
import scrollPersistTaps from '../../utils/scrollPersistTaps';
import { showErrorAlert } from '../../utils/info';
import styles from './styles';
import sharedStyles from '../Styles';
const LICENSE_LINK = 'https://github.com/RocketChat/Rocket.Chat.ReactNative/blob/develop/LICENSE';
const SectionSeparator = React.memo(() => <View style={styles.sectionSeparatorBorder} />);
const SWITCH_TRACK_COLOR = {
false: isAndroid ? COLOR_DANGER : null,
true: COLOR_SUCCESS
};
useMarkdown: state.markdown.useMarkdown
toggleMarkdown: params => dispatch(toggleMarkdownAction(params))
export default class SettingsView extends React.Component {
static navigationOptions = ({ navigation }) => ({
headerLeft: <DrawerButton navigation={navigation} />,
title: I18n.t('Settings')
navigation: PropTypes.object,
server: PropTypes.object,
useMarkdown: PropTypes.bool,
toggleMarkdown: PropTypes.func
toggleMarkdown = (value) => {
AsyncStorage.setItem(MARKDOWN_KEY, JSON.stringify(value));
const { toggleMarkdown } = this.props;
toggleMarkdown(value);
navigateToRoom = (room) => {
const { navigation } = this.props;
navigation.navigate(room);
sendEmail = async() => {
const subject = encodeURI('React Native App Support');
const email = encodeURI('support@rocket.chat');
const description = encodeURI(`
version: ${ getReadableVersion }
device: ${ getDeviceModel }
`);
await Linking.openURL(`mailto:${ email }?subject=${ subject }&body=${ description }`);
showErrorAlert(I18n.t('error-email-send-failed', { message: 'support@rocket.chat' }));
onPressLicense = () => openLink(LICENSE_LINK)
renderDisclosure = () => <DisclosureImage />
renderMarkdownSwitch = () => {
const { useMarkdown } = this.props;
return (
<Switch
value={useMarkdown}
trackColor={SWITCH_TRACK_COLOR}
onValueChange={this.toggleMarkdown}
/>
);
<SafeAreaView style={sharedStyles.listSafeArea} testID='settings-view'>
contentContainerStyle={sharedStyles.listContentContainer}
showsVerticalScrollIndicator={false}
testID='settings-view-list'
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<ListItem
title={I18n.t('Contact_us')}
onPress={this.sendEmail}
showActionIndicator
testID='settings-view-contact'
right={this.renderDisclosure}
/>
<Separator />
<ListItem
title={I18n.t('Language')}
onPress={() => this.navigateToRoom('LanguageView')}
showActionIndicator
testID='settings-view-language'
right={this.renderDisclosure}
/>
<Separator />
<ListItem
title={I18n.t('Theme')}
showActionIndicator
disabled
testID='settings-view-theme'
/>
<Separator />
<ListItem
title={I18n.t('Share_this_app')}
showActionIndicator
disabled
testID='settings-view-share-app'
/>
<SectionSeparator />
<ListItem
title={I18n.t('License')}
onPress={this.onPressLicense}
showActionIndicator
testID='settings-view-license'
right={this.renderDisclosure}
/>
<Separator />
<ListItem title={I18n.t('Version_no', { version: getReadableVersion })} testID='settings-view-version' />
<Separator />
<ListItem
title={I18n.t('Server_version', { version: server.version })}
subtitle={`${ server.server.split('//')[1] }`}
testID='settings-view-server-version'
/>
<SectionSeparator />
<ListItem
title={I18n.t('Enable_markdown')}
testID='settings-view-markdown'
right={() => this.renderMarkdownSwitch()}
/>