Skip to content

Commit d80d99a

Browse files
authored
Merge pull request Expensify#65006 from aadil42/issues/63127/emoji-alphabet-brifely-shown-in-per-diem-field-verified-commits
Preventing brief occurrences of emojis and non-digit chars.
2 parents 665f42d + 24e91ae commit d80d99a

4 files changed

Lines changed: 24 additions & 79 deletions

File tree

src/components/AmountWithoutCurrencyForm.tsx

Lines changed: 0 additions & 72 deletions
This file was deleted.

src/components/AmountWithoutCurrencyInput.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ function AmountWithoutCurrencyInput(
4545
[onInputChange],
4646
);
4747

48+
// Add custom notation for using '-' character in the mask.
49+
// If we only use '-' for characterSet instead of '0123456789.-'
50+
// then the first character has to be '-' optionally, but we also want to allow a digit in first position if the value is positive.
51+
// More info: https://github.com/IvanIhnatsiuk/react-native-advanced-input-mask?tab=readme-ov-file#custom-notations
52+
const customMask = [
53+
{
54+
character: '~',
55+
characterSet: '0123456789.-',
56+
isOptional: true,
57+
},
58+
];
59+
4860
return (
4961
<TextInput
5062
inputID={inputID}
@@ -57,9 +69,10 @@ function AmountWithoutCurrencyInput(
5769
ref={ref}
5870
keyboardType={!shouldAllowNegative ? CONST.KEYBOARD_TYPE.DECIMAL_PAD : undefined}
5971
type="mask"
60-
mask={`[09999999]${separator}[09]`}
61-
allowedKeys="0123456789.,"
62-
validationRegex={'^(?!.*[.,].*[.,])\\d{0,8}(?:[.,]\\d{0,2})?$'}
72+
mask={shouldAllowNegative ? `[~][99999999]${separator}[09]` : `[09999999]${separator}[09]`}
73+
customNotations={customMask}
74+
allowedKeys="0123456789.,-"
75+
validationRegex={'^-?(?!.*[.,].*[.,])\\d{0,8}(?:[.,]\\d{0,2})?$'}
6376
// On android autoCapitalize="words" is necessary when keyboardType="decimal-pad" or inputMode="decimal" to prevent input lag.
6477
// See https://github.com/Expensify/App/issues/51868 for more information
6578
autoCapitalize="words"
@@ -69,6 +82,6 @@ function AmountWithoutCurrencyInput(
6982
);
7083
}
7184

72-
AmountWithoutCurrencyInput.displayName = 'AmountWithoutCurrencyForm';
85+
AmountWithoutCurrencyInput.displayName = 'AmountWithoutCurrencyInput';
7386

7487
export default React.forwardRef(AmountWithoutCurrencyInput);

src/components/TextInput/BaseTextInput/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ type CustomBaseTextInputProps = {
166166
/** The mask of the masked input */
167167
mask?: MaskedTextInputOwnProps['mask'];
168168

169+
/** Custom notations for the masked input */
170+
customNotations?: MaskedTextInputOwnProps['customNotations'];
171+
169172
/** A set of permitted characters for the input */
170173
allowedKeys?: MaskedTextInputOwnProps['allowedKeys'];
171174

src/pages/workspace/perDiem/EditPerDiemAmountPage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, {useCallback} from 'react';
2-
import AmountWithoutCurrencyForm from '@components/AmountWithoutCurrencyForm';
2+
import AmountWithoutCurrencyInput from '@components/AmountWithoutCurrencyInput';
33
import FormProvider from '@components/Form/FormProvider';
44
import InputWrapper from '@components/Form/InputWrapper';
55
import type {FormInputErrors, FormOnyxValues} from '@components/Form/types';
@@ -31,7 +31,7 @@ function EditPerDiemAmountPage({route}: EditPerDiemAmountPageProps) {
3131
const policyID = route.params.policyID;
3232
const rateID = route.params.rateID;
3333
const subRateID = route.params.subRateID;
34-
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`);
34+
const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {canBeMissing: true});
3535

3636
const customUnit = getPerDiemCustomUnit(policy);
3737

@@ -98,13 +98,14 @@ function EditPerDiemAmountPage({route}: EditPerDiemAmountPageProps) {
9898
>
9999
<InputWrapper
100100
ref={inputCallbackRef}
101-
InputComponent={AmountWithoutCurrencyForm}
101+
InputComponent={AmountWithoutCurrencyInput}
102102
defaultValue={defaultAmount}
103103
label={translate('workspace.perDiem.amount')}
104104
accessibilityLabel={translate('workspace.perDiem.amount')}
105105
inputID={INPUT_IDS.AMOUNT}
106106
role={CONST.ROLE.PRESENTATION}
107107
shouldAllowNegative
108+
uncontrolled
108109
/>
109110
</FormProvider>
110111
</ScreenWrapper>

0 commit comments

Comments
 (0)