From 3a106885641d5013017e7e6b3f51611046fec295 Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Mon, 30 Oct 2023 16:35:45 -0400 Subject: [PATCH 01/16] Fixed Android - Chat - Message gets displayed from right to left --- .../ComposerWithSuggestions/ComposerWithSuggestions.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js index ea48f9cc931e..bdc09e5b7715 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js @@ -14,6 +14,7 @@ import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus'; import compose from '@libs/compose'; import * as ComposerUtils from '@libs/ComposerUtils'; import getDraftComment from '@libs/ComposerUtils/getDraftComment'; +import convertToLTR from '@libs/convertToLTR'; import convertToLTRForComposer from '@libs/convertToLTRForComposer'; import * as EmojiUtils from '@libs/EmojiUtils'; import focusComposerWithDelay from '@libs/focusComposerWithDelay'; @@ -524,6 +525,12 @@ function ComposerWithSuggestions({ }), [blur, focus, prepareCommentAndResetComposer, replaceSelectionWithText], ); + // eslint-disable-next-line rulesdir/prefer-early-return + useEffect(() => { + if (value === '') { + setValue(convertToLTR(value)); + } + }, [value]); return ( <> From 7c11e9375866031b54eacf48f4b5af1f99f0c818 Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Mon, 4 Dec 2023 19:12:25 -0400 Subject: [PATCH 02/16] Removed ignore lint rule and doing the early return --- .../ComposerWithSuggestions.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js index bdc09e5b7715..08eeba9a3591 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js @@ -525,11 +525,16 @@ function ComposerWithSuggestions({ }), [blur, focus, prepareCommentAndResetComposer, replaceSelectionWithText], ); - // eslint-disable-next-line rulesdir/prefer-early-return + useEffect(() => { - if (value === '') { - setValue(convertToLTR(value)); - } + const changeInputToLTR = (inputValue) => { + if (inputValue === '') { + setValue(convertToLTR(inputValue)); + } + return true; + }; + + return changeInputToLTR(value); }, [value]); return ( From fbd37e810d112ef0a8721fce64352d6a24fd097f Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Mon, 4 Dec 2023 19:40:19 -0400 Subject: [PATCH 03/16] Fixed early return when useEffect bug --- .../ComposerWithSuggestions.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js index 08eeba9a3591..51aca3577180 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js @@ -527,14 +527,10 @@ function ComposerWithSuggestions({ ); useEffect(() => { - const changeInputToLTR = (inputValue) => { - if (inputValue === '') { - setValue(convertToLTR(inputValue)); - } - return true; - }; - - return changeInputToLTR(value); + if (value !== '') { + return; + } + setValue(convertToLTR(value)); }, [value]); return ( From 5ffd754f97cb9dcc7d3a943c4d43288c1f92e168 Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Tue, 5 Dec 2023 12:13:04 -0400 Subject: [PATCH 04/16] Fixed bugs: when mention, sending empty messages, no placeholder --- .../ComposerWithSuggestions.js | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js index 51aca3577180..1c2a2d578109 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js @@ -106,6 +106,7 @@ function ComposerWithSuggestions({ const styles = useThemeStyles(); const {preferredLocale} = useLocalize(); const isFocused = useIsFocused(); + const [firstChange, setFirstChange] = useState(true); const navigation = useNavigation(); const emojisPresentBefore = useRef([]); const [value, setValue] = useState(() => { @@ -221,16 +222,42 @@ function ComposerWithSuggestions({ debouncedUpdateFrequentlyUsedEmojis(); } } - const newCommentConverted = convertToLTRForComposer(newComment); + + let newCommentConverted = convertToLTRForComposer(newComment); + + const moveCursorToEndOfLine = (commentLength) => { + setSelection({ + start: commentLength + 1, + end: commentLength + 1, + }); + }; + + if (firstChange && commentRef.current === '' && !['@'].includes(newComment)) { + if (commentRef.current !== newComment) { + setValue(convertToLTR(newComment)); + moveCursorToEndOfLine(newComment.length); + } + setFirstChange(false); + } else if (commentRef.current !== newComment) { + newCommentConverted = newComment.length <= 1 ? newCommentConverted.replace(/\u2066/g, '') : newCommentConverted; + setValue(newCommentConverted); + moveCursorToEndOfLine(newComment.length); + setFirstChange(false); + } + const isNewCommentEmpty = !!newCommentConverted.match(/^(\s)*$/); const isPrevCommentEmpty = !!commentRef.current.match(/^(\s)*$/); /** Only update isCommentEmpty state if it's different from previous one */ if (isNewCommentEmpty !== isPrevCommentEmpty) { setIsCommentEmpty(isNewCommentEmpty); + if (isNewCommentEmpty) { + setFirstChange(true); + } } + emojisPresentBefore.current = emojis; - setValue(newCommentConverted); + if (commentValue !== newComment) { const position = Math.max(selection.end + (newComment.length - commentRef.current.length), cursorPosition || 0); setSelection({ @@ -269,6 +296,7 @@ function ComposerWithSuggestions({ raiseIsScrollLikelyLayoutTriggered, debouncedSaveReportComment, selection.end, + firstChange, ], ); @@ -526,13 +554,6 @@ function ComposerWithSuggestions({ [blur, focus, prepareCommentAndResetComposer, replaceSelectionWithText], ); - useEffect(() => { - if (value !== '') { - return; - } - setValue(convertToLTR(value)); - }, [value]); - return ( <> From 59f446695075067d8b90e57d68c4de70b2dc3217 Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Wed, 6 Dec 2023 09:47:01 -0400 Subject: [PATCH 05/16] Added comments and refactoring code to better understanding --- src/libs/convertToLTR/index.android.ts | 22 ++++++++++ src/libs/convertToLTR/index.ts | 9 ++++ .../convertToLTRForComposer/index.android.ts | 3 +- src/libs/convertToLTRForComposer/types.ts | 2 +- .../ComposerWithSuggestions.js | 41 ++++++++----------- 5 files changed, 51 insertions(+), 26 deletions(-) diff --git a/src/libs/convertToLTR/index.android.ts b/src/libs/convertToLTR/index.android.ts index d73fd3de7a21..89dcfda9ec9f 100644 --- a/src/libs/convertToLTR/index.android.ts +++ b/src/libs/convertToLTR/index.android.ts @@ -7,4 +7,26 @@ import ConvertToLTR from './types'; */ const convertToLTR: ConvertToLTR = (text) => `${CONST.UNICODE.LTR}${text}`; +/** This is necessary to convert the input to LTR, there is a delay that causes the cursor not to go to the end of the input line when pasting text or typing fast. */ +const moveCursorToEndOfLine = (commentLength: number, setSelection:(value: React.SetStateAction<{ + start: number; + end: number; +}>)=>void) => { + setSelection({ + start: commentLength + 1, + end: commentLength + 1, + }); +} + +/** We should remove the LTR unicode when the input is empty to prevent: Sending an empty message, bad function of metion suggestions (force option: always remove the unicode), or placeholder issues */ +const removeUnicodeLTRWhenEmpty = (newComment:string, newCommentConverted:string, force?:boolean) => { + + const removeRegEx = new RegExp(`${CONST.UNICODE.LTR}`,'g') + + const result = newComment.length <= 1 || force ? newCommentConverted.replace(removeRegEx, '') : newCommentConverted; + return result; +} + +export {moveCursorToEndOfLine, removeUnicodeLTRWhenEmpty}; + export default convertToLTR; diff --git a/src/libs/convertToLTR/index.ts b/src/libs/convertToLTR/index.ts index 58d8be93836e..3117bfeae077 100644 --- a/src/libs/convertToLTR/index.ts +++ b/src/libs/convertToLTR/index.ts @@ -2,4 +2,13 @@ import ConvertToLTR from './types'; const convertToLTR: ConvertToLTR = (text) => text; +const moveCursorToEndOfLine = (commentLength: number, setSelection:(value: React.SetStateAction<{ + start: number; + end: number; +}>)=>void) => setSelection + +const removeUnicodeLTRWhenEmpty = (newComment:string) => newComment; + +export {moveCursorToEndOfLine, removeUnicodeLTRWhenEmpty}; + export default convertToLTR; diff --git a/src/libs/convertToLTRForComposer/index.android.ts b/src/libs/convertToLTRForComposer/index.android.ts index 09e7f2e5cd87..25b2ddaaf5cf 100644 --- a/src/libs/convertToLTRForComposer/index.android.ts +++ b/src/libs/convertToLTRForComposer/index.android.ts @@ -1,8 +1,9 @@ +import CONST from '@src/CONST'; import ConvertToLTRForComposer from './types'; /** * Android only - Do not convert RTL text to a LTR text for input box using Unicode controls. * Android does not properly support bidirectional text for mixed content for input box */ -const convertToLTRForComposer: ConvertToLTRForComposer = (text) => text; +const convertToLTRForComposer: ConvertToLTRForComposer = (text, isComposerEmpty) => (isComposerEmpty ? `${CONST.UNICODE.LTR}${text}` : text); export default convertToLTRForComposer; diff --git a/src/libs/convertToLTRForComposer/types.ts b/src/libs/convertToLTRForComposer/types.ts index c6edeaaba446..88f468ef1843 100644 --- a/src/libs/convertToLTRForComposer/types.ts +++ b/src/libs/convertToLTRForComposer/types.ts @@ -1,3 +1,3 @@ -type ConvertToLTRForComposer = (text: string) => string; +type ConvertToLTRForComposer = (text: string, isComposerEmpty?: boolean) => string; export default ConvertToLTRForComposer; diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js index 1c2a2d578109..231fb6e1a4c8 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js @@ -14,7 +14,7 @@ import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus'; import compose from '@libs/compose'; import * as ComposerUtils from '@libs/ComposerUtils'; import getDraftComment from '@libs/ComposerUtils/getDraftComment'; -import convertToLTR from '@libs/convertToLTR'; +import {moveCursorToEndOfLine, removeUnicodeLTRWhenEmpty} from '@libs/convertToLTR'; import convertToLTRForComposer from '@libs/convertToLTRForComposer'; import * as EmojiUtils from '@libs/EmojiUtils'; import focusComposerWithDelay from '@libs/focusComposerWithDelay'; @@ -106,7 +106,7 @@ function ComposerWithSuggestions({ const styles = useThemeStyles(); const {preferredLocale} = useLocalize(); const isFocused = useIsFocused(); - const [firstChange, setFirstChange] = useState(true); + const [composerIsEmpty, setComposerIsEmpty] = useState(true); const navigation = useNavigation(); const emojisPresentBefore = useRef([]); const [value, setValue] = useState(() => { @@ -223,43 +223,36 @@ function ComposerWithSuggestions({ } } - let newCommentConverted = convertToLTRForComposer(newComment); + let newCommentConverted = newComment; + const prevComment = commentRef.current; - const moveCursorToEndOfLine = (commentLength) => { - setSelection({ - start: commentLength + 1, - end: commentLength + 1, - }); - }; - - if (firstChange && commentRef.current === '' && !['@'].includes(newComment)) { - if (commentRef.current !== newComment) { - setValue(convertToLTR(newComment)); - moveCursorToEndOfLine(newComment.length); + // This prevent the double execution of setting input value that could affect the place holder and could send an empty message or draft messages in android + if (prevComment !== newComment) { + newCommentConverted = removeUnicodeLTRWhenEmpty(newComment, newCommentConverted); + newCommentConverted = convertToLTRForComposer(newCommentConverted, composerIsEmpty); + if (['@'].includes(newComment)) { + newCommentConverted = removeUnicodeLTRWhenEmpty(newComment, newCommentConverted, true); } - setFirstChange(false); - } else if (commentRef.current !== newComment) { - newCommentConverted = newComment.length <= 1 ? newCommentConverted.replace(/\u2066/g, '') : newCommentConverted; setValue(newCommentConverted); - moveCursorToEndOfLine(newComment.length); - setFirstChange(false); + moveCursorToEndOfLine(newComment.length, setSelection); + setComposerIsEmpty(false); } const isNewCommentEmpty = !!newCommentConverted.match(/^(\s)*$/); - const isPrevCommentEmpty = !!commentRef.current.match(/^(\s)*$/); + const isPrevCommentEmpty = !!prevComment.match(/^(\s)*$/); /** Only update isCommentEmpty state if it's different from previous one */ if (isNewCommentEmpty !== isPrevCommentEmpty) { setIsCommentEmpty(isNewCommentEmpty); if (isNewCommentEmpty) { - setFirstChange(true); + setComposerIsEmpty(true); } } emojisPresentBefore.current = emojis; if (commentValue !== newComment) { - const position = Math.max(selection.end + (newComment.length - commentRef.current.length), cursorPosition || 0); + const position = Math.max(selection.end + (newComment.length - prevComment.length), cursorPosition || 0); setSelection({ start: position, end: position, @@ -267,7 +260,7 @@ function ComposerWithSuggestions({ } // Indicate that draft has been created. - if (commentRef.current.length === 0 && newCommentConverted.length !== 0) { + if (prevComment.length === 0 && newCommentConverted.length !== 0) { Report.setReportWithDraft(reportID, true); } @@ -296,7 +289,7 @@ function ComposerWithSuggestions({ raiseIsScrollLikelyLayoutTriggered, debouncedSaveReportComment, selection.end, - firstChange, + composerIsEmpty, ], ); From 431d7e2c5e56be98a5f68c757a622502b91230cc Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Wed, 6 Dec 2023 11:33:54 -0400 Subject: [PATCH 06/16] Fixed prettier errors --- src/libs/convertToLTR/index.android.ts | 22 +++++++++++++--------- src/libs/convertToLTR/index.ts | 15 ++++++++++----- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/libs/convertToLTR/index.android.ts b/src/libs/convertToLTR/index.android.ts index 89dcfda9ec9f..1697f2c0a5bc 100644 --- a/src/libs/convertToLTR/index.android.ts +++ b/src/libs/convertToLTR/index.android.ts @@ -8,24 +8,28 @@ import ConvertToLTR from './types'; const convertToLTR: ConvertToLTR = (text) => `${CONST.UNICODE.LTR}${text}`; /** This is necessary to convert the input to LTR, there is a delay that causes the cursor not to go to the end of the input line when pasting text or typing fast. */ -const moveCursorToEndOfLine = (commentLength: number, setSelection:(value: React.SetStateAction<{ - start: number; - end: number; -}>)=>void) => { +const moveCursorToEndOfLine = ( + commentLength: number, + setSelection: ( + value: React.SetStateAction<{ + start: number; + end: number; + }>, + ) => void, +) => { setSelection({ start: commentLength + 1, end: commentLength + 1, }); -} +}; /** We should remove the LTR unicode when the input is empty to prevent: Sending an empty message, bad function of metion suggestions (force option: always remove the unicode), or placeholder issues */ -const removeUnicodeLTRWhenEmpty = (newComment:string, newCommentConverted:string, force?:boolean) => { - - const removeRegEx = new RegExp(`${CONST.UNICODE.LTR}`,'g') +const removeUnicodeLTRWhenEmpty = (newComment: string, newCommentConverted: string, force?: boolean) => { + const removeRegEx = new RegExp(`${CONST.UNICODE.LTR}`, 'g'); const result = newComment.length <= 1 || force ? newCommentConverted.replace(removeRegEx, '') : newCommentConverted; return result; -} +}; export {moveCursorToEndOfLine, removeUnicodeLTRWhenEmpty}; diff --git a/src/libs/convertToLTR/index.ts b/src/libs/convertToLTR/index.ts index 3117bfeae077..ee6728943259 100644 --- a/src/libs/convertToLTR/index.ts +++ b/src/libs/convertToLTR/index.ts @@ -2,12 +2,17 @@ import ConvertToLTR from './types'; const convertToLTR: ConvertToLTR = (text) => text; -const moveCursorToEndOfLine = (commentLength: number, setSelection:(value: React.SetStateAction<{ - start: number; - end: number; -}>)=>void) => setSelection +const moveCursorToEndOfLine = ( + commentLength: number, + setSelection: ( + value: React.SetStateAction<{ + start: number; + end: number; + }>, + ) => void, +) => setSelection; -const removeUnicodeLTRWhenEmpty = (newComment:string) => newComment; +const removeUnicodeLTRWhenEmpty = (newComment: string) => newComment; export {moveCursorToEndOfLine, removeUnicodeLTRWhenEmpty}; From 33b573396a4bd747f2e95b949d7423e91c38f336 Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Wed, 6 Dec 2023 17:05:16 -0400 Subject: [PATCH 07/16] Fixed observations, added suggestions and added extra comments --- src/libs/convertToLTR/index.android.ts | 23 ++++++++----------- src/libs/convertToLTR/index.ts | 5 ++-- .../convertToLTRForComposer/index.android.ts | 17 +++++++++++++- .../ComposerWithSuggestions.js | 14 ++++------- 4 files changed, 32 insertions(+), 27 deletions(-) diff --git a/src/libs/convertToLTR/index.android.ts b/src/libs/convertToLTR/index.android.ts index 1697f2c0a5bc..0bc59ee40a92 100644 --- a/src/libs/convertToLTR/index.android.ts +++ b/src/libs/convertToLTR/index.android.ts @@ -1,13 +1,16 @@ -import CONST from '@src/CONST'; -import ConvertToLTR from './types'; - /** * Android only - convert RTL text to a LTR text using Unicode controls. - * https://www.w3.org/International/questions/qa-bidi-unicode-controls + * + * In React Native, when working with bidirectional text (RTL - Right-to-Left or LTR - Left-to-Right), you may encounter issues related to text rendering, especially on Android devices. These issues arise because Android's default behavior for text direction might not always align with the desired directionality of your app. */ +import CONST from '@src/CONST'; +import ConvertToLTR from './types'; + const convertToLTR: ConvertToLTR = (text) => `${CONST.UNICODE.LTR}${text}`; -/** This is necessary to convert the input to LTR, there is a delay that causes the cursor not to go to the end of the input line when pasting text or typing fast. */ +/** + * This is necessary to convert the input to LTR, there is a delay that causes the cursor not to go to the end of the input line when pasting text or typing fast. The delay is caused for the time that takes the input to convert from RTL to LTR and viceversa. + */ const moveCursorToEndOfLine = ( commentLength: number, setSelection: ( @@ -23,14 +26,6 @@ const moveCursorToEndOfLine = ( }); }; -/** We should remove the LTR unicode when the input is empty to prevent: Sending an empty message, bad function of metion suggestions (force option: always remove the unicode), or placeholder issues */ -const removeUnicodeLTRWhenEmpty = (newComment: string, newCommentConverted: string, force?: boolean) => { - const removeRegEx = new RegExp(`${CONST.UNICODE.LTR}`, 'g'); - - const result = newComment.length <= 1 || force ? newCommentConverted.replace(removeRegEx, '') : newCommentConverted; - return result; -}; - -export {moveCursorToEndOfLine, removeUnicodeLTRWhenEmpty}; +export {moveCursorToEndOfLine}; export default convertToLTR; diff --git a/src/libs/convertToLTR/index.ts b/src/libs/convertToLTR/index.ts index ee6728943259..ef08f9be1bf8 100644 --- a/src/libs/convertToLTR/index.ts +++ b/src/libs/convertToLTR/index.ts @@ -1,3 +1,4 @@ +// The Android platform has to handle switching between LTR and RTL languages a bit differently (https://developer.android.com/training/basics/supporting-devices/languages). For all other platforms, these can simply be no-op functions. import ConvertToLTR from './types'; const convertToLTR: ConvertToLTR = (text) => text; @@ -12,8 +13,6 @@ const moveCursorToEndOfLine = ( ) => void, ) => setSelection; -const removeUnicodeLTRWhenEmpty = (newComment: string) => newComment; - -export {moveCursorToEndOfLine, removeUnicodeLTRWhenEmpty}; +export {moveCursorToEndOfLine}; export default convertToLTR; diff --git a/src/libs/convertToLTRForComposer/index.android.ts b/src/libs/convertToLTRForComposer/index.android.ts index 25b2ddaaf5cf..b67cc90ff8b7 100644 --- a/src/libs/convertToLTRForComposer/index.android.ts +++ b/src/libs/convertToLTRForComposer/index.android.ts @@ -1,9 +1,24 @@ import CONST from '@src/CONST'; import ConvertToLTRForComposer from './types'; +/** Android only - We should remove the LTR unicode when the input is empty to prevent: Sending an empty message, metion suggestions not works if @ is the first character; (force option: always remove the unicode, should be used when the user starts writing with @) or placeholder not shows if unicode character is the only remaining character. */ +const resetLTRWhenEmpty = (newComment: string, force?: boolean) => { + const result = newComment.length <= 1 || force ? newComment.replace(CONST.UNICODE.LTR, '') : newComment; + return result; +}; + /** * Android only - Do not convert RTL text to a LTR text for input box using Unicode controls. * Android does not properly support bidirectional text for mixed content for input box */ -const convertToLTRForComposer: ConvertToLTRForComposer = (text, isComposerEmpty) => (isComposerEmpty ? `${CONST.UNICODE.LTR}${text}` : text); +const convertToLTRForComposer: ConvertToLTRForComposer = (text, isComposerEmpty) => { + let newText = resetLTRWhenEmpty(text); + if (newText.startsWith(`${CONST.UNICODE.LTR}@`)) { + newText = resetLTRWhenEmpty(newText, true); + return newText; + } + + return isComposerEmpty ? `${CONST.UNICODE.LTR}${newText}` : newText; +}; + export default convertToLTRForComposer; diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js index 231fb6e1a4c8..bd203fd90c70 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js @@ -14,7 +14,7 @@ import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus'; import compose from '@libs/compose'; import * as ComposerUtils from '@libs/ComposerUtils'; import getDraftComment from '@libs/ComposerUtils/getDraftComment'; -import {moveCursorToEndOfLine, removeUnicodeLTRWhenEmpty} from '@libs/convertToLTR'; +import {moveCursorToEndOfLine} from '@libs/convertToLTR'; import convertToLTRForComposer from '@libs/convertToLTRForComposer'; import * as EmojiUtils from '@libs/EmojiUtils'; import focusComposerWithDelay from '@libs/focusComposerWithDelay'; @@ -106,7 +106,7 @@ function ComposerWithSuggestions({ const styles = useThemeStyles(); const {preferredLocale} = useLocalize(); const isFocused = useIsFocused(); - const [composerIsEmpty, setComposerIsEmpty] = useState(true); + const composerIsEmpty = useRef(true); const navigation = useNavigation(); const emojisPresentBefore = useRef([]); const [value, setValue] = useState(() => { @@ -228,14 +228,10 @@ function ComposerWithSuggestions({ // This prevent the double execution of setting input value that could affect the place holder and could send an empty message or draft messages in android if (prevComment !== newComment) { - newCommentConverted = removeUnicodeLTRWhenEmpty(newComment, newCommentConverted); - newCommentConverted = convertToLTRForComposer(newCommentConverted, composerIsEmpty); - if (['@'].includes(newComment)) { - newCommentConverted = removeUnicodeLTRWhenEmpty(newComment, newCommentConverted, true); - } + newCommentConverted = convertToLTRForComposer(newCommentConverted, composerIsEmpty.current); setValue(newCommentConverted); moveCursorToEndOfLine(newComment.length, setSelection); - setComposerIsEmpty(false); + composerIsEmpty.current = false; } const isNewCommentEmpty = !!newCommentConverted.match(/^(\s)*$/); @@ -245,7 +241,7 @@ function ComposerWithSuggestions({ if (isNewCommentEmpty !== isPrevCommentEmpty) { setIsCommentEmpty(isNewCommentEmpty); if (isNewCommentEmpty) { - setComposerIsEmpty(true); + composerIsEmpty.current = true; } } From 89d738e71540ccb1d57d9483272e6332ec7d5b87 Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Fri, 8 Dec 2023 09:04:35 -0400 Subject: [PATCH 08/16] Moving functions from convertToLTR to convertToLTRForComposer lib, renaming variable from newCommentConverted to newCommentConvertedToLTR --- src/libs/convertToLTR/index.android.ts | 20 ---------------- src/libs/convertToLTR/index.ts | 12 ---------- .../convertToLTRForComposer/index.android.ts | 20 ++++++++++++++++ src/libs/convertToLTRForComposer/index.ts | 5 ++++ .../ComposerWithSuggestions.js | 23 +++++++++---------- 5 files changed, 36 insertions(+), 44 deletions(-) diff --git a/src/libs/convertToLTR/index.android.ts b/src/libs/convertToLTR/index.android.ts index 0bc59ee40a92..0de503e3b6c6 100644 --- a/src/libs/convertToLTR/index.android.ts +++ b/src/libs/convertToLTR/index.android.ts @@ -8,24 +8,4 @@ import ConvertToLTR from './types'; const convertToLTR: ConvertToLTR = (text) => `${CONST.UNICODE.LTR}${text}`; -/** - * This is necessary to convert the input to LTR, there is a delay that causes the cursor not to go to the end of the input line when pasting text or typing fast. The delay is caused for the time that takes the input to convert from RTL to LTR and viceversa. - */ -const moveCursorToEndOfLine = ( - commentLength: number, - setSelection: ( - value: React.SetStateAction<{ - start: number; - end: number; - }>, - ) => void, -) => { - setSelection({ - start: commentLength + 1, - end: commentLength + 1, - }); -}; - -export {moveCursorToEndOfLine}; - export default convertToLTR; diff --git a/src/libs/convertToLTR/index.ts b/src/libs/convertToLTR/index.ts index ef08f9be1bf8..0dca0d0b3ace 100644 --- a/src/libs/convertToLTR/index.ts +++ b/src/libs/convertToLTR/index.ts @@ -3,16 +3,4 @@ import ConvertToLTR from './types'; const convertToLTR: ConvertToLTR = (text) => text; -const moveCursorToEndOfLine = ( - commentLength: number, - setSelection: ( - value: React.SetStateAction<{ - start: number; - end: number; - }>, - ) => void, -) => setSelection; - -export {moveCursorToEndOfLine}; - export default convertToLTR; diff --git a/src/libs/convertToLTRForComposer/index.android.ts b/src/libs/convertToLTRForComposer/index.android.ts index b67cc90ff8b7..5e78fc87e54b 100644 --- a/src/libs/convertToLTRForComposer/index.android.ts +++ b/src/libs/convertToLTRForComposer/index.android.ts @@ -21,4 +21,24 @@ const convertToLTRForComposer: ConvertToLTRForComposer = (text, isComposerEmpty) return isComposerEmpty ? `${CONST.UNICODE.LTR}${newText}` : newText; }; +/** + * This is necessary to convert the input to LTR, there is a delay that causes the cursor not to go to the end of the input line when pasting text or typing fast. The delay is caused for the time that takes the input to convert from RTL to LTR and viceversa. + */ +const moveCursorToEndOfLine = ( + commentLength: number, + setSelection: ( + value: React.SetStateAction<{ + start: number; + end: number; + }>, + ) => void, +) => { + setSelection({ + start: commentLength + 1, + end: commentLength + 1, + }); +}; + +export {moveCursorToEndOfLine}; + export default convertToLTRForComposer; diff --git a/src/libs/convertToLTRForComposer/index.ts b/src/libs/convertToLTRForComposer/index.ts index dd6ee50d862e..9286a41a6712 100644 --- a/src/libs/convertToLTRForComposer/index.ts +++ b/src/libs/convertToLTRForComposer/index.ts @@ -30,4 +30,9 @@ const convertToLTRForComposer: ConvertToLTRForComposer = (text) => { // Add the LTR marker to the beginning of the text. return `${CONST.UNICODE.LTR}${text}`; }; + +const moveCursorToEndOfLine = (commentLength: number) => commentLength; + +export {moveCursorToEndOfLine}; + export default convertToLTRForComposer; diff --git a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js index bd203fd90c70..926a2e75384e 100644 --- a/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js +++ b/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.js @@ -14,8 +14,7 @@ import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus'; import compose from '@libs/compose'; import * as ComposerUtils from '@libs/ComposerUtils'; import getDraftComment from '@libs/ComposerUtils/getDraftComment'; -import {moveCursorToEndOfLine} from '@libs/convertToLTR'; -import convertToLTRForComposer from '@libs/convertToLTRForComposer'; +import convertToLTRForComposer, {moveCursorToEndOfLine} from '@libs/convertToLTRForComposer'; import * as EmojiUtils from '@libs/EmojiUtils'; import focusComposerWithDelay from '@libs/focusComposerWithDelay'; import * as KeyDownListener from '@libs/KeyboardShortcut/KeyDownPressListener'; @@ -223,18 +222,18 @@ function ComposerWithSuggestions({ } } - let newCommentConverted = newComment; + let newCommentConvertedToLTR = newComment; const prevComment = commentRef.current; // This prevent the double execution of setting input value that could affect the place holder and could send an empty message or draft messages in android if (prevComment !== newComment) { - newCommentConverted = convertToLTRForComposer(newCommentConverted, composerIsEmpty.current); - setValue(newCommentConverted); + newCommentConvertedToLTR = convertToLTRForComposer(newCommentConvertedToLTR, composerIsEmpty.current); + setValue(newCommentConvertedToLTR); moveCursorToEndOfLine(newComment.length, setSelection); composerIsEmpty.current = false; } - const isNewCommentEmpty = !!newCommentConverted.match(/^(\s)*$/); + const isNewCommentEmpty = !!newCommentConvertedToLTR.match(/^(\s)*$/); const isPrevCommentEmpty = !!prevComment.match(/^(\s)*$/); /** Only update isCommentEmpty state if it's different from previous one */ @@ -256,22 +255,22 @@ function ComposerWithSuggestions({ } // Indicate that draft has been created. - if (prevComment.length === 0 && newCommentConverted.length !== 0) { + if (prevComment.length === 0 && newCommentConvertedToLTR.length !== 0) { Report.setReportWithDraft(reportID, true); } // The draft has been deleted. - if (newCommentConverted.length === 0) { + if (newCommentConvertedToLTR.length === 0) { Report.setReportWithDraft(reportID, false); } - commentRef.current = newCommentConverted; + commentRef.current = newCommentConvertedToLTR; if (shouldDebounceSaveComment) { - debouncedSaveReportComment(reportID, newCommentConverted); + debouncedSaveReportComment(reportID, newCommentConvertedToLTR); } else { - Report.saveReportComment(reportID, newCommentConverted || ''); + Report.saveReportComment(reportID, newCommentConvertedToLTR || ''); } - if (newCommentConverted) { + if (newCommentConvertedToLTR) { debouncedBroadcastUserIsTyping(reportID); } }, From 2a9f636057bfc95e16ad035296dd5caaf7825a76 Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Mon, 11 Dec 2023 08:55:45 -0400 Subject: [PATCH 09/16] Added space to the list of characters to consider as empty for the composer input --- src/libs/convertToLTRForComposer/index.android.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/convertToLTRForComposer/index.android.ts b/src/libs/convertToLTRForComposer/index.android.ts index 5e78fc87e54b..1d8e77c53fb0 100644 --- a/src/libs/convertToLTRForComposer/index.android.ts +++ b/src/libs/convertToLTRForComposer/index.android.ts @@ -1,7 +1,7 @@ import CONST from '@src/CONST'; import ConvertToLTRForComposer from './types'; -/** Android only - We should remove the LTR unicode when the input is empty to prevent: Sending an empty message, metion suggestions not works if @ is the first character; (force option: always remove the unicode, should be used when the user starts writing with @) or placeholder not shows if unicode character is the only remaining character. */ +/** Android only - We should remove the LTR unicode when the input is empty to prevent: Sending an empty message, metion suggestions not works if @ or \s (at or space) is the first character; (force option: always remove the unicode, should be used when the user starts writing with @) or placeholder not shows if unicode character is the only remaining character. */ const resetLTRWhenEmpty = (newComment: string, force?: boolean) => { const result = newComment.length <= 1 || force ? newComment.replace(CONST.UNICODE.LTR, '') : newComment; return result; @@ -13,7 +13,7 @@ const resetLTRWhenEmpty = (newComment: string, force?: boolean) => { */ const convertToLTRForComposer: ConvertToLTRForComposer = (text, isComposerEmpty) => { let newText = resetLTRWhenEmpty(text); - if (newText.startsWith(`${CONST.UNICODE.LTR}@`)) { + if (newText.startsWith(`${CONST.UNICODE.LTR}@`) || newText.match(/^(\s)*$/)) { newText = resetLTRWhenEmpty(newText, true); return newText; } From 37409499d5a5a48c64c3f10e1924f61ec807d94b Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Tue, 12 Dec 2023 17:51:11 -0400 Subject: [PATCH 10/16] Added method to determinate if we should convert the composer to LTR using regex --- .../convertToLTRForComposer/index.android.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/libs/convertToLTRForComposer/index.android.ts b/src/libs/convertToLTRForComposer/index.android.ts index 1d8e77c53fb0..e82ea9f1982a 100644 --- a/src/libs/convertToLTRForComposer/index.android.ts +++ b/src/libs/convertToLTRForComposer/index.android.ts @@ -1,9 +1,19 @@ import CONST from '@src/CONST'; import ConvertToLTRForComposer from './types'; -/** Android only - We should remove the LTR unicode when the input is empty to prevent: Sending an empty message, metion suggestions not works if @ or \s (at or space) is the first character; (force option: always remove the unicode, should be used when the user starts writing with @) or placeholder not shows if unicode character is the only remaining character. */ +/** + * Android only - We need to determinate when composer is considered empty this going to be used when we don't want to convert the input composer to LTR + */ +function hasBeenComposerConsideredEmpty(text: string): boolean { + // Regular expressions with all character that are consider as empty (spaces, unicode with spaces and unicode with at) + const emptyExpressions = [/^\s*$/, new RegExp(`^${CONST.UNICODE.LTR}@$`), new RegExp(`${CONST.UNICODE.LTR}\\s*$`)]; + return emptyExpressions.some((exp) => exp.test(text)); +} + +/** + * Android only - We should remove the LTR unicode when the input is empty to prevent: Sending an empty message, metion suggestions not works if @ or \s (at or space) is the first character; (force option: always remove the unicode, going to be used when composer is consider as empty) or placeholder not shows if unicode character is the only remaining character. */ const resetLTRWhenEmpty = (newComment: string, force?: boolean) => { - const result = newComment.length <= 1 || force ? newComment.replace(CONST.UNICODE.LTR, '') : newComment; + const result = newComment.length <= 1 || force ? newComment.replaceAll(CONST.UNICODE.LTR, '') : newComment; return result; }; @@ -12,12 +22,11 @@ const resetLTRWhenEmpty = (newComment: string, force?: boolean) => { * Android does not properly support bidirectional text for mixed content for input box */ const convertToLTRForComposer: ConvertToLTRForComposer = (text, isComposerEmpty) => { - let newText = resetLTRWhenEmpty(text); - if (newText.startsWith(`${CONST.UNICODE.LTR}@`) || newText.match(/^(\s)*$/)) { - newText = resetLTRWhenEmpty(newText, true); + const isConsideredAsEmpty = hasBeenComposerConsideredEmpty(text); + const newText = resetLTRWhenEmpty(text, isConsideredAsEmpty); + if (isConsideredAsEmpty) { return newText; } - return isComposerEmpty ? `${CONST.UNICODE.LTR}${newText}` : newText; }; From 04c95e0d849879d6614a6bb21b349399100547cd Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Wed, 13 Dec 2023 13:27:36 -0400 Subject: [PATCH 11/16] Fixed suggestions: variable names, comments, misspelling --- .../convertToLTRForComposer/index.android.ts | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/libs/convertToLTRForComposer/index.android.ts b/src/libs/convertToLTRForComposer/index.android.ts index e82ea9f1982a..9a73e9c03982 100644 --- a/src/libs/convertToLTRForComposer/index.android.ts +++ b/src/libs/convertToLTRForComposer/index.android.ts @@ -2,16 +2,25 @@ import CONST from '@src/CONST'; import ConvertToLTRForComposer from './types'; /** - * Android only - We need to determinate when composer is considered empty this going to be used when we don't want to convert the input composer to LTR + * Android only - The composer is considered "empty" if all it contains is the LTR character followed by an @ or space. */ -function hasBeenComposerConsideredEmpty(text: string): boolean { - // Regular expressions with all character that are consider as empty (spaces, unicode with spaces and unicode with at) - const emptyExpressions = [/^\s*$/, new RegExp(`^${CONST.UNICODE.LTR}@$`), new RegExp(`${CONST.UNICODE.LTR}\\s*$`)]; +function canComposerBeConvertedToLTR(text: string): boolean { + // this handle cases when user type only spaces + const containOnlySpaces = /^\s*$/; + // this handle the case where someone has RTL enabled and they began typing an @mention for someone. + const startsWithLTRAndAt = new RegExp(`^${CONST.UNICODE.LTR}@$`); + // this handle cases could send empty messages when composer is multiline + const startsWithLTRAndSpace = new RegExp(`${CONST.UNICODE.LTR}\\s*$`); + const emptyExpressions = [containOnlySpaces, startsWithLTRAndAt, startsWithLTRAndSpace]; return emptyExpressions.some((exp) => exp.test(text)); } /** - * Android only - We should remove the LTR unicode when the input is empty to prevent: Sending an empty message, metion suggestions not works if @ or \s (at or space) is the first character; (force option: always remove the unicode, going to be used when composer is consider as empty) or placeholder not shows if unicode character is the only remaining character. */ + * Android only - We should remove the LTR unicode when the input is empty to prevent: + * Sending an empty message; + * Mention suggestions not works if @ or \s (at or space) is the first character; + * Placeholder is not displayed if the unicode character is the only character remaining; + * force: always remove the LTR unicode, going to be used when composer is consider as empty */ const resetLTRWhenEmpty = (newComment: string, force?: boolean) => { const result = newComment.length <= 1 || force ? newComment.replaceAll(CONST.UNICODE.LTR, '') : newComment; return result; @@ -22,7 +31,7 @@ const resetLTRWhenEmpty = (newComment: string, force?: boolean) => { * Android does not properly support bidirectional text for mixed content for input box */ const convertToLTRForComposer: ConvertToLTRForComposer = (text, isComposerEmpty) => { - const isConsideredAsEmpty = hasBeenComposerConsideredEmpty(text); + const isConsideredAsEmpty = canComposerBeConvertedToLTR(text); const newText = resetLTRWhenEmpty(text, isConsideredAsEmpty); if (isConsideredAsEmpty) { return newText; From 1735f5acd4727852cf33013f53d78f0cedbb97f8 Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Wed, 13 Dec 2023 14:30:12 -0400 Subject: [PATCH 12/16] Fixed comments and variables to better understanding --- src/libs/convertToLTRForComposer/index.android.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libs/convertToLTRForComposer/index.android.ts b/src/libs/convertToLTRForComposer/index.android.ts index 9a73e9c03982..855681a303c9 100644 --- a/src/libs/convertToLTRForComposer/index.android.ts +++ b/src/libs/convertToLTRForComposer/index.android.ts @@ -2,7 +2,7 @@ import CONST from '@src/CONST'; import ConvertToLTRForComposer from './types'; /** - * Android only - The composer is considered "empty" if all it contains is the LTR character followed by an @ or space. + * Android only - The composer can be converted to LTR if its content is the LTR character followed by an @ or space */ function canComposerBeConvertedToLTR(text: string): boolean { // this handle cases when user type only spaces @@ -31,9 +31,10 @@ const resetLTRWhenEmpty = (newComment: string, force?: boolean) => { * Android does not properly support bidirectional text for mixed content for input box */ const convertToLTRForComposer: ConvertToLTRForComposer = (text, isComposerEmpty) => { - const isConsideredAsEmpty = canComposerBeConvertedToLTR(text); - const newText = resetLTRWhenEmpty(text, isConsideredAsEmpty); - if (isConsideredAsEmpty) { + const shouldComposerMaintainAsLTR = canComposerBeConvertedToLTR(text); + console.log({shouldComposerMaintainAsLTR, isComposerEmpty}); + const newText = resetLTRWhenEmpty(text, shouldComposerMaintainAsLTR); + if (shouldComposerMaintainAsLTR) { return newText; } return isComposerEmpty ? `${CONST.UNICODE.LTR}${newText}` : newText; From e737dcbd5606de983e5b9a57b43c6cf1316fb32e Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Wed, 13 Dec 2023 14:30:26 -0400 Subject: [PATCH 13/16] Comments and variables changed to better understanding --- src/libs/convertToLTRForComposer/index.android.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/convertToLTRForComposer/index.android.ts b/src/libs/convertToLTRForComposer/index.android.ts index 855681a303c9..82d2f3d08429 100644 --- a/src/libs/convertToLTRForComposer/index.android.ts +++ b/src/libs/convertToLTRForComposer/index.android.ts @@ -32,7 +32,6 @@ const resetLTRWhenEmpty = (newComment: string, force?: boolean) => { */ const convertToLTRForComposer: ConvertToLTRForComposer = (text, isComposerEmpty) => { const shouldComposerMaintainAsLTR = canComposerBeConvertedToLTR(text); - console.log({shouldComposerMaintainAsLTR, isComposerEmpty}); const newText = resetLTRWhenEmpty(text, shouldComposerMaintainAsLTR); if (shouldComposerMaintainAsLTR) { return newText; From be6ee76ea6be51d243ac22ad4e2857b0fa7bd6b7 Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Wed, 13 Dec 2023 23:46:08 -0400 Subject: [PATCH 14/16] Fixed grammar in comments --- src/libs/convertToLTRForComposer/index.android.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/convertToLTRForComposer/index.android.ts b/src/libs/convertToLTRForComposer/index.android.ts index 82d2f3d08429..b9351d17d4f6 100644 --- a/src/libs/convertToLTRForComposer/index.android.ts +++ b/src/libs/convertToLTRForComposer/index.android.ts @@ -3,13 +3,15 @@ import ConvertToLTRForComposer from './types'; /** * Android only - The composer can be converted to LTR if its content is the LTR character followed by an @ or space + * because to mention sugggestion works the @ character must not have any character at the beginning e.g.: \u2066@ doesn't work + * also to avoid sending empty messages the unicode character with space could enable the send button. */ function canComposerBeConvertedToLTR(text: string): boolean { - // this handle cases when user type only spaces + // This regex handles the case when a user only types spaces into the composer const containOnlySpaces = /^\s*$/; - // this handle the case where someone has RTL enabled and they began typing an @mention for someone. + // This regex handles the case where someone has RTL enabled and they began typing an @mention for someone. const startsWithLTRAndAt = new RegExp(`^${CONST.UNICODE.LTR}@$`); - // this handle cases could send empty messages when composer is multiline + // This regex handles the case to avoid sending empty messages when composer is multiline const startsWithLTRAndSpace = new RegExp(`${CONST.UNICODE.LTR}\\s*$`); const emptyExpressions = [containOnlySpaces, startsWithLTRAndAt, startsWithLTRAndSpace]; return emptyExpressions.some((exp) => exp.test(text)); From 5be5dc0017b3f23596aa49b7c13d3b639cbe3599 Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Thu, 14 Dec 2023 10:39:56 -0400 Subject: [PATCH 15/16] Fixed comments grammar and using @param doc --- src/libs/convertToLTRForComposer/index.android.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/convertToLTRForComposer/index.android.ts b/src/libs/convertToLTRForComposer/index.android.ts index b9351d17d4f6..472cd8c74a83 100644 --- a/src/libs/convertToLTRForComposer/index.android.ts +++ b/src/libs/convertToLTRForComposer/index.android.ts @@ -7,11 +7,11 @@ import ConvertToLTRForComposer from './types'; * also to avoid sending empty messages the unicode character with space could enable the send button. */ function canComposerBeConvertedToLTR(text: string): boolean { - // This regex handles the case when a user only types spaces into the composer + // This regex handles the case when a user only types spaces into the composer. const containOnlySpaces = /^\s*$/; // This regex handles the case where someone has RTL enabled and they began typing an @mention for someone. const startsWithLTRAndAt = new RegExp(`^${CONST.UNICODE.LTR}@$`); - // This regex handles the case to avoid sending empty messages when composer is multiline + // This regex handles the case where the composer can contain multiple lines of whitespace const startsWithLTRAndSpace = new RegExp(`${CONST.UNICODE.LTR}\\s*$`); const emptyExpressions = [containOnlySpaces, startsWithLTRAndAt, startsWithLTRAndSpace]; return emptyExpressions.some((exp) => exp.test(text)); @@ -22,7 +22,9 @@ function canComposerBeConvertedToLTR(text: string): boolean { * Sending an empty message; * Mention suggestions not works if @ or \s (at or space) is the first character; * Placeholder is not displayed if the unicode character is the only character remaining; - * force: always remove the LTR unicode, going to be used when composer is consider as empty */ + * + * @newComment: the comment written by the user + * @force: always remove the LTR unicode, going to be used when composer is consider as empty */ const resetLTRWhenEmpty = (newComment: string, force?: boolean) => { const result = newComment.length <= 1 || force ? newComment.replaceAll(CONST.UNICODE.LTR, '') : newComment; return result; From 8a75507a130dcc1e1a86c84fec188dd5d761734c Mon Sep 17 00:00:00 2001 From: Samil Abud Date: Fri, 15 Dec 2023 13:43:48 -0400 Subject: [PATCH 16/16] Using jsdoc format for comments --- src/libs/convertToLTRForComposer/index.android.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/convertToLTRForComposer/index.android.ts b/src/libs/convertToLTRForComposer/index.android.ts index 472cd8c74a83..0d68baa80e3a 100644 --- a/src/libs/convertToLTRForComposer/index.android.ts +++ b/src/libs/convertToLTRForComposer/index.android.ts @@ -23,8 +23,11 @@ function canComposerBeConvertedToLTR(text: string): boolean { * Mention suggestions not works if @ or \s (at or space) is the first character; * Placeholder is not displayed if the unicode character is the only character remaining; * - * @newComment: the comment written by the user - * @force: always remove the LTR unicode, going to be used when composer is consider as empty */ + * @param {String} newComment - the comment written by the user + * @param {Boolean} force - always remove the LTR unicode, going to be used when composer is consider as empty + * @return {String} + */ + const resetLTRWhenEmpty = (newComment: string, force?: boolean) => { const result = newComment.length <= 1 || force ? newComment.replaceAll(CONST.UNICODE.LTR, '') : newComment; return result;