Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions __tests__/__snapshots__/Storyshots.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6012,13 +6012,7 @@ exports[`Storyshots Message list 1`] = `
"fontWeight": "400",
},
Array [
Object {
"backgroundColor": "transparent",
"color": "#2F343D",
"fontFamily": "System",
"fontSize": 30,
"fontWeight": "400",
},
Object {},
Object {
"alignItems": "flex-start",
"flexDirection": "row",
Expand All @@ -6040,8 +6034,8 @@ exports[`Storyshots Message list 1`] = `
"overflow": "hidden",
},
Object {
"height": 30,
"width": 30,
"height": 20,
"width": 20,
},
]
}
Expand Down Expand Up @@ -6077,13 +6071,7 @@ exports[`Storyshots Message list 1`] = `
"fontWeight": "400",
},
Array [
Object {
"backgroundColor": "transparent",
"color": "#2F343D",
"fontFamily": "System",
"fontSize": 30,
"fontWeight": "400",
},
Object {},
Object {
"alignItems": "flex-start",
"flexDirection": "row",
Expand Down
15 changes: 11 additions & 4 deletions app/containers/markdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Text, Image } from 'react-native';
import { Parser, Node } from 'commonmark';
import Renderer from 'commonmark-react-renderer';
import PropTypes from 'prop-types';
import { toShort, shortnameToUnicode } from 'emoji-toolkit';
import { shortnameToUnicode } from 'emoji-toolkit';

import I18n from '../../i18n';

Expand Down Expand Up @@ -32,13 +32,19 @@ const emojiRanges = [
' |\n' // allow spaces and line breaks
].join('|');

const removeSpaces = str => str && str.replace(/\s/g, '');

const removeAllEmoji = str => str.replace(new RegExp(emojiRanges, 'g'), '');

const isOnlyEmoji = str => !removeAllEmoji(str).length;
const isOnlyEmoji = (str) => {
str = removeSpaces(str);
return !removeAllEmoji(str).length;
};

const removeOneEmoji = str => str.replace(new RegExp(emojiRanges), '');

const emojiCount = (str) => {
str = removeSpaces(str);
let oldLength = 0;
let counter = 0;

Expand Down Expand Up @@ -322,15 +328,16 @@ export default class Markdown extends PureComponent {

if (preview) {
m = m.split('\n').reduce((lines, line) => `${ lines } ${ line }`, '');
const ast = this.parser.parse(m);
return this.renderer.render(ast);
}

if (!useMarkdown && !preview) {
return <Text style={styles.text} numberOfLines={numberOfLines}>{m}</Text>;
}

const ast = this.parser.parse(m);
const encodedEmojis = toShort(m);
this.isMessageContainsOnlyEmoji = isOnlyEmoji(encodedEmojis) && emojiCount(encodedEmojis) <= 3;
this.isMessageContainsOnlyEmoji = isOnlyEmoji(m) && emojiCount(m) <= 3;

this.editedMessage(ast);

Expand Down