SearchBar.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { Images } from '@/constants/images';
  2. import { Image } from 'expo-image';
  3. import React, { useState } from 'react';
  4. import { StyleSheet, TextInput, TouchableOpacity, View } from 'react-native';
  5. interface SearchBarProps {
  6. onSearch?: (keyword: string) => void;
  7. }
  8. export function SearchBar({ onSearch }: SearchBarProps) {
  9. const [keyword, setKeyword] = useState('');
  10. const handleSearch = () => {
  11. onSearch?.(keyword);
  12. };
  13. return (
  14. <View style={styles.container}>
  15. {/* Logo - 134rpx = 67pt, 50rpx = 25pt */}
  16. <View style={styles.logo}>
  17. <Image source={Images.home.portrait} style={styles.logoImage} contentFit="contain" />
  18. </View>
  19. {/* 搜索框 - 328rpx = 164pt, 56rpx = 28pt */}
  20. <View style={styles.searchBox}>
  21. <TouchableOpacity onPress={handleSearch}>
  22. <Image source={Images.home.search} style={styles.searchIcon} contentFit="contain" />
  23. </TouchableOpacity>
  24. <TextInput
  25. style={styles.input}
  26. placeholder="搜索"
  27. placeholderTextColor="#C4C3C3"
  28. value={keyword}
  29. onChangeText={setKeyword}
  30. onSubmitEditing={handleSearch}
  31. returnKeyType="search"
  32. />
  33. </View>
  34. </View>
  35. );
  36. }
  37. const styles = StyleSheet.create({
  38. container: {
  39. flexDirection: 'row',
  40. alignItems: 'center',
  41. paddingHorizontal: 15,
  42. paddingVertical: 10,
  43. },
  44. logo: {
  45. width: 67,
  46. height: 25,
  47. marginRight: 20,
  48. },
  49. logoImage: {
  50. width: '100%',
  51. height: '100%',
  52. },
  53. searchBox: {
  54. flexDirection: 'row',
  55. alignItems: 'center',
  56. justifyContent: 'center',
  57. backgroundColor: 'rgba(255,255,255,0.38)',
  58. borderRadius: 180,
  59. paddingHorizontal: 12,
  60. height: 28,
  61. width: 164,
  62. },
  63. searchIcon: {
  64. width: 15,
  65. height: 15,
  66. marginRight: 5,
  67. },
  68. input: {
  69. width: 100,
  70. color: '#fff',
  71. fontSize: 12,
  72. padding: 0,
  73. },
  74. });