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
299 changes: 0 additions & 299 deletions patches/react-native+0.75.2+018+Add-regex-to-TextInput.patch

This file was deleted.

3 changes: 0 additions & 3 deletions src/components/AmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ function AmountForm(
forwardDeletePressedRef.current = key === 'delete' || (allowedOS.includes(operatingSystem ?? '') && event.nativeEvent.ctrlKey && key === 'd');
};

const regex = useMemo(() => MoneyRequestUtils.amountRegex(decimals, amountMaxLength), [decimals, amountMaxLength]);
const formattedAmount = MoneyRequestUtils.replaceAllDigits(currentAmount, toLocaleDigit);
const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();

Expand All @@ -262,7 +261,6 @@ function AmountForm(
keyboardType={CONST.KEYBOARD_TYPE.DECIMAL_PAD}
inputMode={CONST.INPUT_MODE.DECIMAL}
errorText={errorText}
regex={regex}
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
/>
Expand Down Expand Up @@ -302,7 +300,6 @@ function AmountForm(
isCurrencyPressable={isCurrencyPressable}
style={[styles.iouAmountTextInput]}
containerStyle={[styles.iouAmountTextInputContainer]}
regex={regex}
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
/>
Expand Down
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' | 'regex'>;
} & Pick<BaseTextInputProps, 'autoFocus'>;

function AmountTextInput(
{
Expand Down
21 changes: 3 additions & 18 deletions src/components/AmountWithoutCurrencyForm.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, {useCallback, useMemo, useState} from 'react';
import React, {useCallback, useMemo} from 'react';
import type {ForwardedRef} from 'react';
import type {NativeSyntheticEvent, TextInputSelectionChangeEventData} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import {addLeadingZero, amountRegex, replaceAllDigits, replaceCommasWithPeriod, stripSpacesFromAmount, validateAmount} from '@libs/MoneyRequestUtils';
import {addLeadingZero, replaceAllDigits, replaceCommasWithPeriod, stripSpacesFromAmount, validateAmount} from '@libs/MoneyRequestUtils';
import CONST from '@src/CONST';
import TextInput from './TextInput';
import type {BaseTextInputProps, BaseTextInputRef} from './TextInput/BaseTextInput/types';
Expand All @@ -22,11 +21,6 @@ function AmountWithoutCurrencyForm(
const {toLocaleDigit} = useLocalize();

const currentAmount = useMemo(() => (typeof amount === 'string' ? amount : ''), [amount]);
const [selection, setSelection] = useState({
start: currentAmount.length,
end: currentAmount.length,
});
const decimals = 2;

/**
* Sets the selection and the amount accordingly to the value passed to the input
Expand All @@ -39,28 +33,20 @@ function AmountWithoutCurrencyForm(
const newAmountWithoutSpaces = stripSpacesFromAmount(newAmount);
const replacedCommasAmount = replaceCommasWithPeriod(newAmountWithoutSpaces);
const withLeadingZero = addLeadingZero(replacedCommasAmount);
if (!validateAmount(withLeadingZero, decimals)) {
// Use a shallow copy of selection to trigger setSelection
// More info: https://github.com/Expensify/App/issues/16385
setSelection((prevSelection) => ({...prevSelection}));
if (!validateAmount(withLeadingZero, 2)) {
return;
}
onInputChange?.(withLeadingZero);
},
[onInputChange],
);

const regex = useMemo(() => amountRegex(decimals), [decimals]);
const formattedAmount = replaceAllDigits(currentAmount, toLocaleDigit);

return (
<TextInput
value={formattedAmount}
onChangeText={setNewAmount}
selection={selection}
onSelectionChange={(e: NativeSyntheticEvent<TextInputSelectionChangeEventData>) => {
setSelection(e.nativeEvent.selection);
}}
inputID={inputID}
name={name}
label={label}
Expand All @@ -69,7 +55,6 @@ function AmountWithoutCurrencyForm(
role={role}
ref={ref}
keyboardType={CONST.KEYBOARD_TYPE.DECIMAL_PAD}
regex={regex}
// eslint-disable-next-line react/jsx-props-no-spreading
{...rest}
/>
Expand Down
Loading