@@ -92,6 +92,17 @@ type MoneyRequestAmountInputProps = {
9292 /** The width of inner content */
9393 contentWidth ?: number ;
9494
95+ /** Whether the amount is negative */
96+ isNegative ?: boolean ;
97+
98+ /** Function to toggle the amount to negative */
99+ toggleNegative ?: ( ) => void ;
100+
101+ /** Function to clear the negative amount */
102+ clearNegative ?: ( ) => void ;
103+
104+ /** Whether to allow flipping amount */
105+ allowFlippingAmount ?: boolean ;
95106 /** The testID of the input. Used to locate this view in end-to-end tests. */
96107 testID ?: string ;
97108} & Pick < TextInputWithCurrencySymbolProps , 'autoGrowExtraSpace' | 'submitBehavior' > ;
@@ -131,6 +142,10 @@ function MoneyRequestAmountInput(
131142 autoGrow = true ,
132143 autoGrowExtraSpace,
133144 contentWidth,
145+ isNegative = false ,
146+ allowFlippingAmount = false ,
147+ toggleNegative,
148+ clearNegative,
134149 testID,
135150 submitBehavior,
136151 ...props
@@ -164,6 +179,10 @@ function MoneyRequestAmountInput(
164179 */
165180 const setNewAmount = useCallback (
166181 ( newAmount : string ) => {
182+ if ( allowFlippingAmount && newAmount . startsWith ( '-' ) && toggleNegative ) {
183+ toggleNegative ( ) ;
184+ }
185+
167186 // Remove spaces from the newAmount value because Safari on iOS adds spaces when pasting a copied value
168187 // More info: https://github.com/Expensify/App/issues/16974
169188 const newAmountWithoutSpaces = stripSpacesFromAmount ( newAmount ) ;
@@ -192,7 +211,7 @@ function MoneyRequestAmountInput(
192211 return strippedAmount ;
193212 } ) ;
194213 } ,
195- [ decimals , onAmountChange ] ,
214+ [ allowFlippingAmount , decimals , onAmountChange , toggleNegative ] ,
196215 ) ;
197216
198217 useImperativeHandle ( moneyRequestAmountInputRef , ( ) => ( {
@@ -252,6 +271,11 @@ function MoneyRequestAmountInput(
252271 */
253272 const textInputKeyPress = ( { nativeEvent} : NativeSyntheticEvent < KeyboardEvent > ) => {
254273 const key = nativeEvent ?. key . toLowerCase ( ) ;
274+
275+ if ( ! textInput . current ?. value && key === 'backspace' && isNegative ) {
276+ clearNegative ?.( ) ;
277+ }
278+
255279 if ( isMobileSafari ( ) && key === CONST . PLATFORM_SPECIFIC_KEYS . CTRL . DEFAULT ) {
256280 // Optimistically anticipate forward-delete on iOS Safari (in cases where the Mac accessibility keyboard is being
257281 // used for input). If the Control-D shortcut doesn't get sent, the ref will still be reset on the next key press.
@@ -343,6 +367,7 @@ function MoneyRequestAmountInput(
343367 onMouseDown = { handleMouseDown }
344368 onMouseUp = { handleMouseUp }
345369 contentWidth = { contentWidth }
370+ isNegative = { isNegative }
346371 testID = { testID }
347372 submitBehavior = { submitBehavior }
348373 />
0 commit comments