From 5876fcaf8e48e51415cf93cc12851b7db484f8d0 Mon Sep 17 00:00:00 2001 From: Jakob Stornig Date: Thu, 4 Jan 2024 19:57:05 +0100 Subject: [PATCH] feat: now has onchange functionality. clear works now --- components/common/SearchBar.tsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/components/common/SearchBar.tsx b/components/common/SearchBar.tsx index 372d052..714a3d6 100644 --- a/components/common/SearchBar.tsx +++ b/components/common/SearchBar.tsx @@ -1,14 +1,18 @@ import { AntDesign } from '@expo/vector-icons'; -import React from 'react'; +import React, { useState } from 'react'; import { StyleSheet, TextInput, TouchableOpacity, View, ViewProps } from 'react-native'; import { SIZES } from '../../constants/theme'; import { useTheme } from '../../app/contexts/ThemeContext'; -type SearchBarProps = {placeholder: string} & ViewProps +interface SearchBarProps extends ViewProps { + placeholder? : string; + onChangeText? : (text: string) => void | undefined +} export default function SearchBar(props: SearchBarProps) { const [isActive, setIsactive] = React.useState(false); const { colors } = useTheme(); + const [text, setText] = useState(""); const textColor = colors const backgroundColor = colors.elementDefaultColor; @@ -23,6 +27,10 @@ export default function SearchBar(props: SearchBarProps) { setIsactive(false) } } + if(props.onChangeText){ + props.onChangeText(text) + } + setText(text) } // cant apply the background color otherwise @@ -35,10 +43,10 @@ export default function SearchBar(props: SearchBarProps) { // changed styles.container to containerStyle return ( - + {isActive && - + {handleChange("")}}> }