Skip to content

Commit 9eb1310

Browse files
authored
Merge pull request #58380 from huult/56951-tax-input-dot-move
56951 tax input dot move
2 parents e308bf2 + 8aa3040 commit 9eb1310

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

src/components/AmountForm.tsx

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import type {NativeSyntheticEvent} from 'react-native';
44
import {View} from 'react-native';
55
import useLocalize from '@hooks/useLocalize';
66
import useThemeStyles from '@hooks/useThemeStyles';
7-
import * as Browser from '@libs/Browser';
8-
import * as CurrencyUtils from '@libs/CurrencyUtils';
9-
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
7+
import {isMobileSafari} from '@libs/Browser';
8+
import {getCurrencyDecimals} from '@libs/CurrencyUtils';
9+
import {canUseTouchScreen as canUseTouchScreenCheck} from '@libs/DeviceCapabilities';
1010
import getOperatingSystem from '@libs/getOperatingSystem';
11-
import * as MoneyRequestUtils from '@libs/MoneyRequestUtils';
11+
import {addLeadingZero, replaceAllDigits, replaceCommasWithPeriod, stripCommaFromAmount, stripDecimalsFromAmount, stripSpacesFromAmount, validateAmount} from '@libs/MoneyRequestUtils';
12+
import variables from '@styles/variables';
1213
import CONST from '@src/CONST';
1314
import BigNumberPad from './BigNumberPad';
1415
import FormHelpMessage from './FormHelpMessage';
@@ -88,7 +89,7 @@ function AmountForm(
8889

8990
const textInput = useRef<BaseTextInputRef | null>(null);
9091

91-
const decimals = fixedDecimals ?? CurrencyUtils.getCurrencyDecimals(currency) + extraDecimals;
92+
const decimals = fixedDecimals ?? getCurrencyDecimals(currency) + extraDecimals;
9293
const currentAmount = useMemo(() => (typeof amount === 'string' ? amount : ''), [amount]);
9394

9495
const [shouldUpdateSelection, setShouldUpdateSelection] = useState(true);
@@ -104,7 +105,7 @@ function AmountForm(
104105
* Event occurs when a user presses a mouse button over an DOM element.
105106
*/
106107
const focusTextInput = (event: React.MouseEvent, ids: string[]) => {
107-
const relatedTargetId = (event.nativeEvent?.target as HTMLElement | null)?.id ?? '';
108+
const relatedTargetId = (event.nativeEvent?.target as HTMLElement)?.id;
108109
if (!ids.includes(relatedTargetId)) {
109110
return;
110111
}
@@ -131,15 +132,15 @@ function AmountForm(
131132
(newAmount: string) => {
132133
// Remove spaces from the newAmount value because Safari on iOS adds spaces when pasting a copied value
133134
// More info: https://github.com/Expensify/App/issues/16974
134-
const newAmountWithoutSpaces = MoneyRequestUtils.stripSpacesFromAmount(newAmount);
135+
const newAmountWithoutSpaces = stripSpacesFromAmount(newAmount);
135136
// Use a shallow copy of selection to trigger setSelection
136137
// More info: https://github.com/Expensify/App/issues/16385
137-
if (!MoneyRequestUtils.validateAmount(newAmountWithoutSpaces, decimals, amountMaxLength)) {
138+
if (!validateAmount(newAmountWithoutSpaces, decimals, amountMaxLength)) {
138139
setSelection((prevSelection) => ({...prevSelection}));
139140
return;
140141
}
141142

142-
const strippedAmount = MoneyRequestUtils.stripCommaFromAmount(newAmountWithoutSpaces);
143+
const strippedAmount = stripCommaFromAmount(newAmountWithoutSpaces);
143144
const isForwardDelete = currentAmount.length > strippedAmount.length && forwardDeletePressedRef.current;
144145
setSelection(getNewSelection(selection, isForwardDelete ? strippedAmount.length : currentAmount.length, strippedAmount.length));
145146
onInputChange?.(strippedAmount);
@@ -155,16 +156,16 @@ function AmountForm(
155156
const setFormattedAmount = (text: string) => {
156157
// Remove spaces from the newAmount value because Safari on iOS adds spaces when pasting a copied value
157158
// More info: https://github.com/Expensify/App/issues/16974
158-
const newAmountWithoutSpaces = MoneyRequestUtils.stripSpacesFromAmount(text);
159-
const replacedCommasAmount = MoneyRequestUtils.replaceCommasWithPeriod(newAmountWithoutSpaces);
160-
const withLeadingZero = MoneyRequestUtils.addLeadingZero(replacedCommasAmount);
159+
const newAmountWithoutSpaces = stripSpacesFromAmount(text);
160+
const replacedCommasAmount = replaceCommasWithPeriod(newAmountWithoutSpaces);
161+
const withLeadingZero = addLeadingZero(replacedCommasAmount);
161162

162-
if (!MoneyRequestUtils.validateAmount(withLeadingZero, decimals, amountMaxLength)) {
163+
if (!validateAmount(withLeadingZero, decimals, amountMaxLength)) {
163164
setSelection((prevSelection) => ({...prevSelection}));
164165
return;
165166
}
166167

167-
const strippedAmount = MoneyRequestUtils.stripCommaFromAmount(withLeadingZero);
168+
const strippedAmount = stripCommaFromAmount(withLeadingZero);
168169
const isForwardDelete = currentAmount.length > strippedAmount.length && forwardDeletePressedRef.current;
169170
setSelection(getNewSelection(selection, isForwardDelete ? strippedAmount.length : currentAmount.length, strippedAmount.length));
170171
onInputChange?.(strippedAmount);
@@ -173,12 +174,12 @@ function AmountForm(
173174
// Modifies the amount to match the decimals for changed currency.
174175
useEffect(() => {
175176
// If the changed currency supports decimals, we can return
176-
if (MoneyRequestUtils.validateAmount(currentAmount, decimals, amountMaxLength)) {
177+
if (validateAmount(currentAmount, decimals, amountMaxLength)) {
177178
return;
178179
}
179180

180181
// If the changed currency doesn't support decimals, we can strip the decimals
181-
setNewAmount(MoneyRequestUtils.stripDecimalsFromAmount(currentAmount));
182+
setNewAmount(stripDecimalsFromAmount(currentAmount));
182183

183184
// we want to update only when decimals change (setNewAmount also changes when decimals change).
184185
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
@@ -198,11 +199,11 @@ function AmountForm(
198199
if (currentAmount.length > 0) {
199200
const selectionStart = selection.start === selection.end ? selection.start - 1 : selection.start;
200201
const newAmount = `${currentAmount.substring(0, selectionStart)}${currentAmount.substring(selection.end)}`;
201-
setNewAmount(MoneyRequestUtils.addLeadingZero(newAmount));
202+
setNewAmount(addLeadingZero(newAmount));
202203
}
203204
return;
204205
}
205-
const newAmount = MoneyRequestUtils.addLeadingZero(`${currentAmount.substring(0, selection.start)}${key}${currentAmount.substring(selection.end)}`);
206+
const newAmount = addLeadingZero(`${currentAmount.substring(0, selection.start)}${key}${currentAmount.substring(selection.end)}`);
206207
setNewAmount(newAmount);
207208
},
208209
[currentAmount, selection, shouldUpdateSelection, setNewAmount],
@@ -225,7 +226,7 @@ function AmountForm(
225226
*/
226227
const textInputKeyPress = (event: NativeSyntheticEvent<KeyboardEvent>) => {
227228
const key = event.nativeEvent.key.toLowerCase();
228-
if (Browser.isMobileSafari() && key === CONST.PLATFORM_SPECIFIC_KEYS.CTRL.DEFAULT) {
229+
if (isMobileSafari() && key === CONST.PLATFORM_SPECIFIC_KEYS.CTRL.DEFAULT) {
229230
// Optimistically anticipate forward-delete on iOS Safari (in cases where the Mac Accessiblity keyboard is being
230231
// used for input). If the Control-D shortcut doesn't get sent, the ref will still be reset on the next key press.
231232
forwardDeletePressedRef.current = true;
@@ -238,8 +239,8 @@ function AmountForm(
238239
forwardDeletePressedRef.current = key === 'delete' || (allowedOS.includes(operatingSystem ?? '') && event.nativeEvent.ctrlKey && key === 'd');
239240
};
240241

241-
const formattedAmount = MoneyRequestUtils.replaceAllDigits(currentAmount, toLocaleDigit);
242-
const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();
242+
const formattedAmount = replaceAllDigits(currentAmount, toLocaleDigit);
243+
const canUseTouchScreen = canUseTouchScreenCheck();
243244

244245
if (displayAsTextInput) {
245246
return (
@@ -279,6 +280,7 @@ function AmountForm(
279280
>
280281
<TextInputWithCurrencySymbol
281282
formattedAmount={formattedAmount}
283+
autoGrowExtraSpace={variables.w80}
282284
onChangeAmount={setNewAmount}
283285
onCurrencyButtonPress={onCurrencyButtonPress}
284286
placeholder={numberFormat(0)}

0 commit comments

Comments
 (0)