Skip to content

Commit

Permalink
Fix composer font height being smaller on first render
Browse files Browse the repository at this point in the history
For emojis only text.
  • Loading branch information
CyberAndrii committed Jan 17, 2025
1 parent d50b5ae commit 781eb78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
9 changes: 3 additions & 6 deletions src/components/Composer/implementation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import * as Browser from '@libs/Browser';
import * as EmojiUtils from '@libs/EmojiUtils';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import isEnterWhileComposition from '@libs/KeyboardShortcut/isEnterWhileComposition';
import variables from '@styles/variables';
import CONST from '@src/CONST';

const excludeNoStyles: Array<keyof MarkdownStyle> = [];
Expand Down Expand Up @@ -73,7 +72,6 @@ function Composer(
start: selectionProp.start,
end: selectionProp.end,
});
const [hasMultipleLines, setHasMultipleLines] = useState(false);
const [isRendered, setIsRendered] = useState(false);

// On mobile safari, the cursor will move from right to left with inputMode set to none during report transition
Expand Down Expand Up @@ -343,15 +341,15 @@ function Composer(
const inputStyleMemo = useMemo(
() => [
StyleSheet.flatten([style, {outline: 'none'}]),
StyleUtils.getComposeTextAreaPadding(isComposerFullSize),
StyleUtils.getComposeTextAreaPadding(isComposerFullSize, textContainsOnlyEmojis),
Browser.isMobileSafari() || Browser.isSafari() ? styles.rtlTextRenderForSafari : {},
scrollStyleMemo,
StyleUtils.getComposerMaxHeightStyle(maxLines, isComposerFullSize),
isComposerFullSize ? {height: '100%', maxHeight: 'none'} : undefined,
textContainsOnlyEmojis && hasMultipleLines ? styles.onlyEmojisTextLineHeight : {},
textContainsOnlyEmojis ? styles.onlyEmojisTextLineHeight : {},
],

[style, styles.rtlTextRenderForSafari, styles.onlyEmojisTextLineHeight, scrollStyleMemo, hasMultipleLines, StyleUtils, maxLines, isComposerFullSize, textContainsOnlyEmojis],
[style, styles.rtlTextRenderForSafari, styles.onlyEmojisTextLineHeight, scrollStyleMemo, StyleUtils, maxLines, isComposerFullSize, textContainsOnlyEmojis],
);

return (
Expand All @@ -373,7 +371,6 @@ function Composer(
onSelectionChange={addCursorPositionToSelectionChange}
onContentSizeChange={(e) => {
setPrevHeight(e.nativeEvent.contentSize.height);
setHasMultipleLines(e.nativeEvent.contentSize.height > variables.componentSizeLarge);
}}
disabled={isDisabled}
onKeyPress={handleKeyPress}
Expand Down
19 changes: 11 additions & 8 deletions src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,18 +953,21 @@ function getEmojiPickerListHeight(isRenderingShortcutRow: boolean, windowHeight:
}

/**
* Returns padding vertical based on number of lines
* Returns vertical padding based on number of lines.
*/
function getComposeTextAreaPadding(isComposerFullSize: boolean): TextStyle {
let paddingValue = 5;
function getComposeTextAreaPadding(isComposerFullSize: boolean, textContainsOnlyEmojis: boolean): TextStyle {
let paddingTop = 8;
let paddingBottom = 8;
// Issue #26222: If isComposerFullSize paddingValue will always be 5 to prevent padding jumps when adding multiple lines.
if (!isComposerFullSize) {
paddingValue = 8;
paddingTop = 8;
paddingBottom = 8;
}
return {
paddingTop: paddingValue,
paddingBottom: paddingValue,
};
// We need to reduce the top padding because emojis have a bigger font height.
if (textContainsOnlyEmojis) {
paddingTop = 3;
}
return {paddingTop, paddingBottom};
}

/**
Expand Down

0 comments on commit 781eb78

Please sign in to comment.