feat: edit expense
This commit is contained in:
parent
deda54152b
commit
5b71fa74b1
11 changed files with 273 additions and 41 deletions
|
|
@ -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))){
|
||||
|
|
|
|||
|
|
@ -7,14 +7,13 @@ import { useTheme } from '../../app/contexts/ThemeContext';
|
|||
interface SearchBarProps extends ViewProps {
|
||||
placeholder? : string;
|
||||
onChangeText? : (text: string) => void | undefined
|
||||
value?: string
|
||||
}
|
||||
|
||||
export default function TextInputBar(props: SearchBarProps) {
|
||||
const [isActive, setIsactive] = React.useState(false);
|
||||
const { colors } = useTheme();
|
||||
const [text, setText] = useState<string>("");
|
||||
|
||||
const textColor = colors
|
||||
const backgroundColor = colors.elementDefaultColor;
|
||||
|
||||
const handleChange = (text:string) : void => {
|
||||
|
|
@ -30,7 +29,7 @@ export default function TextInputBar(props: SearchBarProps) {
|
|||
if(props.onChangeText){
|
||||
props.onChangeText(text)
|
||||
}
|
||||
setText(text)
|
||||
|
||||
}
|
||||
|
||||
// cant apply the background color otherwise
|
||||
|
|
@ -43,7 +42,7 @@ export default function TextInputBar(props: SearchBarProps) {
|
|||
// changed styles.container to containerStyle
|
||||
return (
|
||||
<View style={[containerStyle, props.style]}>
|
||||
<TextInput placeholderTextColor={colors.secondaryText} onChangeText = {handleChange} style={[{fontSize: SIZES.normal, height: "100%", color:colors.primaryText}, styles.TextInput]} autoCorrect={false} keyboardType='default' placeholder={props.placeholder} value={text} onFocus={()=>handleChange(text)} onEndEditing={()=>setIsactive(false)}/>
|
||||
<TextInput placeholderTextColor={colors.secondaryText} onChangeText = {handleChange} style={[{fontSize: SIZES.normal, height: "100%", color:colors.primaryText}, styles.TextInput]} autoCorrect={false} keyboardType='default' placeholder={props.placeholder} value={props.value} onEndEditing={()=>setIsactive(false)}/>
|
||||
|
||||
{isActive &&
|
||||
<TouchableOpacity style={styles.cancel} onPress={()=>{handleChange("")}}>
|
||||
|
|
|
|||
Reference in a new issue