Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/components/AmountTextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type AmountTextInputProps = {

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

function AmountTextInput(
{
Expand Down
5 changes: 4 additions & 1 deletion src/components/MoneyRequestAmountInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CONST from '@src/CONST';
import isTextInputFocused from './TextInput/BaseTextInput/isTextInputFocused';
import type {BaseTextInputRef} from './TextInput/BaseTextInput/types';
import TextInputWithCurrencySymbol from './TextInputWithCurrencySymbol';
import type {TextInputWithCurrencySymbolProps} from './TextInputWithCurrencySymbol/types';

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

Expand Down Expand Up @@ -91,7 +92,7 @@ type MoneyRequestAmountInputProps = {

/** The width of inner content */
contentWidth?: number;
};
} & Pick<TextInputWithCurrencySymbolProps, 'autoGrowExtraSpace'>;

type Selection = {
start: number;
Expand Down Expand Up @@ -126,6 +127,7 @@ function MoneyRequestAmountInput(
hideFocusedState = true,
shouldKeepUserInput = false,
autoGrow = true,
autoGrowExtraSpace,
contentWidth,
...props
}: MoneyRequestAmountInputProps,
Expand Down Expand Up @@ -289,6 +291,7 @@ function MoneyRequestAmountInput(
return (
<TextInputWithCurrencySymbol
autoGrow={autoGrow}
autoGrowExtraSpace={autoGrowExtraSpace}
disableKeyboard={disableKeyboard}
formattedAmount={formattedAmount}
onChangeAmount={setNewAmount}
Expand Down
8 changes: 3 additions & 5 deletions src/components/TextInput/BaseTextInput/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function BaseTextInput(
autoFocus = false,
disableKeyboard = false,
autoGrow = false,
autoGrowExtraSpace = 0,
autoGrowHeight = false,
maxAutoGrowHeight,
hideFocusedState = false,
Expand Down Expand Up @@ -250,7 +251,8 @@ function BaseTextInput(
const newTextInputContainerStyles: StyleProp<ViewStyle> = StyleSheet.flatten([
styles.textInputContainer,
textInputContainerStyles,
(autoGrow || !!contentWidth) && StyleUtils.getWidthStyle(textInputWidth),
!!contentWidth && StyleUtils.getWidthStyle(textInputWidth),
autoGrow && StyleUtils.getAutoGrowWidthInputContainerStyles(textInputWidth, autoGrowExtraSpace),
!hideFocusedState && isFocused && styles.borderColorFocus,
(!!hasError || !!errorText) && styles.borderColorDanger,
autoGrowHeight && {scrollPaddingTop: typeof maxAutoGrowHeight === 'number' ? 2 * maxAutoGrowHeight : undefined},
Expand Down Expand Up @@ -441,14 +443,10 @@ function BaseTextInput(
)}
{/*
Text input component doesn't support auto grow by default.
We're using a hidden text input to achieve that.
This text view is used to calculate width or height of the input value given textStyle in this component.
This Text component is intentionally positioned out of the screen.
*/}
{(!!autoGrow || autoGrowHeight) && !isAutoGrowHeightMarkdown && (
// Add +2 to width on Safari browsers so that text is not cut off due to the cursor or when changing the value
// https://github.com/Expensify/App/issues/8158
// https://github.com/Expensify/App/issues/26628
<Text
style={[
inputStyle,
Expand Down
3 changes: 3 additions & 0 deletions src/components/TextInput/BaseTextInput/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ type CustomBaseTextInputProps = {
*/
autoGrow?: boolean;

/** If autoGrow is enabled, this reserves extra space for incoming characters to prevent flickering on native platforms. */
autoGrowExtraSpace?: number;

/**
* Autogrow input container height based on the entered text
*/
Expand Down
2 changes: 1 addition & 1 deletion src/components/TextInputWithCurrencySymbol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type BaseTextInputWithCurrencySymbolProps = {

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

type TextInputWithCurrencySymbolProps = Omit<BaseTextInputWithCurrencySymbolProps, 'onSelectionChange'> & {
onSelectionChange?: (start: number, end: number) => void;
Expand Down
4 changes: 3 additions & 1 deletion src/pages/iou/MoneyRequestAmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import * as CurrencyUtils from '@libs/CurrencyUtils';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as MoneyRequestUtils from '@libs/MoneyRequestUtils';
import Navigation from '@libs/Navigation/Navigation';
import variables from '@styles/variables';
import type {BaseTextInputRef} from '@src/components/TextInput/BaseTextInput/types';
import CONST from '@src/CONST';
import type {Route} from '@src/ROUTES';
Expand Down Expand Up @@ -259,6 +260,7 @@ function MoneyRequestAmountForm(
>
<MoneyRequestAmountInput
amount={amount}
autoGrowExtraSpace={variables.w80}
currency={currency}
isCurrencyPressable={isCurrencyPressable}
onCurrencyButtonPress={onCurrencyButtonPress}
Expand Down Expand Up @@ -312,7 +314,7 @@ function MoneyRequestAmountForm(
addBankAccountRoute={bankAccountRoute}
addDebitCardRoute={ROUTES.IOU_SEND_ADD_DEBIT_CARD}
currency={currency ?? CONST.CURRENCY.USD}
policyID={policyID ?? '-1'}
policyID={policyID}
style={[styles.w100, canUseTouchScreen ? styles.mt5 : styles.mt3]}
buttonSize={CONST.DROPDOWN_BUTTON_SIZE.LARGE}
kycWallAnchorAlignment={{
Expand Down
15 changes: 14 additions & 1 deletion src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ function getBackgroundColorAndFill(backgroundColor: string, fill: string): SVGAv
*/
function getEReceiptColorCode(transaction: OnyxEntry<Transaction>): EReceiptColorName {
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
const transactionID = transaction?.parentTransactionID || transaction?.transactionID || '';
const transactionID = transaction?.parentTransactionID || transaction?.transactionID;
if (!transactionID) {
return CONST.ERECEIPT_COLORS.YELLOW;
}

const colorHash = UserUtils.hashText(transactionID.trim(), eReceiptColors.length);

Expand Down Expand Up @@ -1297,6 +1300,16 @@ const createStyleUtils = (theme: ThemeColors, styles: ThemeStyles) => ({
};
},

/*
* Returns styles for the text input container, with extraSpace allowing overflow without affecting the layout.
*/
getAutoGrowWidthInputContainerStyles: (width: number, extraSpace: number): ViewStyle => {
if (!!width && !!extraSpace) {
return {marginRight: -extraSpace, width: width + extraSpace};
}
return {width};
},

/*
* Returns the actual maxHeight of the auto-growing markdown text input.
*/
Expand Down