Skip to content

Commit

Permalink
added browser check for setting line height
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazalavi committed Sep 25, 2023
1 parent f0c9bbe commit 6545a81
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/components/TextInput/BaseTextInput.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _ from 'underscore';
import React, {useState, useRef, useEffect, useCallback} from 'react';
import React, {useState, useRef, useEffect, useCallback, useMemo} from 'react';
import {Animated, View, StyleSheet} from 'react-native';
import Str from 'expensify-common/lib/str';
import RNTextInput from '../RNTextInput';
Expand Down Expand Up @@ -236,6 +236,25 @@ function BaseTextInput(props) {
]);
const isMultiline = props.multiline || props.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() && _.isArray(props.inputStyle)) {
const lineHeightValue = _.find(props.inputStyle, (f) => f.lineHeight !== undefined)
if(lineHeightValue) {
return lineHeightValue.lineHeight
}
} else if (Browser.isSafari() || Browser.isMobileChrome()) {
return height;
}
return undefined;
}, [props.inputStyle, height])

return (
<>
<View style={styles.pointerEventsNone}>
Expand Down Expand Up @@ -321,7 +340,7 @@ function BaseTextInput(props) {

// 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: undefined},
!isMultiline && {height, lineHeight},

// Stop scrollbar flashing when breaking lines with autoGrowHeight enabled.
props.autoGrowHeight && StyleUtils.getAutoGrowHeightInputStyle(textInputHeight, maxHeight),
Expand Down

0 comments on commit 6545a81

Please sign in to comment.