import { faArrowLeft, faSearch } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-native-fontawesome"; import { useIsFocused, useNavigation } from "@react-navigation/native"; import React, { useEffect, useRef, useState } from "react"; import { Image, KeyboardAvoidingView, StyleSheet, TextInput, TouchableOpacity, View, } from "react-native"; import obn from "../../../assets/obn.png"; const SearchHeader = ({ unfocus, searchProduct, cat }) => { const [searchKeyword, setsearchKeyword] = useState(""); const navigation = useNavigation(); const isFocused = useIsFocused(); useEffect(() => { setsearchKeyword(cat); // searchProduct(searchKeyword); }, [isFocused]); console.log(searchKeyword); const Search = (e) => { setsearchKeyword(e); }; const textInputRef = useRef(null); useEffect(() => { focusTextInput(); }, []); useEffect(() => { unfocusTextInput(); }, [unfocus]); const focusTextInput = () => { if (textInputRef.current) { textInputRef.current.focus(); } }; const unfocusTextInput = () => { if (textInputRef.current) { textInputRef.current.blur(); } }; return ( navigation.navigate("Home")} style={styles.backIcon} > Search(e)} defaultValue={cat ?? ""} onSubmitEditing={() => searchProduct(searchKeyword)} /> searchProduct(searchKeyword)} style={styles.backIcon} > ); }; const styles = StyleSheet.create({ container: { // flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center", width: "100%", // top: 0, // position: "fixed", paddingVertical: 15, paddingTop: 5, // height:80 // boxShadow: '0px 0px 4px 0px rgba(0, 0, 0, 0.25)' }, wrapper: { flexDirection: "row", width: "95%", alignItems: "center", justifyContent: "space-around", margin: "auto", }, button: { padding: 15, }, imgLogo: { height: 30, width: 30, }, input: { backgroundColor: "#f5f5f5dd", padding: 10, paddingHorizontal: 20, borderRadius: 10, width: "70%", }, }); export default SearchHeader;