[FIX] Some issues on preview message (#1271)

This commit is contained in:
Djorkaeff Alexandre 2019-10-04 10:28:36 -03:00 committed by Diego Mello
parent 6fd722a0d8
commit f3972ef49e
4 changed files with 37 additions and 21 deletions

View File

@ -5,7 +5,7 @@ import { Text } from 'react-native';
import styles from './styles'; import styles from './styles';
const AtMention = React.memo(({ const AtMention = React.memo(({
mention, mentions, username, navToRoomInfo, style = [] mention, mentions, username, navToRoomInfo, preview, style = []
}) => { }) => {
let mentionStyle = styles.mention; let mentionStyle = styles.mention;
if (mention === 'all' || mention === 'here') { if (mention === 'all' || mention === 'here') {
@ -33,8 +33,8 @@ const AtMention = React.memo(({
return ( return (
<Text <Text
style={[mentionStyle, ...style]} style={[preview ? styles.text : mentionStyle, ...style]}
onPress={handlePress} onPress={preview ? undefined : handlePress}
> >
{`@${ mention }`} {`@${ mention }`}
</Text> </Text>
@ -46,6 +46,7 @@ AtMention.propTypes = {
username: PropTypes.string, username: PropTypes.string,
navToRoomInfo: PropTypes.func, navToRoomInfo: PropTypes.func,
style: PropTypes.array, style: PropTypes.array,
preview: PropTypes.bool,
mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object]) mentions: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
}; };

View File

@ -5,7 +5,7 @@ import { Text } from 'react-native';
import styles from './styles'; import styles from './styles';
const Hashtag = React.memo(({ const Hashtag = React.memo(({
hashtag, channels, navToRoomInfo, style = [] hashtag, channels, navToRoomInfo, preview, style = []
}) => { }) => {
const handlePress = () => { const handlePress = () => {
const index = channels.findIndex(channel => channel.name === hashtag); const index = channels.findIndex(channel => channel.name === hashtag);
@ -19,8 +19,8 @@ const Hashtag = React.memo(({
if (channels && channels.length && channels.findIndex(channel => channel.name === hashtag) !== -1) { if (channels && channels.length && channels.findIndex(channel => channel.name === hashtag) !== -1) {
return ( return (
<Text <Text
style={[styles.mention, ...style]} style={[preview ? styles.text : styles.mention, ...style]}
onPress={handlePress} onPress={preview ? undefined : handlePress}
> >
{`#${ hashtag }`} {`#${ hashtag }`}
</Text> </Text>
@ -33,6 +33,7 @@ Hashtag.propTypes = {
hashtag: PropTypes.string, hashtag: PropTypes.string,
navToRoomInfo: PropTypes.func, navToRoomInfo: PropTypes.func,
style: PropTypes.array, style: PropTypes.array,
preview: PropTypes.bool,
channels: PropTypes.oneOfType([PropTypes.array, PropTypes.object]) channels: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
}; };

View File

@ -6,7 +6,7 @@ import styles from './styles';
import openLink from '../../utils/openLink'; import openLink from '../../utils/openLink';
const Link = React.memo(({ const Link = React.memo(({
children, link children, link, preview
}) => { }) => {
const handlePress = () => { const handlePress = () => {
if (!link) { if (!link) {
@ -20,7 +20,7 @@ const Link = React.memo(({
// if you have a [](https://rocket.chat) render https://rocket.chat // if you have a [](https://rocket.chat) render https://rocket.chat
return ( return (
<Text <Text
onPress={handlePress} onPress={preview ? undefined : handlePress}
style={styles.link} style={styles.link}
> >
{ childLength !== 0 ? children : link } { childLength !== 0 ? children : link }
@ -30,7 +30,8 @@ const Link = React.memo(({
Link.propTypes = { Link.propTypes = {
children: PropTypes.node, children: PropTypes.node,
link: PropTypes.string link: PropTypes.string,
preview: PropTypes.bool
}; };
export default Link; export default Link;

View File

@ -180,19 +180,25 @@ export default class Markdown extends PureComponent {
); );
}; };
renderLink = ({ children, href }) => ( renderLink = ({ children, href }) => {
<MarkdownLink link={href}> const { preview } = this.props;
return (
<MarkdownLink link={href} preview={preview}>
{children} {children}
</MarkdownLink> </MarkdownLink>
); );
}
renderHashtag = ({ hashtag }) => { renderHashtag = ({ hashtag }) => {
const { channels, navToRoomInfo, style } = this.props; const {
channels, navToRoomInfo, style, preview
} = this.props;
return ( return (
<MarkdownHashtag <MarkdownHashtag
hashtag={hashtag} hashtag={hashtag}
channels={channels} channels={channels}
navToRoomInfo={navToRoomInfo} navToRoomInfo={navToRoomInfo}
preview={preview}
style={style} style={style}
/> />
); );
@ -200,7 +206,7 @@ export default class Markdown extends PureComponent {
renderAtMention = ({ mentionName }) => { renderAtMention = ({ mentionName }) => {
const { const {
username, mentions, navToRoomInfo, style username, mentions, navToRoomInfo, preview, style
} = this.props; } = this.props;
return ( return (
<MarkdownAtMention <MarkdownAtMention
@ -208,6 +214,7 @@ export default class Markdown extends PureComponent {
mention={mentionName} mention={mentionName}
username={username} username={username}
navToRoomInfo={navToRoomInfo} navToRoomInfo={navToRoomInfo}
preview={preview}
style={style} style={style}
/> />
); );
@ -275,11 +282,17 @@ export default class Markdown extends PureComponent {
); );
}; };
renderBlockQuote = ({ children }) => ( renderBlockQuote = ({ children }) => {
const { preview } = this.props;
if (preview) {
return children;
}
return (
<MarkdownBlockQuote> <MarkdownBlockQuote>
{children} {children}
</MarkdownBlockQuote> </MarkdownBlockQuote>
); );
}
renderTable = ({ children, numColumns }) => ( renderTable = ({ children, numColumns }) => (
<MarkdownTable numColumns={numColumns}> <MarkdownTable numColumns={numColumns}>