SearchTitleBar.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import React, {Component} from 'react';
  2. import Global from '../utils/Global';
  3. import {
  4. Button,
  5. Dimensions,
  6. Image,
  7. PixelRatio,
  8. StatusBar,
  9. StyleSheet,
  10. TextInput,
  11. TouchableOpacity,
  12. View,
  13. Platform
  14. } from 'react-native';
  15. const {width} = Dimensions.get('window');
  16. export default class SearchTitleBar extends Component {
  17. constructor(props) {
  18. super(props);
  19. this.state = {
  20. inputContent: ''
  21. }
  22. }
  23. renderAndroid() {
  24. return (
  25. <View style={styles.container}>
  26. <StatusBar
  27. backgroundColor='#393A3E'
  28. barStyle="light-content"
  29. />
  30. <View style={styles.content}>
  31. <TouchableOpacity activeOpacity={0.5} onPress={this.handleBackClick}>
  32. <Image source={require('../../images/ic_back.png')} style={styles.backBtn}/>
  33. </TouchableOpacity>
  34. <View style={styles.btnDivider}/>
  35. <View style={styles.inputContainer}>
  36. <View style={styles.inputSubContainer}>
  37. <Image source={require('../../images/ic_search_bar_search.png')} style={styles.icon}/>
  38. <TextInput onChangeText={(text) => {
  39. this.setState({inputContent: text})
  40. }} style={styles.textInput} underlineColorAndroid="transparent"/>
  41. <Button onPress={() => {
  42. this.props.handleSearchClick(this.state.inputContent)
  43. }} color={'#49BC1C'} title={"搜索"}/>
  44. </View>
  45. <View style={styles.inputLine}/>
  46. </View>
  47. </View>
  48. </View>
  49. );
  50. }
  51. renderIOS() {
  52. return (
  53. <View style={styles.container}>
  54. <View style={{height: 20, backgroundColor: Global.titleBackgroundColor}}/>
  55. <View style={styles.content}>
  56. <TouchableOpacity activeOpacity={0.5} onPress={this.handleBackClick}>
  57. <Image source={require('../../images/ic_back.png')} style={styles.backBtn}/>
  58. </TouchableOpacity>
  59. <View style={styles.btnDivider}/>
  60. <View style={styles.inputContainer}>
  61. <View style={styles.inputSubContainer}>
  62. <Image source={require('../../images/ic_search_bar_search.png')} style={styles.icon}/>
  63. <TextInput onChangeText={(text) => {
  64. this.setState({inputContent: text})
  65. }} style={styles.textInput} underlineColorAndroid="transparent"/>
  66. <Button onPress={() => {
  67. this.props.handleSearchClick(this.state.inputContent)
  68. }} color={'#49BC1C'} title={"搜索"}/>
  69. </View>
  70. <View style={styles.inputLine}/>
  71. </View>
  72. </View>
  73. </View>
  74. );
  75. }
  76. render() {
  77. if (Platform.OS === 'ios') {
  78. return this.renderIOS();
  79. }
  80. return this.renderAndroid();
  81. }
  82. handleBackClick = () => {
  83. this.props.nav.goBack();
  84. }
  85. }
  86. const styles = StyleSheet.create({
  87. container: {
  88. flexDirection: 'column',
  89. },
  90. content: {
  91. width: width,
  92. height: 50,
  93. backgroundColor: Global.titleBackgroundColor,
  94. flexDirection: 'row',
  95. alignItems: 'center'
  96. },
  97. backBtn: {
  98. marginLeft: 10,
  99. marginRight: 10,
  100. width: 30,
  101. height: 30,
  102. },
  103. btnDivider: {
  104. width: 1 / PixelRatio.get(),
  105. height: 30,
  106. marginTop: 10,
  107. marginBottom: 10,
  108. backgroundColor: '#888888'
  109. },
  110. inputContainer: {
  111. flexDirection: 'column',
  112. flex: 1,
  113. paddingLeft: 10,
  114. paddingRight: 10,
  115. },
  116. inputSubContainer: {
  117. flexDirection: 'row',
  118. alignItems: 'center',
  119. },
  120. inputLine: {
  121. height: 1,
  122. backgroundColor: '#49BC1C'
  123. },
  124. icon: {
  125. width: 30,
  126. height: 30,
  127. },
  128. textInput: {
  129. padding: 0,
  130. flex: 1,
  131. color: '#FFFFFF'
  132. },
  133. });