@@ -4,11 +4,12 @@ import type {NativeSyntheticEvent} from 'react-native';
4
4
import { View } from 'react-native' ;
5
5
import useLocalize from '@hooks/useLocalize' ;
6
6
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' ;
10
10
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' ;
12
13
import CONST from '@src/CONST' ;
13
14
import BigNumberPad from './BigNumberPad' ;
14
15
import FormHelpMessage from './FormHelpMessage' ;
@@ -88,7 +89,7 @@ function AmountForm(
88
89
89
90
const textInput = useRef < BaseTextInputRef | null > ( null ) ;
90
91
91
- const decimals = fixedDecimals ?? CurrencyUtils . getCurrencyDecimals ( currency ) + extraDecimals ;
92
+ const decimals = fixedDecimals ?? getCurrencyDecimals ( currency ) + extraDecimals ;
92
93
const currentAmount = useMemo ( ( ) => ( typeof amount === 'string' ? amount : '' ) , [ amount ] ) ;
93
94
94
95
const [ shouldUpdateSelection , setShouldUpdateSelection ] = useState ( true ) ;
@@ -104,7 +105,7 @@ function AmountForm(
104
105
* Event occurs when a user presses a mouse button over an DOM element.
105
106
*/
106
107
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 ;
108
109
if ( ! ids . includes ( relatedTargetId ) ) {
109
110
return ;
110
111
}
@@ -131,15 +132,15 @@ function AmountForm(
131
132
( newAmount : string ) => {
132
133
// Remove spaces from the newAmount value because Safari on iOS adds spaces when pasting a copied value
133
134
// More info: https://github.com/Expensify/App/issues/16974
134
- const newAmountWithoutSpaces = MoneyRequestUtils . stripSpacesFromAmount ( newAmount ) ;
135
+ const newAmountWithoutSpaces = stripSpacesFromAmount ( newAmount ) ;
135
136
// Use a shallow copy of selection to trigger setSelection
136
137
// More info: https://github.com/Expensify/App/issues/16385
137
- if ( ! MoneyRequestUtils . validateAmount ( newAmountWithoutSpaces , decimals , amountMaxLength ) ) {
138
+ if ( ! validateAmount ( newAmountWithoutSpaces , decimals , amountMaxLength ) ) {
138
139
setSelection ( ( prevSelection ) => ( { ...prevSelection } ) ) ;
139
140
return ;
140
141
}
141
142
142
- const strippedAmount = MoneyRequestUtils . stripCommaFromAmount ( newAmountWithoutSpaces ) ;
143
+ const strippedAmount = stripCommaFromAmount ( newAmountWithoutSpaces ) ;
143
144
const isForwardDelete = currentAmount . length > strippedAmount . length && forwardDeletePressedRef . current ;
144
145
setSelection ( getNewSelection ( selection , isForwardDelete ? strippedAmount . length : currentAmount . length , strippedAmount . length ) ) ;
145
146
onInputChange ?.( strippedAmount ) ;
@@ -155,16 +156,16 @@ function AmountForm(
155
156
const setFormattedAmount = ( text : string ) => {
156
157
// Remove spaces from the newAmount value because Safari on iOS adds spaces when pasting a copied value
157
158
// 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 ) ;
161
162
162
- if ( ! MoneyRequestUtils . validateAmount ( withLeadingZero , decimals , amountMaxLength ) ) {
163
+ if ( ! validateAmount ( withLeadingZero , decimals , amountMaxLength ) ) {
163
164
setSelection ( ( prevSelection ) => ( { ...prevSelection } ) ) ;
164
165
return ;
165
166
}
166
167
167
- const strippedAmount = MoneyRequestUtils . stripCommaFromAmount ( withLeadingZero ) ;
168
+ const strippedAmount = stripCommaFromAmount ( withLeadingZero ) ;
168
169
const isForwardDelete = currentAmount . length > strippedAmount . length && forwardDeletePressedRef . current ;
169
170
setSelection ( getNewSelection ( selection , isForwardDelete ? strippedAmount . length : currentAmount . length , strippedAmount . length ) ) ;
170
171
onInputChange ?.( strippedAmount ) ;
@@ -173,12 +174,12 @@ function AmountForm(
173
174
// Modifies the amount to match the decimals for changed currency.
174
175
useEffect ( ( ) => {
175
176
// If the changed currency supports decimals, we can return
176
- if ( MoneyRequestUtils . validateAmount ( currentAmount , decimals , amountMaxLength ) ) {
177
+ if ( validateAmount ( currentAmount , decimals , amountMaxLength ) ) {
177
178
return ;
178
179
}
179
180
180
181
// If the changed currency doesn't support decimals, we can strip the decimals
181
- setNewAmount ( MoneyRequestUtils . stripDecimalsFromAmount ( currentAmount ) ) ;
182
+ setNewAmount ( stripDecimalsFromAmount ( currentAmount ) ) ;
182
183
183
184
// we want to update only when decimals change (setNewAmount also changes when decimals change).
184
185
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps
@@ -198,11 +199,11 @@ function AmountForm(
198
199
if ( currentAmount . length > 0 ) {
199
200
const selectionStart = selection . start === selection . end ? selection . start - 1 : selection . start ;
200
201
const newAmount = `${ currentAmount . substring ( 0 , selectionStart ) } ${ currentAmount . substring ( selection . end ) } ` ;
201
- setNewAmount ( MoneyRequestUtils . addLeadingZero ( newAmount ) ) ;
202
+ setNewAmount ( addLeadingZero ( newAmount ) ) ;
202
203
}
203
204
return ;
204
205
}
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 ) } ` ) ;
206
207
setNewAmount ( newAmount ) ;
207
208
} ,
208
209
[ currentAmount , selection , shouldUpdateSelection , setNewAmount ] ,
@@ -225,7 +226,7 @@ function AmountForm(
225
226
*/
226
227
const textInputKeyPress = ( event : NativeSyntheticEvent < KeyboardEvent > ) => {
227
228
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 ) {
229
230
// Optimistically anticipate forward-delete on iOS Safari (in cases where the Mac Accessiblity keyboard is being
230
231
// used for input). If the Control-D shortcut doesn't get sent, the ref will still be reset on the next key press.
231
232
forwardDeletePressedRef . current = true ;
@@ -238,8 +239,8 @@ function AmountForm(
238
239
forwardDeletePressedRef . current = key === 'delete' || ( allowedOS . includes ( operatingSystem ?? '' ) && event . nativeEvent . ctrlKey && key === 'd' ) ;
239
240
} ;
240
241
241
- const formattedAmount = MoneyRequestUtils . replaceAllDigits ( currentAmount , toLocaleDigit ) ;
242
- const canUseTouchScreen = DeviceCapabilities . canUseTouchScreen ( ) ;
242
+ const formattedAmount = replaceAllDigits ( currentAmount , toLocaleDigit ) ;
243
+ const canUseTouchScreen = canUseTouchScreenCheck ( ) ;
243
244
244
245
if ( displayAsTextInput ) {
245
246
return (
@@ -279,6 +280,7 @@ function AmountForm(
279
280
>
280
281
< TextInputWithCurrencySymbol
281
282
formattedAmount = { formattedAmount }
283
+ autoGrowExtraSpace = { variables . w80 }
282
284
onChangeAmount = { setNewAmount }
283
285
onCurrencyButtonPress = { onCurrencyButtonPress }
284
286
placeholder = { numberFormat ( 0 ) }
0 commit comments