Skip to content

Revert "Simplify single line TextInput styling to allow for different heights" #55668

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

Closed
Closed
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
7 changes: 1 addition & 6 deletions src/components/TextInput/BaseTextInput/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,6 @@ function BaseTextInput(

const inputPaddingLeft = !!prefixCharacter && StyleUtils.getPaddingLeft(StyleUtils.getCharacterPadding(prefixCharacter) + styles.pl1.paddingLeft);
const inputPaddingRight = !!suffixCharacter && StyleUtils.getPaddingRight(StyleUtils.getCharacterPadding(suffixCharacter) + styles.pr1.paddingRight);

// Height fix is needed only for Text single line inputs
const shouldApplyHeight = !isMultiline && !isMarkdownEnabled;
return (
<>
<View style={[containerStyles]}>
Expand Down Expand Up @@ -356,9 +353,7 @@ function BaseTextInput(
inputPaddingRight,
inputProps.secureTextEntry && styles.secureInput,

// Explicitly remove `lineHeight` from single line inputs so that long text doesn't disappear
// once it exceeds the input space on iOS (See https://github.com/Expensify/App/issues/13802)
shouldApplyHeight && {height, lineHeight: undefined},
!isMultiline && {height, lineHeight: undefined},

// Stop scrollbar flashing when breaking lines with autoGrowHeight enabled.
...(autoGrowHeight && !isAutoGrowHeightMarkdown
Expand Down
38 changes: 32 additions & 6 deletions src/components/TextInput/BaseTextInput/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Str} from 'expensify-common';
import type {ForwardedRef, MutableRefObject} from 'react';
import React, {forwardRef, useCallback, useEffect, useRef, useState} from 'react';
import React, {forwardRef, useCallback, useEffect, useMemo, useRef, useState} from 'react';
import type {GestureResponderEvent, LayoutChangeEvent, NativeSyntheticEvent, StyleProp, TextInput, TextInputFocusEventData, ViewStyle} from 'react-native';
import {ActivityIndicator, StyleSheet, View} from 'react-native';
import {useSharedValue, withSpring} from 'react-native-reanimated';
Expand All @@ -24,8 +24,8 @@
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import {isMobileChrome, isMobileSafari, isSafari} from '@libs/Browser';
import {scrollToRight} from '@libs/InputUtils';
import * as Browser from '@libs/Browser';

Check failure on line 27 in src/components/TextInput/BaseTextInput/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import * as InputUtils from '@libs/InputUtils';

Check failure on line 28 in src/components/TextInput/BaseTextInput/index.tsx

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Namespace imports from @libs are not allowed. Use named imports instead. Example: import { method } from "@libs/module"
import isInputAutoFilled from '@libs/isInputAutoFilled';
import variables from '@styles/variables';
import CONST from '@src/CONST';
Expand Down Expand Up @@ -98,6 +98,7 @@
const [passwordHidden, setPasswordHidden] = useState(inputProps.secureTextEntry);
const [textInputWidth, setTextInputWidth] = useState(0);
const [textInputHeight, setTextInputHeight] = useState(0);
const [height, setHeight] = useState<number>(variables.componentSizeLarge);
const [width, setWidth] = useState<number | null>(null);

const labelScale = useSharedValue<number>(initialActiveLabel ? styleConst.ACTIVE_LABEL_SCALE : styleConst.INACTIVE_LABEL_SCALE);
Expand Down Expand Up @@ -186,6 +187,7 @@
const layout = event.nativeEvent.layout;

setWidth((prevWidth: number | null) => (autoGrowHeight ? layout.width : prevWidth));
setHeight((prevHeight: number) => (!multiline ? layout.height : prevHeight));
},
[autoGrowHeight, multiline],
);
Expand Down Expand Up @@ -261,6 +263,25 @@
]);
const isMultiline = multiline || autoGrowHeight;

/**
* To prevent text jumping caused by virtual DOM calculations on Safari and mobile Chrome,
* make sure to include the `lineHeight`.
* Reference: https://github.com/Expensify/App/issues/26735
* For other platforms, explicitly remove `lineHeight` from single-line inputs
* to prevent long text from disappearing once it exceeds the input space.
* See https://github.com/Expensify/App/issues/13802
*/
const lineHeight = useMemo(() => {
if (Browser.isSafari() || Browser.isMobileChrome()) {
const lineHeightValue = StyleSheet.flatten(inputStyle).lineHeight;
if (lineHeightValue !== undefined) {
return lineHeightValue;
}
}

return undefined;
}, [inputStyle]);

const inputPaddingLeft = !!prefixCharacter && StyleUtils.getPaddingLeft(StyleUtils.getCharacterPadding(prefixCharacter) + styles.pl1.paddingLeft);
const inputPaddingRight = !!suffixCharacter && StyleUtils.getPaddingRight(StyleUtils.getCharacterPadding(suffixCharacter) + styles.pr1.paddingRight);

Expand Down Expand Up @@ -309,6 +330,7 @@
/>
</>
) : 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 @@ -358,11 +380,15 @@
inputPaddingRight,
inputProps.secureTextEntry && styles.secureInput,

// Explicitly remove `lineHeight` from single line inputs so that long text doesn't disappear
// once it exceeds the input space (See https://github.com/Expensify/App/issues/13802)
!isMultiline && {height, lineHeight},

// Explicitly change boxSizing attribute for mobile chrome in order to apply line-height
// for the issue mentioned here https://github.com/Expensify/App/issues/26735
// Set overflow property to enable the parent flexbox to shrink its size
// (See https://github.com/Expensify/App/issues/41766)
!isMultiline && isMobileChrome() && {boxSizing: 'content-box', height: undefined, ...styles.overflowAuto},
!isMultiline && Browser.isMobileChrome() && {boxSizing: 'content-box', height: undefined, ...styles.overflowAuto},

// Stop scrollbar flashing when breaking lines with autoGrowHeight enabled.
...(autoGrowHeight && !isAutoGrowHeightMarkdown
Expand Down Expand Up @@ -405,7 +431,7 @@
if (didScrollToEndRef.current || !input.current) {
return;
}
scrollToRight(input.current);
InputUtils.scrollToRight(input.current);
didScrollToEndRef.current = true;
}}
>
Expand Down Expand Up @@ -498,7 +524,7 @@
return;
}
let additionalWidth = 0;
if (isMobileSafari() || isSafari() || isMobileChrome()) {
if (Browser.isMobileSafari() || Browser.isSafari() || Browser.isMobileChrome()) {
additionalWidth = 2;
}
setTextInputWidth(e.nativeEvent.layout.width + additionalWidth);
Expand Down
3 changes: 2 additions & 1 deletion src/styles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1247,11 +1247,12 @@ const styles = (theme: ThemeColors) =>
},

textInputMultilineContainer: {
height: '100%',
paddingTop: 23,
},

textInputAndIconContainer: {
flex: 1,
height: '100%',
zIndex: -1,
flexDirection: 'row',
},
Expand Down
Loading