-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Fixed Android - Chat - Message gets displayed from right to l…
…eft"
- Loading branch information
1 parent
9e81447
commit f3673e4
Showing
6 changed files
with
18 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
/** | ||
* Android only - convert RTL text to a LTR text using 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'; | ||
|
||
/** | ||
* Android only - convert RTL text to a LTR text using Unicode controls. | ||
* https://www.w3.org/International/questions/qa-bidi-unicode-controls | ||
*/ | ||
const convertToLTR: ConvertToLTR = (text) => `${CONST.UNICODE.LTR}${text}`; | ||
|
||
export default convertToLTR; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,8 @@ | ||
import CONST from '@src/CONST'; | ||
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 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 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)); | ||
} | ||
|
||
/** | ||
* 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; | ||
* | ||
* @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; | ||
}; | ||
|
||
/** | ||
* 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) => { | ||
const shouldComposerMaintainAsLTR = canComposerBeConvertedToLTR(text); | ||
const newText = resetLTRWhenEmpty(text, shouldComposerMaintainAsLTR); | ||
if (shouldComposerMaintainAsLTR) { | ||
return newText; | ||
} | ||
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}; | ||
|
||
const convertToLTRForComposer: ConvertToLTRForComposer = (text) => text; | ||
export default convertToLTRForComposer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
type ConvertToLTRForComposer = (text: string, isComposerEmpty?: boolean) => string; | ||
type ConvertToLTRForComposer = (text: string) => string; | ||
|
||
export default ConvertToLTRForComposer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters