Skip to content

Commit 0131ea7

Browse files
committed
Simplify single line TextInput styling to allow for different heights
1 parent 5133090 commit 0131ea7

File tree

3 files changed

+8
-30
lines changed

3 files changed

+8
-30
lines changed

src/components/TextInput/BaseTextInput/index.native.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ function BaseTextInput(
266266

267267
const inputPaddingLeft = !!prefixCharacter && StyleUtils.getPaddingLeft(StyleUtils.getCharacterPadding(prefixCharacter) + styles.pl1.paddingLeft);
268268
const inputPaddingRight = !!suffixCharacter && StyleUtils.getPaddingRight(StyleUtils.getCharacterPadding(suffixCharacter) + styles.pr1.paddingRight);
269+
270+
// Height fix is needed only for Text single line inputs
271+
const shouldApplyHeight = !isMultiline && !isMarkdownEnabled;
269272
return (
270273
<>
271274
<View style={[containerStyles]}>
@@ -349,14 +352,17 @@ function BaseTextInput(
349352
underlineColorAndroid="transparent"
350353
style={[
351354
styles.flex1,
355+
styles.flexRow,
352356
styles.w100,
353357
inputStyle,
354358
(!hasLabel || isMultiline) && styles.pv0,
355359
inputPaddingLeft,
356360
inputPaddingRight,
357361
inputProps.secureTextEntry && styles.secureInput,
358362

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

361367
// Stop scrollbar flashing when breaking lines with autoGrowHeight enabled.
362368
...(autoGrowHeight && !isAutoGrowHeightMarkdown

src/components/TextInput/BaseTextInput/index.tsx

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Str} from 'expensify-common';
22
import type {ForwardedRef, MutableRefObject} from 'react';
3-
import React, {forwardRef, useCallback, useEffect, useMemo, useRef, useState} from 'react';
3+
import React, {forwardRef, useCallback, useEffect, useRef, useState} from 'react';
44
import type {GestureResponderEvent, LayoutChangeEvent, NativeSyntheticEvent, StyleProp, TextInput, TextInputFocusEventData, ViewStyle} from 'react-native';
55
import {ActivityIndicator, StyleSheet, View} from 'react-native';
66
import {useSharedValue, withSpring} from 'react-native-reanimated';
@@ -98,7 +98,6 @@ function BaseTextInput(
9898
const [passwordHidden, setPasswordHidden] = useState(inputProps.secureTextEntry);
9999
const [textInputWidth, setTextInputWidth] = useState(0);
100100
const [textInputHeight, setTextInputHeight] = useState(0);
101-
const [height, setHeight] = useState<number>(variables.componentSizeLarge);
102101
const [width, setWidth] = useState<number | null>(null);
103102

104103
const labelScale = useSharedValue<number>(initialActiveLabel ? styleConst.ACTIVE_LABEL_SCALE : styleConst.INACTIVE_LABEL_SCALE);
@@ -187,7 +186,6 @@ function BaseTextInput(
187186
const layout = event.nativeEvent.layout;
188187

189188
setWidth((prevWidth: number | null) => (autoGrowHeight ? layout.width : prevWidth));
190-
setHeight((prevHeight: number) => (!multiline ? layout.height : prevHeight));
191189
},
192190
[autoGrowHeight, multiline],
193191
);
@@ -263,25 +261,6 @@ function BaseTextInput(
263261
]);
264262
const isMultiline = multiline || autoGrowHeight;
265263

266-
/**
267-
* To prevent text jumping caused by virtual DOM calculations on Safari and mobile Chrome,
268-
* make sure to include the `lineHeight`.
269-
* Reference: https://github.com/Expensify/App/issues/26735
270-
* For other platforms, explicitly remove `lineHeight` from single-line inputs
271-
* to prevent long text from disappearing once it exceeds the input space.
272-
* See https://github.com/Expensify/App/issues/13802
273-
*/
274-
const lineHeight = useMemo(() => {
275-
if (Browser.isSafari() || Browser.isMobileChrome()) {
276-
const lineHeightValue = StyleSheet.flatten(inputStyle).lineHeight;
277-
if (lineHeightValue !== undefined) {
278-
return lineHeightValue;
279-
}
280-
}
281-
282-
return undefined;
283-
}, [inputStyle]);
284-
285264
const inputPaddingLeft = !!prefixCharacter && StyleUtils.getPaddingLeft(StyleUtils.getCharacterPadding(prefixCharacter) + styles.pl1.paddingLeft);
286265
const inputPaddingRight = !!suffixCharacter && StyleUtils.getPaddingRight(StyleUtils.getCharacterPadding(suffixCharacter) + styles.pr1.paddingRight);
287266

@@ -330,7 +309,6 @@ function BaseTextInput(
330309
/>
331310
</>
332311
) : null}
333-
334312
<View style={[styles.textInputAndIconContainer, isMultiline && hasLabel && styles.textInputMultilineContainer, styles.pointerEventsBoxNone]}>
335313
{!!iconLeft && (
336314
<View style={[styles.textInputLeftIconContainer, !isReadOnly ? styles.cursorPointer : styles.pointerEventsNone]}>
@@ -380,10 +358,6 @@ function BaseTextInput(
380358
inputPaddingRight,
381359
inputProps.secureTextEntry && styles.secureInput,
382360

383-
// Explicitly remove `lineHeight` from single line inputs so that long text doesn't disappear
384-
// once it exceeds the input space (See https://github.com/Expensify/App/issues/13802)
385-
!isMultiline && {height, lineHeight},
386-
387361
// Explicitly change boxSizing attribute for mobile chrome in order to apply line-height
388362
// for the issue mentioned here https://github.com/Expensify/App/issues/26735
389363
// Set overflow property to enable the parent flexbox to shrink its size

src/styles/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,8 +1247,6 @@ const styles = (theme: ThemeColors) =>
12471247
},
12481248

12491249
textInputAndIconContainer: {
1250-
flex: 1,
1251-
height: '100%',
12521250
zIndex: -1,
12531251
flexDirection: 'row',
12541252
},

0 commit comments

Comments
 (0)