feat: edit expense

This commit is contained in:
Jakob Stornig 2024-01-05 15:26:09 +01:00
parent deda54152b
commit 5b71fa74b1
11 changed files with 273 additions and 41 deletions

View file

@ -1,5 +1,5 @@
import { View, Text, TouchableOpacity, TextInput, StyleSheet, NativeSyntheticEvent, TextInputKeyPressEventData } from 'react-native'
import React, {LegacyRef, MutableRefObject, useRef, useState} from 'react'
import React, {LegacyRef, MutableRefObject, useEffect, useRef, useState} from 'react'
import { SIZES } from '../../constants/theme';
import { useTheme } from '../../app/contexts/ThemeContext';
@ -19,13 +19,21 @@ const formatDecimal = (value: string)=>{
interface AutoDecimalInputProps{
onValueChange?: (formattedValue: string) => void | undefined
label: string,
initialValue? : number
}
const AutoDecimalInput: React.FC<AutoDecimalInputProps> = ({onValueChange, label}) => {
const AutoDecimalInput: React.FC<AutoDecimalInputProps> = ({onValueChange, label, initialValue}) => {
const { colors } = useTheme();
const inputRef = useRef<TextInput>(null);
const [pressedNumbers, setPressedNumbers] = useState<string>("");
const init = () => {
if(initialValue){
const pressedNumber = initialValue.toFixed(2).replace(".", "")
update(pressedNumber);
}
}
const update = (newValues : string) => {
if(onValueChange){
onValueChange(formatDecimal(newValues))
@ -33,6 +41,10 @@ const AutoDecimalInput: React.FC<AutoDecimalInputProps> = ({onValueChange, label
setPressedNumbers(newValues);
}
useEffect(() => {
init()
}, [initialValue])
const handleInput = (e: NativeSyntheticEvent<TextInputKeyPressEventData>)=>{
const pressedKey:string = e.nativeEvent.key
if(Number.isInteger(Number.parseInt(pressedKey))){