* Update screens * Update login tests * Remove done * Fix failing tests * Update screens and components * Check styles fix * Update tests * Prevent setState call after component unmounts * Add empty setButtons func to dummy navigator * Remove platform check * Remove Platform import * Update react-native-navigation version * Add separate showModalOverCurrentContext function * check-style fixes * Remove overriding of AppDelegate's window * Fix modal over current context animation * Add showSearchModal navigation action * Check-style fix * Address review comments * Update SettingsSidebar and children * Update EditProfile screen * Update SettingsSidebar * Keep track of latest componentId to appear * Track componentId in state to use in navigation actions * Update FlaggedPosts and children * Update RecentMentions * Update Settings * Store componentIds in ephemeral store * Update AttachmentButton * Remove unnecessary dismissModal * Fix typo * Upate NotificationSettings * Update NotificationSettingsAutoResponder * Update NotificationSettingsMentions * Update NotificationSettingsMobile * Update CreateChannel and children * Update MoreChannels * Update ChannelPeek and children * Update ChannelNavBar and children * Update ChannelPostList and children * Update ChannelInfo and children * Update ChannelAddMembers * Update ChannelMembers * Update EditChannel * Fix setting of top bar buttons * Update Channel screen and children * Update PinnedPosts * Update LongPost * Update PostOptions * Update PostTextboxBase * Update EditPost * Check-styles fix * Update DisplaySettings * Update Timezone * Update SelectTimezone * Update IntlWrapper and Notification * Update InteractiveDialog and children * Update ExpandedAnnouncementBanner * Update ClientUpgradeListener * Update MoreDirectMessages * Update SelectorScreen * Update UserProfile * Update Thread * Update About * Update ImagePreview * Update TextPreview * Update AddReaction * Update ReactionList and children * Update Code * Update TermsOfService * Update Permalink * Update Permalink * Update ErrorTeamsList * Update Search * Remove navigator prop * Fix setButtons calls * Remove navigationComponentId * Fix test * Handle in-app notifs in global event handler * Fix in-app notification handling * Fix typo * Fix tests * Auto dismiss in-app notif after 5 seconds * Fix typo * Update overlay dismissal * Animate in-app notif dismissal and allow gesture dismissal
169 lines
4.7 KiB
JavaScript
169 lines
4.7 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 {
|
|
BackHandler,
|
|
Platform,
|
|
ScrollView,
|
|
StyleSheet,
|
|
Text,
|
|
TextInput,
|
|
View,
|
|
} from 'react-native';
|
|
|
|
import {getCodeFont} from 'app/utils/markdown';
|
|
import {changeOpacity, makeStyleSheetFromTheme, setNavigatorStyles} from 'app/utils/theme';
|
|
|
|
export default class Code extends React.PureComponent {
|
|
static propTypes = {
|
|
actions: PropTypes.shape({
|
|
popTopScreen: PropTypes.func.isRequired,
|
|
}).isRequired,
|
|
componentId: PropTypes.string,
|
|
theme: PropTypes.object.isRequired,
|
|
content: PropTypes.string.isRequired,
|
|
};
|
|
|
|
componentDidMount() {
|
|
BackHandler.addEventListener('hardwareBackPress', this.handleAndroidBack);
|
|
}
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
if (this.props.theme !== nextProps.theme) {
|
|
setNavigatorStyles(this.props.componentId, nextProps.theme);
|
|
}
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
BackHandler.removeEventListener('hardwareBackPress', this.handleAndroidBack);
|
|
}
|
|
|
|
handleAndroidBack = () => {
|
|
this.props.actions.popTopScreen();
|
|
return true;
|
|
};
|
|
|
|
countLines = (content) => {
|
|
return content.split('\n').length;
|
|
};
|
|
|
|
render() {
|
|
const style = getStyleSheet(this.props.theme);
|
|
|
|
const numberOfLines = this.countLines(this.props.content);
|
|
let lineNumbers = '1';
|
|
for (let i = 1; i < numberOfLines; i++) {
|
|
const line = (i + 1).toString();
|
|
|
|
lineNumbers += '\n' + line;
|
|
}
|
|
|
|
let lineNumbersStyle;
|
|
if (numberOfLines >= 10) {
|
|
lineNumbersStyle = [style.lineNumbers, style.lineNumbersRight];
|
|
} else {
|
|
lineNumbersStyle = style.lineNumbers;
|
|
}
|
|
|
|
let textComponent;
|
|
if (Platform.OS === 'ios') {
|
|
textComponent = (
|
|
<TextInput
|
|
editable={false}
|
|
multiline={true}
|
|
value={this.props.content}
|
|
style={[style.codeText]}
|
|
/>
|
|
);
|
|
} else {
|
|
textComponent = (
|
|
<Text
|
|
selectable={true}
|
|
style={style.codeText}
|
|
>
|
|
{this.props.content}
|
|
</Text>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<ScrollView
|
|
style={style.scrollContainer}
|
|
contentContainerStyle={style.container}
|
|
>
|
|
<View style={lineNumbersStyle}>
|
|
<Text style={style.lineNumbersText}>
|
|
{lineNumbers}
|
|
</Text>
|
|
</View>
|
|
<ScrollView
|
|
style={style.codeContainer}
|
|
contentContainerStyle={style.code}
|
|
horizontal={true}
|
|
>
|
|
{textComponent}
|
|
</ScrollView>
|
|
</ScrollView>
|
|
);
|
|
}
|
|
}
|
|
|
|
const getStyleSheet = makeStyleSheetFromTheme((theme) => {
|
|
return {
|
|
scrollContainer: {
|
|
flex: 1,
|
|
},
|
|
container: {
|
|
minHeight: '100%',
|
|
flexDirection: 'row',
|
|
},
|
|
lineNumbers: {
|
|
alignItems: 'center',
|
|
backgroundColor: changeOpacity(theme.centerChannelColor, 0.05),
|
|
borderRightColor: changeOpacity(theme.centerChannelColor, 0.15),
|
|
borderRightWidth: StyleSheet.hairlineWidth,
|
|
flexDirection: 'column',
|
|
justifyContent: 'flex-start',
|
|
paddingHorizontal: 6,
|
|
paddingVertical: 4,
|
|
},
|
|
lineNumbersRight: {
|
|
alignItems: 'flex-end',
|
|
},
|
|
lineNumbersText: {
|
|
color: changeOpacity(theme.centerChannelColor, 0.5),
|
|
fontSize: 12,
|
|
lineHeight: 18,
|
|
},
|
|
codeContainer: {
|
|
flexGrow: 0,
|
|
flexShrink: 1,
|
|
width: '100%',
|
|
},
|
|
code: {
|
|
paddingHorizontal: 6,
|
|
...Platform.select({
|
|
android: {
|
|
paddingVertical: 4,
|
|
},
|
|
ios: {
|
|
top: -4,
|
|
},
|
|
}),
|
|
},
|
|
codeText: {
|
|
color: changeOpacity(theme.centerChannelColor, 0.65),
|
|
fontFamily: getCodeFont(),
|
|
fontSize: 12,
|
|
lineHeight: 18,
|
|
...Platform.select({
|
|
ios: {
|
|
margin: 0,
|
|
padding: 0,
|
|
},
|
|
}),
|
|
},
|
|
};
|
|
});
|