YRSearchBar.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React from 'react';
  2. import {
  3. Keyboard,
  4. Image,
  5. Text,
  6. TextInput,
  7. TouchableOpacity,
  8. View,
  9. StyleSheet,
  10. ScrollView,
  11. RefreshControl
  12. } from "react-native"
  13. let Dimensions = require('Dimensions');
  14. let screenWidth = Dimensions.get('window').width;
  15. /*自定义搜索框组件*/
  16. class YRSearchBar extends React.Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. inputValue: ""
  21. };
  22. }
  23. onStartSearch = (onSearch) => {
  24. Keyboard.dismiss();
  25. onSearch(this.refs.keyWordInput.props.value);
  26. }
  27. render() {
  28. let {placeholder, onSearchChangeText, value, onSearch} = this.props;
  29. return <View style={styles.searchContainer}>
  30. <View style={styles.search}>
  31. <Image source={require('../../assets/images/icon_find.png')}
  32. style={{width: 18 ,height: 18}}></Image>
  33. <TextInput underlineColorAndroid="transparent"
  34. placeholder={placeholder}
  35. style={styles.searchInput}
  36. onChangeText={onSearchChangeText}
  37. value={value}
  38. ref="keyWordInput"
  39. onSubmitEditing={this.onStartSearch.bind(this, onSearch)}>
  40. </TextInput>
  41. <TouchableOpacity
  42. onPress={this.onStartSearch.bind(this, onSearch)}
  43. style={styles.searchView}>
  44. <Text style={{color: '#0391ff', fontSize: 14}}>搜索</Text>
  45. </TouchableOpacity>
  46. </View>
  47. </View>
  48. }
  49. }
  50. const styles = StyleSheet.create({
  51. searchContainer: {
  52. paddingRight: 15,
  53. paddingLeft: 15,
  54. paddingTop: 10,
  55. paddingBottom: 10,
  56. backgroundColor: "#F8F8F8"
  57. },
  58. search: {
  59. height: 32,
  60. backgroundColor: "#ffffff",
  61. borderRadius: 10,
  62. borderWidth: 1,
  63. borderColor: "#E0E0E0",
  64. paddingLeft: 10,
  65. flexDirection: 'row',
  66. alignItems: 'center'
  67. },
  68. searchInput: {
  69. marginLeft: 10,
  70. width: screenWidth * 7 / 10,
  71. height: 30,
  72. padding: 0,
  73. fontSize: 14,
  74. },
  75. searchView: {
  76. justifyContent: "flex-end",
  77. }
  78. });
  79. export default YRSearchBar;