From ca07fdcd4eb6fdb5cca5c9b34638fc8977fea9c6 Mon Sep 17 00:00:00 2001 From: Prakhar Agarwal Date: Thu, 13 Jun 2024 21:25:46 +0530 Subject: [PATCH] feat: Add backspace long press functionality to currency keyboard (#3282) Signed-off-by: Prakhar Agarwal --- .../currency-keyboard/currency-keyboard.tsx | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/components/currency-keyboard/currency-keyboard.tsx b/app/components/currency-keyboard/currency-keyboard.tsx index 93136c858e..a2915b97e6 100644 --- a/app/components/currency-keyboard/currency-keyboard.tsx +++ b/app/components/currency-keyboard/currency-keyboard.tsx @@ -1,4 +1,4 @@ -import React from "react" +import React, { useEffect, useState } from "react" import { Pressable, StyleProp, View, ViewStyle } from "react-native" import { testProps } from "@app/utils/testProps" @@ -96,11 +96,39 @@ const Key = ({ return baseStyle } + const [timerId, setTimerId] = useState(null) + + const handleBackSpacePressIn = (numberPadKey: KeyType) => { + const id = setInterval(() => { + if (numberPadKey === KeyType.Backspace) { + handleKeyPress(numberPadKey) + } + }, 300) + setTimerId(id) + } + + const handleBackSpacePressOut = () => { + if (timerId) { + clearInterval(timerId) + setTimerId(null) + } + } + + useEffect(() => { + return () => { + if (timerId) { + clearInterval(timerId) + } + } + }, [timerId]) + return ( handleBackSpacePressIn(numberPadKey)} onPress={() => handleKeyPress(numberPadKey)} + onPressOut={handleBackSpacePressOut} {...testProps(`Key ${numberPadKey}`)} > {({ pressed }) => {