Skip to content

Commit 2389457

Browse files
Merge pull request #54189 from QichenZhu/fix/53286-2nd-try
Fix IOU amount input flicking on native platforms
2 parents 704008d + 21056ff commit 2389457

File tree

7 files changed

+25
-9
lines changed

7 files changed

+25
-9
lines changed

src/components/AmountTextInput.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type AmountTextInputProps = {
3939

4040
/** Hide the focus styles on TextInput */
4141
hideFocusedState?: boolean;
42-
} & Pick<BaseTextInputProps, 'autoFocus'>;
42+
} & Pick<BaseTextInputProps, 'autoFocus' | 'autoGrowExtraSpace'>;
4343

4444
function AmountTextInput(
4545
{

src/components/MoneyRequestAmountInput.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import CONST from '@src/CONST';
1212
import isTextInputFocused from './TextInput/BaseTextInput/isTextInputFocused';
1313
import type {BaseTextInputRef} from './TextInput/BaseTextInput/types';
1414
import TextInputWithCurrencySymbol from './TextInputWithCurrencySymbol';
15+
import type {TextInputWithCurrencySymbolProps} from './TextInputWithCurrencySymbol/types';
1516

1617
type CurrentMoney = {amount: string; currency: string};
1718

@@ -91,7 +92,7 @@ type MoneyRequestAmountInputProps = {
9192

9293
/** The width of inner content */
9394
contentWidth?: number;
94-
};
95+
} & Pick<TextInputWithCurrencySymbolProps, 'autoGrowExtraSpace'>;
9596

9697
type Selection = {
9798
start: number;
@@ -126,6 +127,7 @@ function MoneyRequestAmountInput(
126127
hideFocusedState = true,
127128
shouldKeepUserInput = false,
128129
autoGrow = true,
130+
autoGrowExtraSpace,
129131
contentWidth,
130132
...props
131133
}: MoneyRequestAmountInputProps,
@@ -289,6 +291,7 @@ function MoneyRequestAmountInput(
289291
return (
290292
<TextInputWithCurrencySymbol
291293
autoGrow={autoGrow}
294+
autoGrowExtraSpace={autoGrowExtraSpace}
292295
disableKeyboard={disableKeyboard}
293296
formattedAmount={formattedAmount}
294297
onChangeAmount={setNewAmount}

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ function BaseTextInput(
5050
autoFocus = false,
5151
disableKeyboard = false,
5252
autoGrow = false,
53+
autoGrowExtraSpace = 0,
5354
autoGrowHeight = false,
5455
maxAutoGrowHeight,
5556
hideFocusedState = false,
@@ -253,7 +254,8 @@ function BaseTextInput(
253254
const newTextInputContainerStyles: StyleProp<ViewStyle> = StyleSheet.flatten([
254255
styles.textInputContainer,
255256
textInputContainerStyles,
256-
(autoGrow || !!contentWidth) && StyleUtils.getWidthStyle(textInputWidth),
257+
!!contentWidth && StyleUtils.getWidthStyle(textInputWidth),
258+
autoGrow && StyleUtils.getAutoGrowWidthInputContainerStyles(textInputWidth, autoGrowExtraSpace),
257259
!hideFocusedState && isFocused && styles.borderColorFocus,
258260
(!!hasError || !!errorText) && styles.borderColorDanger,
259261
autoGrowHeight && {scrollPaddingTop: typeof maxAutoGrowHeight === 'number' ? 2 * maxAutoGrowHeight : undefined},
@@ -444,14 +446,10 @@ function BaseTextInput(
444446
)}
445447
{/*
446448
Text input component doesn't support auto grow by default.
447-
We're using a hidden text input to achieve that.
448449
This text view is used to calculate width or height of the input value given textStyle in this component.
449450
This Text component is intentionally positioned out of the screen.
450451
*/}
451452
{(!!autoGrow || autoGrowHeight) && !isAutoGrowHeightMarkdown && (
452-
// Add +2 to width on Safari browsers so that text is not cut off due to the cursor or when changing the value
453-
// https://github.com/Expensify/App/issues/8158
454-
// https://github.com/Expensify/App/issues/26628
455453
<Text
456454
style={[
457455
inputStyle,

src/components/TextInput/BaseTextInput/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ type CustomBaseTextInputProps = {
5454
*/
5555
autoGrow?: boolean;
5656

57+
/** If autoGrow is enabled, this reserves extra space for incoming characters to prevent flickering on native platforms. */
58+
autoGrowExtraSpace?: number;
59+
5760
/**
5861
* Autogrow input container height based on the entered text
5962
*/

src/components/TextInputWithCurrencySymbol/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type BaseTextInputWithCurrencySymbolProps = {
7777

7878
/** Hide the focus styles on TextInput */
7979
hideFocusedState?: boolean;
80-
} & Pick<BaseTextInputProps, 'autoFocus' | 'autoGrow' | 'contentWidth' | 'onPress'>;
80+
} & Pick<BaseTextInputProps, 'autoFocus' | 'autoGrow' | 'autoGrowExtraSpace' | 'contentWidth' | 'onPress'>;
8181

8282
type TextInputWithCurrencySymbolProps = Omit<BaseTextInputWithCurrencySymbolProps, 'onSelectionChange'> & {
8383
onSelectionChange?: (start: number, end: number) => void;

src/pages/iou/MoneyRequestAmountForm.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as CurrencyUtils from '@libs/CurrencyUtils';
1919
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
2020
import * as MoneyRequestUtils from '@libs/MoneyRequestUtils';
2121
import Navigation from '@libs/Navigation/Navigation';
22+
import variables from '@styles/variables';
2223
import type {BaseTextInputRef} from '@src/components/TextInput/BaseTextInput/types';
2324
import CONST from '@src/CONST';
2425
import type {Route} from '@src/ROUTES';
@@ -259,6 +260,7 @@ function MoneyRequestAmountForm(
259260
>
260261
<MoneyRequestAmountInput
261262
amount={amount}
263+
autoGrowExtraSpace={variables.w80}
262264
currency={currency}
263265
isCurrencyPressable={isCurrencyPressable}
264266
onCurrencyButtonPress={onCurrencyButtonPress}
@@ -312,7 +314,7 @@ function MoneyRequestAmountForm(
312314
addBankAccountRoute={bankAccountRoute}
313315
addDebitCardRoute={ROUTES.IOU_SEND_ADD_DEBIT_CARD}
314316
currency={currency ?? CONST.CURRENCY.USD}
315-
policyID={policyID ?? '-1'}
317+
policyID={policyID}
316318
style={[styles.w100, canUseTouchScreen ? styles.mt5 : styles.mt3]}
317319
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.LARGE}
318320
kycWallAnchorAlignment={{

src/styles/utils/index.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,16 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({
13021302
};
13031303
},
13041304

1305+
/*
1306+
* Returns styles for the text input container, with extraSpace allowing overflow without affecting the layout.
1307+
*/
1308+
getAutoGrowWidthInputContainerStyles: (width: number, extraSpace: number): ViewStyle => {
1309+
if (!!width && !!extraSpace) {
1310+
return {marginRight: -extraSpace, width: width + extraSpace};
1311+
}
1312+
return {width};
1313+
},
1314+
13051315
/*
13061316
* Returns the actual maxHeight of the auto-growing markdown text input.
13071317
*/

0 commit comments

Comments
 (0)