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

Fix composer font height being smaller on first render #55438

Merged
Show file tree
Hide file tree
Changes from all 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
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 {isMobileSafari, isSafari} from '@libs/Browser';
import {containsOnlyEmojis} from '@libs/EmojiUtils';
import {base64ToFile} 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 @@ -349,15 +347,15 @@ function Composer(
const inputStyleMemo = useMemo(
() => [
StyleSheet.flatten([style, {outline: 'none'}]),
StyleUtils.getComposeTextAreaPadding(isComposerFullSize),
StyleUtils.getComposeTextAreaPadding(isComposerFullSize, textContainsOnlyEmojis),
isMobileSafari() || 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 @@ -379,7 +377,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 @@ -944,18 +944,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