Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Android - Chat - Message gets displayed from right to left #32297

Merged
Merged
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -105,6 +106,7 @@ function ComposerWithSuggestions({
const styles = useThemeStyles();
const {preferredLocale} = useLocalize();
const isFocused = useIsFocused();
const [firstChange, setFirstChange] = useState(true);
samilabud marked this conversation as resolved.
Show resolved Hide resolved
const navigation = useNavigation();
const emojisPresentBefore = useRef([]);
const [value, setValue] = useState(() => {
Expand Down Expand Up @@ -220,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)) {
samilabud marked this conversation as resolved.
Show resolved Hide resolved
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);
samilabud marked this conversation as resolved.
Show resolved Hide resolved
}
}

emojisPresentBefore.current = emojis;
setValue(newCommentConverted);

if (commentValue !== newComment) {
const position = Math.max(selection.end + (newComment.length - commentRef.current.length), cursorPosition || 0);
setSelection({
Expand Down Expand Up @@ -268,6 +296,7 @@ function ComposerWithSuggestions({
raiseIsScrollLikelyLayoutTriggered,
debouncedSaveReportComment,
selection.end,
firstChange,
],
);

Expand Down
Loading