From 2cc6234c0053181f9c4eb008eec5d0b5566c0527 Mon Sep 17 00:00:00 2001 From: Prakhar Agarwal Date: Sat, 25 May 2024 16:23:37 +0530 Subject: [PATCH] feat: Add backspace long press functionality to currency keyboard 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 }) => {