({
onChange,
value,
currency,
decimals,
style,
digitButtonStyle,
digitTextStyle,
periodButtonStyle,
periodTextStyle,
deleteButtonStyle,
deleteIcon,
})
| 5 | import useCurrency from './useCurrency'; |
| 6 | import { ViewPropTypes } from 'react-native'; |
| 7 | function KeypadComponent({ |
| 8 | onChange, |
| 9 | value, |
| 10 | currency, |
| 11 | decimals, |
| 12 | style, |
| 13 | digitButtonStyle, |
| 14 | digitTextStyle, |
| 15 | periodButtonStyle, |
| 16 | periodTextStyle, |
| 17 | deleteButtonStyle, |
| 18 | deleteIcon, |
| 19 | }) { |
| 20 | const { handler, decimalSeparator } = useCurrency(currency, decimals); |
| 21 | const handleKeypadPress = useCallback( |
| 22 | (pressedKey) => { |
| 23 | const newValue = handler(value, pressedKey); |
| 24 | let valueAsNumber = 0; |
| 25 | try { |
| 26 | valueAsNumber = Number(newValue.replace(decimalSeparator, '.')); |
| 27 | } catch (error) { |
| 28 | console.error(error); |
| 29 | } |
| 30 | onChange({ value: newValue, valueAsNumber, pressedKey }); |
| 31 | }, |
| 32 | [decimalSeparator, handler, onChange, value], |
| 33 | ); |
| 34 | const handleKeypadPress1 = useCallback( |
| 35 | () => handleKeypadPress(KEYS.DIGIT_1), |
| 36 | [handleKeypadPress], |
| 37 | ); |
| 38 | const handleKeypadPress2 = useCallback( |
| 39 | () => handleKeypadPress(KEYS.DIGIT_2), |
| 40 | [handleKeypadPress], |
| 41 | ); |
| 42 | const handleKeypadPress3 = useCallback( |
| 43 | () => handleKeypadPress(KEYS.DIGIT_3), |
| 44 | [handleKeypadPress], |
| 45 | ); |
| 46 | const handleKeypadPress4 = useCallback( |
| 47 | () => handleKeypadPress(KEYS.DIGIT_4), |
| 48 | [handleKeypadPress], |
| 49 | ); |
| 50 | const handleKeypadPress5 = useCallback( |
| 51 | () => handleKeypadPress(KEYS.DIGIT_5), |
| 52 | [handleKeypadPress], |
| 53 | ); |
| 54 | const handleKeypadPress6 = useCallback( |
| 55 | () => handleKeypadPress(KEYS.DIGIT_6), |
| 56 | [handleKeypadPress], |
| 57 | ); |
| 58 | const handleKeypadPress7 = useCallback( |
| 59 | () => handleKeypadPress(KEYS.DIGIT_7), |
| 60 | [handleKeypadPress], |
| 61 | ); |
| 62 | const handleKeypadPress8 = useCallback( |
| 63 | () => handleKeypadPress(KEYS.DIGIT_8), |
| 64 | [handleKeypadPress], |
nothing calls this directly
no test coverage detected