Skip to content

Commit

Permalink
Merge pull request #49896 from tsa321/baseTextInputMarkdown
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpersaud authored Oct 11, 2024
2 parents d7f3c5c + bed7eea commit 4c90d62
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
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 @@ -72,6 +72,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 @@ -274,7 +275,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 ? [StyleUtils.getMarkdownMaxHeight(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 @@ -78,6 +78,7 @@ function BaseTextInput(
ref: ForwardedRef<BaseTextInputRef>,
) {
const InputComponent = isMarkdownEnabled ? RNMarkdownTextInput : RNTextInput;
const isAutoGrowHeightMarkdown = isMarkdownEnabled && autoGrowHeight;

const theme = useTheme();
const styles = useThemeStyles();
Expand All @@ -97,6 +98,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 @@ -300,7 +302,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 @@ -326,6 +331,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 @@ -386,10 +392,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 ? [StyleUtils.getMarkdownMaxHeight(maxAutoGrowHeight), styles.verticalAlignTop] : undefined,
// Add disabled color theme when field is not editable.
inputProps.disabled && shouldUseDisabledStyles && styles.textInputDisabled,
styles.pointerEventsAuto,
Expand Down Expand Up @@ -490,7 +496,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
1 change: 1 addition & 0 deletions src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ const styles = (theme: ThemeColors) =>
overflow: 'hidden',
borderBottomWidth: 2,
borderColor: theme.border,
paddingBottom: 8,
},

optionRowAmountInput: {
Expand Down
9 changes: 9 additions & 0 deletions src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1250,6 +1250,15 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({
};
},

/*
* Returns the actual maxHeight of the auto-growing markdown text input.
*/
getMarkdownMaxHeight: (maxAutoGrowHeight: number | undefined): TextStyle => {
// maxHeight is not of the input only but the of the whole input container
// which also includes the top padding and bottom border
return maxAutoGrowHeight ? {maxHeight: maxAutoGrowHeight - styles.textInputMultilineContainer.paddingTop - styles.textInputContainer.borderBottomWidth} : {};
},

/**
* Return the style from an avatar size constant
*/
Expand Down

0 comments on commit 4c90d62

Please sign in to comment.