Skip to content

Commit

Permalink
Merge pull request #28126 from ayazalavi/ayaz/safari_line_height_issue
Browse files Browse the repository at this point in the history
added browser check for setting line height
  • Loading branch information
arosiclair authored Sep 26, 2023
2 parents f2a9e9f + 63a6d3b commit 30f675d
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 30f675d

Please sign in to comment.