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 auto grow of base text input using markdown component #49896

Merged
merged 9 commits into from
Oct 11, 2024
11 changes: 8 additions & 3 deletions src/components/TextInput/BaseTextInput/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function BaseTextInput(
ref: ForwardedRef<BaseTextInputRef>,
) {
const InputComponent = isMarkdownEnabled ? RNMarkdownTextInput : RNTextInput;
const isAutoGrowHeightMarkdown = isMarkdownEnabled && autoGrowHeight;

const inputProps = {shouldSaveDraft: false, shouldUseDefaultValue: false, ...props};
const theme = useTheme();
Expand Down Expand Up @@ -273,7 +274,10 @@ function BaseTextInput(
onLayout={onLayout}
accessibilityLabel={label}
style={[
autoGrowHeight && styles.autoGrowHeightInputContainer(textInputHeight, variables.componentSizeLarge, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : 0),
autoGrowHeight &&
!isAutoGrowHeightMarkdown &&
styles.autoGrowHeightInputContainer(textInputHeight, variables.componentSizeLarge, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : 0),
isAutoGrowHeightMarkdown && {minHeight: variables.componentSizeLarge},
!isMultiline && styles.componentHeightLarge,
touchableInputWrapperStyle,
]}
Expand Down Expand Up @@ -351,9 +355,10 @@ function BaseTextInput(
!isMultiline && {height, lineHeight: undefined},

// Stop scrollbar flashing when breaking lines with autoGrowHeight enabled.
...(autoGrowHeight
...(autoGrowHeight && !isAutoGrowHeightMarkdown
? [StyleUtils.getAutoGrowHeightInputStyle(textInputHeight, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : 0), styles.verticalAlignTop]
: []),
isAutoGrowHeightMarkdown ? [{maxHeight: maxAutoGrowHeight}, styles.verticalAlignTop] : undefined,
// Add disabled color theme when field is not editable.
inputProps.disabled && styles.textInputDisabled,
styles.pointerEventsAuto,
Expand Down Expand Up @@ -444,7 +449,7 @@ function BaseTextInput(
This text view is used to calculate width or height of the input value given textStyle in this component.
This Text component is intentionally positioned out of the screen.
*/}
{(!!autoGrow || autoGrowHeight) && (
{(!!autoGrow || autoGrowHeight) && !isAutoGrowHeightMarkdown && (
// Add +2 to width on Safari browsers so that text is not cut off due to the cursor or when changing the value
// https://github.com/Expensify/App/issues/8158
// https://github.com/Expensify/App/issues/26628
Expand Down
14 changes: 10 additions & 4 deletions src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function BaseTextInput(
ref: ForwardedRef<BaseTextInputRef>,
) {
const InputComponent = isMarkdownEnabled ? RNMarkdownTextInput : RNTextInput;
const isAutoGrowHeightMarkdown = isMarkdownEnabled && autoGrowHeight;

const theme = useTheme();
const styles = useThemeStyles();
Expand All @@ -95,6 +96,7 @@ function BaseTextInput(
const [textInputHeight, setTextInputHeight] = useState(0);
const [height, setHeight] = useState<number>(variables.componentSizeLarge);
const [width, setWidth] = useState<number | null>(null);

const labelScale = useRef(new Animated.Value(initialActiveLabel ? styleConst.ACTIVE_LABEL_SCALE : styleConst.INACTIVE_LABEL_SCALE)).current;
const labelTranslateY = useRef(new Animated.Value(initialActiveLabel ? styleConst.ACTIVE_LABEL_TRANSLATE_Y : styleConst.INACTIVE_LABEL_TRANSLATE_Y)).current;
const input = useRef<HTMLInputElement | null>(null);
Expand Down Expand Up @@ -298,7 +300,10 @@ function BaseTextInput(
// or if multiline is not supplied we calculate the textinput height, using onLayout.
onLayout={onLayout}
style={[
autoGrowHeight && styles.autoGrowHeightInputContainer(textInputHeight, variables.componentSizeLarge, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : 0),
autoGrowHeight &&
!isAutoGrowHeightMarkdown &&
styles.autoGrowHeightInputContainer(textInputHeight, variables.componentSizeLarge, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : 0),
isAutoGrowHeightMarkdown && {minHeight: variables.componentSizeLarge},
!isMultiline && styles.componentHeightLarge,
touchableInputWrapperStyle,
]}
Expand All @@ -325,6 +330,7 @@ function BaseTextInput(
/>
</>
) : null}

<View style={[styles.textInputAndIconContainer, isMultiline && hasLabel && styles.textInputMultilineContainer, styles.pointerEventsBoxNone]}>
{iconLeft && (
<View style={[styles.textInputLeftIconContainer, !isReadOnly ? styles.cursorPointer : styles.pointerEventsNone]}>
Expand Down Expand Up @@ -385,10 +391,10 @@ function BaseTextInput(
!isMultiline && Browser.isMobileChrome() && {boxSizing: 'content-box', height: undefined, ...styles.overflowAuto},

// Stop scrollbar flashing when breaking lines with autoGrowHeight enabled.
...(autoGrowHeight
...(autoGrowHeight && !isAutoGrowHeightMarkdown
? [StyleUtils.getAutoGrowHeightInputStyle(textInputHeight, typeof maxAutoGrowHeight === 'number' ? maxAutoGrowHeight : 0), styles.verticalAlignTop]
: []),

isAutoGrowHeightMarkdown ? [{maxHeight: maxAutoGrowHeight}, styles.verticalAlignTop] : undefined,
// Add disabled color theme when field is not editable.
inputProps.disabled && styles.textInputDisabled,
styles.pointerEventsAuto,
Expand Down Expand Up @@ -489,7 +495,7 @@ function BaseTextInput(
This text view is used to calculate width or height of the input value given textStyle in this component.
This Text component is intentionally positioned out of the screen.
*/}
{(!!autoGrow || autoGrowHeight) && (
{(!!autoGrow || autoGrowHeight) && !isAutoGrowHeightMarkdown && (
// Add +2 to width on Safari browsers so that text is not cut off due to the cursor or when changing the value
// Reference: https://github.com/Expensify/App/issues/8158, https://github.com/Expensify/App/issues/26628
// For mobile Chrome, ensure proper display of the text selection handle (blue bubble down).
Expand Down
2 changes: 1 addition & 1 deletion src/pages/PrivateNotes/PrivateNotesEditPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function PrivateNotesEditPage({route, personalDetailsList, report, session}: Pri
maxLength={CONST.MAX_COMMENT_LENGTH}
autoCorrect={false}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
maxAutoGrowHeight={variables.markdownTextInputAutoGrowMaxHeight}
defaultValue={privateNote}
value={privateNote}
onChangeText={(text: string) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/RoomDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function RoomDescriptionPage({report, policies}: RoomDescriptionPageProps) {
accessibilityLabel={translate('reportDescriptionPage.roomDescription')}
role={CONST.ROLE.PRESENTATION}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
maxAutoGrowHeight={variables.markdownTextInputAutoGrowMaxHeight}
maxLength={CONST.REPORT_DESCRIPTION.MAX_LENGTH}
ref={(el: BaseTextInputRef | null): void => {
if (!el) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/iou/request/step/IOURequestStepDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function IOURequestStepDescription({
inputRef.current = el;
}}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
maxAutoGrowHeight={variables.markdownTextInputAutoGrowMaxHeight}
shouldSubmitForm
isMarkdownEnabled
excludedMarkdownStyles={!isReportInGroupPolicy ? ['mentionReport'] : []}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tasks/NewTaskDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function NewTaskDescriptionPage({task, route}: NewTaskDescriptionPageProps) {
inputCallbackRef(el);
}}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
maxAutoGrowHeight={variables.markdownTextInputAutoGrowMaxHeight}
shouldSubmitForm
isMarkdownEnabled
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tasks/NewTaskDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function NewTaskDetailsPage({task, route}: NewTaskDetailsPageProps) {
label={translate('newTaskPage.descriptionOptional')}
accessibilityLabel={translate('newTaskPage.descriptionOptional')}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
maxAutoGrowHeight={variables.markdownTextInputAutoGrowMaxHeight}
shouldSubmitForm
defaultValue={Parser.htmlToMarkdown(Parser.replace(taskDescription))}
value={taskDescription}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tasks/TaskDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function TaskDescriptionPage({report, currentUserPersonalDetails}: TaskDescripti
inputRef.current = element;
}}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
maxAutoGrowHeight={variables.markdownTextInputAutoGrowMaxHeight}
shouldSubmitForm
isMarkdownEnabled
/>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceNewRoomPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function WorkspaceNewRoomPage({policies, reports, formState, session, activePoli
accessibilityLabel={translate('reportDescriptionPage.roomDescriptionOptional')}
role={CONST.ROLE.PRESENTATION}
autoGrowHeight
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
maxAutoGrowHeight={variables.markdownTextInputAutoGrowMaxHeight}
maxLength={CONST.REPORT_DESCRIPTION.MAX_LENGTH}
autoCapitalize="none"
shouldInterceptSwipe
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceProfileDescriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function WorkspaceProfileDescriptionPage({policy}: Props) {
inputID="description"
label={translate('workspace.editor.descriptionInputLabel')}
accessibilityLabel={translate('workspace.editor.descriptionInputLabel')}
maxAutoGrowHeight={variables.textInputAutoGrowMaxHeight}
maxAutoGrowHeight={variables.markdownTextInputAutoGrowMaxHeight}
value={description}
maxLength={CONST.REPORT_DESCRIPTION.MAX_LENGTH}
spellCheck={false}
Expand Down
1 change: 1 addition & 0 deletions src/styles/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export default {
mushroomTopHatHeight: 128,
bankButtonMargin: 23,
textInputAutoGrowMaxHeight: 115,
markdownTextInputAutoGrowMaxHeight: 90,
tsa321 marked this conversation as resolved.
Show resolved Hide resolved
eReceiptBackgroundImageMinWidth: 217,

searchTypeColumnWidth: 52,
Expand Down
Loading