SearchBar.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { Colors } from "@/constants/Colors";
  2. import { Images } from "@/constants/images";
  3. import { Image } from "expo-image";
  4. import React, { useState } from "react";
  5. import {
  6. StyleSheet,
  7. Text,
  8. TextInput,
  9. TouchableOpacity,
  10. View,
  11. } from "react-native";
  12. interface SearchBarProps {
  13. onSearch?: (keyword: string) => void;
  14. }
  15. export function SearchBar({ onSearch }: SearchBarProps) {
  16. const [keyword, setKeyword] = useState("");
  17. const handleSearch = () => {
  18. onSearch?.(keyword);
  19. };
  20. return (
  21. <View style={styles.container}>
  22. {/* Logo Area */}
  23. <View style={styles.logo}>
  24. {/* Use text logo for now to ensure theme match */}
  25. <Text style={styles.logoText}>
  26. CYBER<Text style={styles.logoTextHighlight}>MART</Text>
  27. </Text>
  28. </View>
  29. {/* Search Box */}
  30. <View style={styles.searchBox}>
  31. <TouchableOpacity onPress={handleSearch}>
  32. {/* Tint the search icon */}
  33. <Image
  34. source={Images.home.search}
  35. style={styles.searchIcon}
  36. contentFit="contain"
  37. tintColor={Colors.neonBlue}
  38. />
  39. </TouchableOpacity>
  40. <TextInput
  41. style={styles.input}
  42. placeholder="搜索装备..."
  43. placeholderTextColor={Colors.textTertiary}
  44. value={keyword}
  45. onChangeText={setKeyword}
  46. onSubmitEditing={handleSearch}
  47. returnKeyType="search"
  48. />
  49. </View>
  50. </View>
  51. );
  52. }
  53. const styles = StyleSheet.create({
  54. container: {
  55. flexDirection: "row",
  56. alignItems: "center",
  57. paddingHorizontal: 15,
  58. paddingVertical: 10,
  59. backgroundColor: Colors.darkBg, // Ensure bg matches
  60. },
  61. logo: {
  62. marginRight: 20,
  63. justifyContent: "center",
  64. },
  65. logoText: {
  66. color: "#fff",
  67. fontWeight: "bold",
  68. fontSize: 18,
  69. fontStyle: "italic",
  70. },
  71. logoTextHighlight: {
  72. color: Colors.neonBlue,
  73. },
  74. searchBox: {
  75. flex: 1, // Take remaining width
  76. flexDirection: "row",
  77. alignItems: "center",
  78. backgroundColor: "rgba(255, 255, 255, 0.05)",
  79. borderRadius: 20,
  80. paddingHorizontal: 12,
  81. height: 36,
  82. borderWidth: 1,
  83. borderColor: "rgba(0, 243, 255, 0.3)", // Neon border
  84. },
  85. searchIcon: {
  86. width: 16,
  87. height: 16,
  88. marginRight: 8,
  89. },
  90. input: {
  91. flex: 1,
  92. color: Colors.textPrimary,
  93. fontSize: 14,
  94. padding: 0,
  95. },
  96. });