TitleBar.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. import React, {Component} from 'react';
  2. import MenuPopWindow from '../views/PopupWindow';
  3. import Global from '../utils/Global';
  4. import {
  5. StyleSheet,
  6. Text,
  7. View,
  8. Image,
  9. Dimensions,
  10. TouchableOpacity,
  11. Button,
  12. Platform
  13. } from 'react-native';
  14. const {width, height} = Dimensions.get('window');
  15. export default class TitleBar extends Component {
  16. constructor(props) {
  17. super(props);
  18. this.state = {
  19. showPop: false,
  20. }
  21. }
  22. renderAndroid() {
  23. return (
  24. <View style={styles.titleBarContainer}>
  25. <View style={styles.titleBarTextContainer}>
  26. <Text style={styles.title}>RN微信</Text>
  27. </View>
  28. <View style={styles.titleBarButtonContainer}>
  29. <TouchableOpacity activeOpacity={0.5} onPress={this.handleSearchClick}>
  30. <Image
  31. source={require('../../images/ic_search.png')}
  32. style={styles.titleBarImg}
  33. />
  34. </TouchableOpacity>
  35. <TouchableOpacity activeOpacity={0.5} onPress={this.handleAddClick}>
  36. <Image
  37. source={require('../../images/ic_add.png')}
  38. style={styles.titleBarImg}
  39. />
  40. </TouchableOpacity>
  41. <View style={{position: 'absolute', top: 0, left: 0, width: width, height: height}}>
  42. <MenuPopWindow
  43. width={140}
  44. height={200}
  45. show={this.state.showPop}
  46. closeModal={(show) => {
  47. this.setState({showPop: show})
  48. }}
  49. menuIcons={[require('../../images/ic_pop_group_chat.png'), require('../../images/ic_pop_add_friends.png'), require('../../images/ic_pop_scan.png'),
  50. require('../../images/ic_pop_pay.png'), require('../../images/ic_pop_help.png')]}
  51. menuTexts={['发起群聊', '添加朋友', '扫一扫', '收付款', '帮助与反馈']}
  52. />
  53. </View>
  54. </View>
  55. </View>
  56. );
  57. }
  58. renderIOS() {
  59. return (
  60. <View style={{flexDirection: 'column'}}>
  61. <View style={{height: 20, backgroundColor: Global.titleBackgroundColor}}/>
  62. <View style={styles.titleBarContainer}>
  63. <View style={styles.titleBarTextContainer}>
  64. <Text style={styles.title}>RN微信</Text>
  65. </View>
  66. <View style={styles.titleBarButtonContainer}>
  67. <TouchableOpacity activeOpacity={0.5} onPress={this.handleSearchClick}>
  68. <Image
  69. source={require('../../images/ic_search.png')}
  70. style={styles.titleBarImg}
  71. />
  72. </TouchableOpacity>
  73. <TouchableOpacity activeOpacity={0.5} onPress={this.handleAddClick}>
  74. <Image
  75. source={require('../../images/ic_add.png')}
  76. style={styles.titleBarImg}
  77. />
  78. </TouchableOpacity>
  79. <View style={{position: 'absolute', top: 100, left: 0, width: width, height: height}}>
  80. <MenuPopWindow
  81. width={140}
  82. height={200}
  83. show={this.state.showPop}
  84. closeModal={(show) => {
  85. this.setState({showPop: show})
  86. }}
  87. menuIcons={[require('../../images/ic_pop_group_chat.png'), require('../../images/ic_pop_add_friends.png'), require('../../images/ic_pop_scan.png'),
  88. require('../../images/ic_pop_pay.png'), require('../../images/ic_pop_help.png')]}
  89. menuTexts={['发起群聊', '添加朋友', '扫一扫', '收付款', '帮助与反馈']}
  90. />
  91. </View>
  92. </View>
  93. </View>
  94. </View>
  95. );
  96. }
  97. render() {
  98. if (Platform.OS === 'ios') {
  99. return this.renderIOS();
  100. }
  101. return this.renderAndroid();
  102. }
  103. handleSearchClick = () => {
  104. // 跳转到SearchScreen界面
  105. this.props.nav.navigate('Search');
  106. }
  107. handleAddClick = () => {
  108. this.setState({showPop: !this.state.showPop});
  109. }
  110. }
  111. class CustomModal extends Component {
  112. constructor(props) {
  113. super(props);
  114. this.state = {
  115. modalVisible: false,
  116. }
  117. }
  118. render() {
  119. return (
  120. <Modal
  121. animationType={"fade"}
  122. transparent={true}
  123. visible={this.state.modalVisible}
  124. onRequestClose={() => {
  125. alert("Modal has been closed.")
  126. }}>
  127. <View style={modalStyle.container}>
  128. <View style={modalStyle.content}>
  129. <Text>Hello World! This is a Modal!</Text>
  130. <Button
  131. style={{marginTop: 20}}
  132. title={"Close"}
  133. onPress={() => {
  134. this.setState({modalVisible: false})
  135. }}/>
  136. </View>
  137. </View>
  138. </Modal>
  139. );
  140. }
  141. closeModel = () => {
  142. this.setState({modalVisible: false});
  143. }
  144. openModal() {
  145. this.setState({modalVisible: true});
  146. }
  147. }
  148. const modalStyle = StyleSheet.create({
  149. container: {
  150. flex: 1,
  151. flexDirection: 'column',
  152. justifyContent: 'center',
  153. alignItems: 'center',
  154. backgroundColor: 'rgba(0, 0, 0, 0.5)'
  155. },
  156. content: {
  157. width: width - 40,
  158. flexDirection: 'column',
  159. justifyContent: 'center',
  160. alignItems: 'center',
  161. marginLeft: 20,
  162. marginRight: 20,
  163. backgroundColor: '#FFFFFF',
  164. height: 100,
  165. borderRadius: 5,
  166. paddingTop: 10,
  167. paddingBottom: 10,
  168. paddingLeft: 10,
  169. paddingRight: 10,
  170. }
  171. });
  172. const styles = StyleSheet.create({
  173. titleBarContainer: {
  174. flexDirection: 'row',
  175. width: width,
  176. height: 50,
  177. backgroundColor: Global.titleBackgroundColor
  178. },
  179. titleBarTextContainer: {
  180. flex: 1,
  181. flexDirection: 'row',
  182. alignItems: 'center',
  183. paddingLeft: 10,
  184. paddingRight: 10,
  185. },
  186. titleBarButtonContainer: {
  187. alignItems: 'center',
  188. flexDirection: 'row',
  189. paddingLeft: 10,
  190. paddingRight: 10,
  191. },
  192. title: {
  193. color: '#FFFFFF',
  194. fontSize: 18,
  195. fontWeight: 'bold',
  196. },
  197. titleBarImg: {
  198. width: 25,
  199. height: 25,
  200. marginLeft: 15,
  201. marginRight: 15,
  202. }
  203. });