Skip to content

Commit

Permalink
conflicts resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
kbieganowski committed Apr 3, 2024
1 parent 13182fd commit a6768d3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 35 deletions.
3 changes: 3 additions & 0 deletions src/hooks/useMarkdownStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function useMarkdownStyle(): MarkdownStyle {
color: theme.text,
backgroundColor: 'transparent',
},
emoji: {
fontSize: 19,
},
pre: {
fontFamily: FontUtils.fontFamily.platform.MONOSPACE,
color: theme.text,
Expand Down
29 changes: 6 additions & 23 deletions src/libs/EmojiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,31 +125,14 @@ function isFirstLetterEmoji(message: string): boolean {
* Validates that this message contains only emojis
*/
function containsOnlyEmojis(message: string): boolean {
const trimmedMessage = Str.replaceAll(message.replace(/ /g, ''), '\n', '');
const match = trimmedMessage.match(CONST.REGEX.EMOJIS);

if (!match) {
if (!message) {
return false;
}
const splittedMessage = message.split(' ');
// @ts-expect-error -- comments contain only BMP characters and emojis so codePointAt will return number
const messageWithoutEmojis = splittedMessage.filter((char: string) => char && char.codePointAt(0) <= 0xffff);

const codes = [];
match.map((emoji) =>
getEmojiUnicode(emoji)
.split(' ')
.map((code) => {
if (!(CONST.INVISIBLE_CODEPOINTS as readonly string[]).includes(code)) {
codes.push(code);
}
return code;
}),
);

// Emojis are stored as multiple characters, so we're using spread operator
// to iterate over the actual emojis, not just characters that compose them
const messageCodes = [...trimmedMessage]
.map((char) => getEmojiUnicode(char))
.filter((string) => string.length > 0 && !(CONST.INVISIBLE_CODEPOINTS as readonly string[]).includes(string));
return codes.length === messageCodes.length;
return messageWithoutEmojis.length === 0;
}

/**
Expand Down Expand Up @@ -665,7 +648,7 @@ const splitTextWithEmojis = (text: string): string[] => {
// eslint-disable-next-line no-continue -- skip rest of the checks in current iteration
continue;
}
// @ts-expect-error -- ensured in 1st 'if' that object won't be undefined
// @ts-expect-error -- comments contain only BMP characters and emojis so codePointAt will return number
if (tmpResult[j].codePointAt(0) <= 0xffff) {
// is BMP character
tmpString += tmpResult[j];
Expand Down
7 changes: 4 additions & 3 deletions src/pages/home/report/comment/TextCommentFragment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,23 @@ function TextCommentFragment({fragment, styleAsDeleted, styleAsMuted = false, so
{CONST.REGEX.EMOJIS.test(message) ? (
<TextWithEmojiFragment
text={message}
textContainsOnlyEmojis={textContainsOnlyEmojis}
passedStyles={style}
styleAsDeleted={styleAsDeleted}
styleAsMuted={styleAsMuted}
isEdited={fragment.isEdited}
emojisOnly={textContainsOnlyEmojis}
/>
) : (
<>
<Text
style={[
textContainsOnlyEmojis ? styles.onlyEmojisText : undefined,
styles.ltr,
style,
styles.enhancedLineHeight,
styleAsDeleted ? styles.offlineFeedback.deleted : undefined,
styleAsMuted ? styles.colorMuted : undefined,
!DeviceCapabilities.canUseTouchScreen() || !isSmallScreenWidth ? styles.userSelectText : styles.userSelectNone,
textContainsOnlyEmojis ? styles.onlyEmojisText : styles.enhancedLineHeight,
]}
>
{message}
Expand All @@ -106,7 +107,7 @@ function TextCommentFragment({fragment, styleAsDeleted, styleAsMuted = false, so
{fragment.isEdited && (
<>
<Text
style={[textContainsOnlyEmojis && styles.onlyEmojisTextLineHeight, styles.userSelectNone]}
style={[styles.userSelectNone]}
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
>
{' '}
Expand Down
14 changes: 7 additions & 7 deletions src/pages/home/report/comment/TextWithEmojiFragment.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import type {StyleProp, TextStyle} from 'react-native';
import {View} from 'react-native';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
Expand All @@ -12,24 +11,24 @@ import CONST from '@src/CONST';

type ComponentProps = {
text: string;
textContainsOnlyEmojis: boolean;
passedStyles: StyleProp<TextStyle>;
styleAsDeleted?: boolean;
styleAsMuted?: boolean;
isSmallScreenWidth?: boolean;
isEdited?: boolean;
emojisOnly?: boolean;
};
function TextWithEmojiFragment({text, textContainsOnlyEmojis, passedStyles, styleAsDeleted, styleAsMuted, isSmallScreenWidth, isEdited}: ComponentProps) {
function TextWithEmojiFragment({text, passedStyles, styleAsDeleted, styleAsMuted, isSmallScreenWidth, isEdited, emojisOnly}: ComponentProps) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const theme = useTheme();
const processedTextArray = splitTextWithEmojis(text);

return (
<View style={styles.emojisAndTextWrapper}>
<>
{processedTextArray.map((word: string) =>
CONST.REGEX.EMOJIS.test(word) ? (
<Text style={[styles.emojisWithinText, textContainsOnlyEmojis ? styles.onlyEmojisText : undefined]}>{word}</Text>
<Text style={[emojisOnly ? styles.onlyEmojisText : styles.emojisWithinText]}>{word}</Text>
) : (
<Text
style={[
Expand All @@ -38,6 +37,7 @@ function TextWithEmojiFragment({text, textContainsOnlyEmojis, passedStyles, styl
styleAsDeleted ? styles.offlineFeedback.deleted : undefined,
styleAsMuted ? styles.colorMuted : undefined,
!DeviceCapabilities.canUseTouchScreen() || !isSmallScreenWidth ? styles.userSelectText : styles.userSelectNone,
emojisOnly ? styles.onlyEmojisText : styles.enhancedLineHeight,
]}
>
{word}
Expand All @@ -48,7 +48,7 @@ function TextWithEmojiFragment({text, textContainsOnlyEmojis, passedStyles, styl
{isEdited && (
<>
<Text
style={[textContainsOnlyEmojis && styles.onlyEmojisTextLineHeight, styles.userSelectNone]}
style={[emojisOnly && styles.onlyEmojisTextLineHeight, styles.userSelectNone]}
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
>
{' '}
Expand All @@ -62,7 +62,7 @@ function TextWithEmojiFragment({text, textContainsOnlyEmojis, passedStyles, styl
</Text>
</>
)}
</View>
</>
);
}

Expand Down
6 changes: 4 additions & 2 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1574,8 +1574,6 @@ const styles = (theme: ThemeColors) =>
emojisAndTextWrapper: {
flexDirection: 'row',
alignItems: 'center',
flexWrap: 'wrap',
width: '100%',
},

onlyEmojisText: {
Expand All @@ -1591,6 +1589,10 @@ const styles = (theme: ThemeColors) =>
lineHeight: variables.fontSizeOnlyEmojisHeight,
},

enhancedLineHeight: {
lineHeight: 23,
},

createMenuPositionSidebar: (windowHeight: number) =>
({
horizontal: 18,
Expand Down

0 comments on commit a6768d3

Please sign in to comment.