Skip to content

Commit 27b2b41

Browse files
committed
update keyboard type for IOS
1 parent 264119e commit 27b2b41

7 files changed

Lines changed: 60 additions & 3 deletions

File tree

src/CONST/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,7 @@ const CONST = {
17901790
ASCII_CAPABLE: 'ascii-capable',
17911791
NUMBER_PAD: 'number-pad',
17921792
DECIMAL_PAD: 'decimal-pad',
1793+
NUMBERS_AND_PUNCTUATION: 'numbers-and-punctuation',
17931794
},
17941795

17951796
INPUT_MODE: {

src/components/AmountWithoutCurrencyInput.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, {useCallback, useMemo} from 'react';
22
import type {ForwardedRef} from 'react';
33
import useLocalize from '@hooks/useLocalize';
4+
import getAmountInputKeyboard from '@libs/getAmountInputKeyboard';
45
import {replaceAllDigits, replaceCommasWithPeriod, stripSpacesFromAmount} from '@libs/MoneyRequestUtils';
5-
import CONST from '@src/CONST';
66
import TextInput from './TextInput';
77
import type {BaseTextInputProps, BaseTextInputRef} from './TextInput/BaseTextInput/types';
88

@@ -57,6 +57,8 @@ function AmountWithoutCurrencyInput(
5757
},
5858
];
5959

60+
const {keyboardType, inputMode} = getAmountInputKeyboard(shouldAllowNegative);
61+
6062
return (
6163
<TextInput
6264
inputID={inputID}
@@ -67,10 +69,10 @@ function AmountWithoutCurrencyInput(
6769
accessibilityLabel={accessibilityLabel}
6870
role={role}
6971
ref={ref}
70-
keyboardType={CONST.KEYBOARD_TYPE.DECIMAL_PAD}
72+
keyboardType={keyboardType}
73+
inputMode={inputMode}
7174
type="mask"
7275
mask={shouldAllowNegative ? `[~][99999999]${separator}[09]` : `[09999999]${separator}[09]`}
73-
inputMode={CONST.INPUT_MODE.DECIMAL}
7476
customNotations={customMask}
7577
allowedKeys="0123456789.,-"
7678
validationRegex={'^-?(?!.*[.,].*[.,])\\d{0,8}(?:[.,]\\d{0,2})?$'}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import CONST from '@src/CONST';
2+
import type GetAmountInputKeyboard from './type';
3+
4+
const getAmountInputKeyboard: GetAmountInputKeyboard = () => {
5+
return {
6+
keyboardType: CONST.KEYBOARD_TYPE.DECIMAL_PAD,
7+
inputMode: CONST.INPUT_MODE.DECIMAL,
8+
};
9+
};
10+
11+
export default getAmountInputKeyboard;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import CONST from '@src/CONST';
2+
import type GetAmountInputKeyboard from './type';
3+
4+
const getAmountInputKeyboard: GetAmountInputKeyboard = () => {
5+
return {
6+
keyboardType: CONST.KEYBOARD_TYPE.DECIMAL_PAD,
7+
inputMode: CONST.INPUT_MODE.DECIMAL,
8+
};
9+
};
10+
11+
export default getAmountInputKeyboard;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import CONST from '@src/CONST';
2+
import type GetAmountInputKeyboard from './type';
3+
4+
const getAmountInputKeyboard: GetAmountInputKeyboard = (shouldAllowNegative = false) => {
5+
return {
6+
keyboardType: shouldAllowNegative ? CONST.KEYBOARD_TYPE.NUMBERS_AND_PUNCTUATION : CONST.KEYBOARD_TYPE.DECIMAL_PAD,
7+
inputMode: shouldAllowNegative ? undefined : CONST.INPUT_MODE.DECIMAL,
8+
};
9+
};
10+
11+
export default getAmountInputKeyboard;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {isMobileIOS} from '@libs/Browser';
2+
import CONST from '@src/CONST';
3+
import type GetAmountInputKeyboard from './type';
4+
5+
const getAmountInputKeyboard: GetAmountInputKeyboard = (shouldAllowNegative = false) => {
6+
return {
7+
keyboardType: isMobileIOS() && shouldAllowNegative ? CONST.KEYBOARD_TYPE.NUMBERS_AND_PUNCTUATION : CONST.KEYBOARD_TYPE.DECIMAL_PAD,
8+
inputMode: isMobileIOS() && shouldAllowNegative ? undefined : CONST.INPUT_MODE.DECIMAL,
9+
};
10+
};
11+
12+
export default getAmountInputKeyboard;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type {ValueOf} from 'type-fest';
2+
import type CONST from '@src/CONST';
3+
4+
type GetAmountInputKeyboard = (shouldAllowNegative?: boolean) => {
5+
keyboardType: ValueOf<typeof CONST.KEYBOARD_TYPE> | undefined;
6+
inputMode: ValueOf<typeof CONST.INPUT_MODE> | undefined;
7+
};
8+
9+
export default GetAmountInputKeyboard;

0 commit comments

Comments
 (0)