Skip to content

Commit

Permalink
Merge pull request #40288 from FitseTLT/fix-numpad-longpress-back-key
Browse files Browse the repository at this point in the history
Fix numpad longpress back key
  • Loading branch information
chiragsalian authored Apr 23, 2024
2 parents df57111 + 4abee43 commit 65bab75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/components/AmountForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ function AmountForm(

const strippedAmount = MoneyRequestUtils.stripCommaFromAmount(newAmountWithoutSpaces);
const isForwardDelete = currentAmount.length > strippedAmount.length && forwardDeletePressedRef.current;
setSelection((prevSelection) => getNewSelection(prevSelection, isForwardDelete ? strippedAmount.length : currentAmount.length, strippedAmount.length));
setSelection(getNewSelection(selection, isForwardDelete ? strippedAmount.length : currentAmount.length, strippedAmount.length));
onInputChange?.(strippedAmount);
},
[amountMaxLength, currentAmount, decimals, onInputChange],
[amountMaxLength, currentAmount, decimals, onInputChange, selection],
);

// Modifies the amount to match the decimals for changed currency.
Expand Down
9 changes: 7 additions & 2 deletions src/components/BigNumberPad.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useState} from 'react';
import React, {useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
import useLocalize from '@hooks/useLocalize';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -33,6 +33,11 @@ function BigNumberPad({numberPressed, longPressHandlerStateChanged = () => {}, i
const styles = useThemeStyles();
const [timer, setTimer] = useState<NodeJS.Timeout | null>(null);
const {isExtraSmallScreenHeight} = useWindowDimensions();
const numberPressedRef = useRef(numberPressed);

useEffect(() => {
numberPressedRef.current = numberPressed;
}, [numberPressed]);

/**
* Handle long press key on number pad.
Expand All @@ -46,7 +51,7 @@ function BigNumberPad({numberPressed, longPressHandlerStateChanged = () => {}, i
longPressHandlerStateChanged(true);

const newTimer = setInterval(() => {
numberPressed(key);
numberPressedRef.current?.(key);
}, 100);

setTimer(newTimer);
Expand Down

0 comments on commit 65bab75

Please sign in to comment.