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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 16 additions & 13 deletions src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type {OnyxEntry} from 'react-native-onyx';
import type {EdgeInsets} from 'react-native-safe-area-context';
import type {ValueOf} from 'type-fest';
import type ImageSVGProps from '@components/ImageSVG/types';
import * as Browser from '@libs/Browser';
import {isMobile} from '@libs/Browser';
import getPlatform from '@libs/getPlatform';
import * as UserUtils from '@libs/UserUtils';
import {hashText} from '@libs/UserUtils';
// eslint-disable-next-line no-restricted-imports
import {defaultTheme} from '@styles/theme';
import colors from '@styles/theme/colors';
Expand Down Expand Up @@ -275,7 +275,7 @@ function getAvatarBorderStyle(size: AvatarSizeName, type: string): ViewStyle {
* Helper method to return workspace avatar color styles
*/
function getDefaultWorkspaceAvatarColor(text: string): ViewStyle {
const colorHash = UserUtils.hashText(text.trim(), workspaceColorOptions.length);
const colorHash = hashText(text.trim(), workspaceColorOptions.length);
return workspaceColorOptions.at(colorHash) ?? {backgroundColor: colors.blue200, fill: colors.blue700};
}

Expand All @@ -296,7 +296,7 @@ function getEReceiptColorCode(transaction: OnyxEntry<Transaction>): EReceiptColo
return CONST.ERECEIPT_COLORS.YELLOW;
}

const colorHash = UserUtils.hashText(transactionID.trim(), eReceiptColors.length);
const colorHash = hashText(transactionID.trim(), eReceiptColors.length);

return eReceiptColors.at(colorHash) ?? CONST.ERECEIPT_COLORS.YELLOW;
}
Expand Down Expand Up @@ -953,25 +953,28 @@ 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};
}

/**
* Returns style object for the mobile on WEB
*/
function getOuterModalStyle(windowHeight: number, viewportOffsetTop: number): ViewStyle {
return Browser.isMobile() ? {maxHeight: windowHeight, marginTop: viewportOffsetTop} : {};
return isMobile() ? {maxHeight: windowHeight, marginTop: viewportOffsetTop} : {};
}

/**
Expand Down
Loading