11import { Str } from 'expensify-common' ;
22import isEmpty from 'lodash/isEmpty' ;
3- import React , { useEffect } from 'react' ;
3+ import React , { memo , useEffect , useMemo } from 'react' ;
44import type { StyleProp , TextStyle } from 'react-native' ;
55import Text from '@components/Text' ;
66import ZeroWidthView from '@components/ZeroWidthView' ;
@@ -11,7 +11,7 @@ import useTheme from '@hooks/useTheme';
1111import useThemeStyles from '@hooks/useThemeStyles' ;
1212import convertToLTR from '@libs/convertToLTR' ;
1313import { canUseTouchScreen } from '@libs/DeviceCapabilities' ;
14- import { containsOnlyCustomEmoji as containsOnlyCustomEmojiUtil , containsOnlyEmojis as containsOnlyEmojisUtil , isEmojiOnSeparateLine , splitTextWithEmojis } from '@libs/EmojiUtils' ;
14+ import { containsOnlyCustomEmoji as containsOnlyCustomEmojiUtil , containsOnlyEmojis as containsOnlyEmojisUtil , splitTextWithEmojis } from '@libs/EmojiUtils' ;
1515import Parser from '@libs/Parser' ;
1616import Performance from '@libs/Performance' ;
1717import { getHtmlWithAttachmentID , getTextFromHtml } from '@libs/ReportActionsUtils' ;
@@ -62,7 +62,7 @@ function TextCommentFragment({fragment, styleAsDeleted, reportActionID, styleAsM
6262
6363 const message = isEmpty ( iouMessage ) ? text : iouMessage ;
6464
65- const processedTextArray = splitTextWithEmojis ( message ) ;
65+ const processedTextArray = useMemo ( ( ) => splitTextWithEmojis ( message ) , [ message ] ) ;
6666
6767 useEffect ( ( ) => {
6868 Performance . markEnd ( CONST . TIMING . SEND_MESSAGE , { message : text } ) ;
@@ -74,7 +74,7 @@ function TextCommentFragment({fragment, styleAsDeleted, reportActionID, styleAsM
7474 // on native, we render it as text, not as html
7575 // on other device, only render it as text if the only difference is <br /> tag
7676 const containsOnlyEmojis = containsOnlyEmojisUtil ( text ?? '' ) ;
77- const containsOnlyCustomEmoji = containsOnlyCustomEmojiUtil ( text ) ;
77+ const containsOnlyCustomEmoji = useMemo ( ( ) => containsOnlyCustomEmojiUtil ( text ) , [ text ] ) ;
7878 const containsEmojis = CONST . REGEX . ALL_EMOJIS . test ( text ?? '' ) ;
7979 if ( ! shouldRenderAsText ( html , text ?? '' ) && ! ( containsOnlyEmojis && styleAsDeleted ) ) {
8080 const editedTag = fragment ?. isEdited ? `<edited ${ styleAsDeleted ? 'deleted' : '' } ></edited>` : '' ;
@@ -90,15 +90,7 @@ function TextCommentFragment({fragment, styleAsDeleted, reportActionID, styleAsM
9090 if ( ! htmlContent . includes ( '<emoji>' ) ) {
9191 htmlContent = Parser . replace ( htmlContent , { filterRules : [ 'emoji' ] , shouldEscapeText : false } ) ;
9292 }
93- const lines = htmlContent . split ( / < b r \s * \/ ? > / i) ;
94- const processedLines = lines . map ( ( line ) => {
95- if ( isEmojiOnSeparateLine ( line ) ) {
96- return line . replace ( '<emoji>' , '<emoji ismedium oneline >' ) ;
97- }
98- return line . replace ( '<emoji>' , '<emoji ismedium>' ) ;
99- } ) ;
100-
101- htmlContent = processedLines . join ( '<br />' ) ;
93+ htmlContent = Str . replaceAll ( htmlContent , '<emoji>' , '<emoji ismedium>' ) ;
10294 }
10395
10496 let htmlWithTag = editedTag ? `${ htmlContent } ${ editedTag } ` : htmlContent ;
@@ -166,4 +158,4 @@ function TextCommentFragment({fragment, styleAsDeleted, reportActionID, styleAsM
166158 ) ;
167159}
168160
169- export default TextCommentFragment ;
161+ export default memo ( TextCommentFragment ) ;
0 commit comments