ContactDetailScreen.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import React, {Component} from 'react';
  2. import CommonTitleBar from '../views/CommonTitleBar';
  3. import CommonLoadingView from '../views/CommonLoadingView';
  4. import ListItemDivider from '../views/ListItemDivider';
  5. import Global from '../utils/Global';
  6. import StorageUtil from '../utils/StorageUtil';
  7. import {Dimensions, Image, ScrollView, StyleSheet, Text, TouchableOpacity, View} from 'react-native';
  8. const {width} = Dimensions.get('window');
  9. export default class ContactDetailScreen extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = {
  13. loadingState: Global.loading,
  14. };
  15. // 聊天人的信息
  16. this.userInfo = this.props.navigation.state.params.data;
  17. StorageUtil.get('username', (error, object) => {
  18. if (!error && object != null) {
  19. this.setState({loginUsername: object.username, loadingState: Global.loadSuccess});
  20. }
  21. })
  22. }
  23. render() {
  24. switch (this.state.loadingState) {
  25. case Global.loading:
  26. return this.renderLoadingView();
  27. case Global.loadSuccess:
  28. return this.renderDetailView();
  29. case Global.loadError:
  30. return this.renderErrorView();
  31. }
  32. }
  33. renderLoadingView() {
  34. return (
  35. <View style={styles.container}>
  36. <CommonTitleBar nav={this.props.navigation} title={""}/>
  37. <View style={styles.content}>
  38. <CommonLoadingView hintText={"正在获取联系人数据..."}/>
  39. </View>
  40. </View>
  41. );
  42. }
  43. renderErrorView() {
  44. return (
  45. <View style={styles.container}>
  46. <CommonTitleBar nav={this.props.navigation} title={""}/>
  47. <TouchableOpacity style={styles.content} activeOpacity={0.6} onPress={() => this.getUserInfo()}>
  48. <View style={[styles.content, {justifyContent: 'center', alignItems: 'center'}]}>
  49. <Text style={{fontSize: 17, color: '#999999'}}>加载用户数据失败</Text>
  50. <Text style={{fontSize: 17, color: '#999999', marginTop: 5}}>点击屏幕重试</Text>
  51. </View>
  52. </TouchableOpacity>
  53. </View>
  54. );
  55. }
  56. renderDetailView() {
  57. return (
  58. <View style={styles.container}>
  59. <CommonTitleBar nav={this.props.navigation} title={this.props.navigation.state.params.title}/>
  60. <ScrollView>
  61. <View style={styles.content}>
  62. <View style={styles.contactInfoContainer}>
  63. <Image style={styles.avatar} source={this.userInfo.icon}/>
  64. <View style={styles.contactInfoTextContainer}>
  65. <Text style={styles.contactNameText}>{this.userInfo.title}</Text>
  66. <Text style={styles.conatactNickNameText}>{"昵称:" + this.userInfo.nick}</Text>
  67. </View>
  68. </View>
  69. <View style={styles.markContainer}>
  70. <Text style={[styles.markText]}>设置备注和标签</Text>
  71. </View>
  72. <View style={styles.bottomContainer}>
  73. <View style={styles.regionContainer}>
  74. <Text style={[styles.commonFontStyle]}>地区</Text>
  75. <Text style={styles.regionText}>湖北 武汉</Text>
  76. </View>
  77. <ListItemDivider/>
  78. <View style={styles.galleryContainer}>
  79. <Text style={[styles.commonFontStyle]}>个人相册</Text>
  80. <Image style={styles.galleryImg} source={require('../../images/avatar.png')}/>
  81. <Image style={styles.galleryImg} source={require('../../images/avatar.png')}/>
  82. <Image style={styles.galleryImg} source={require('../../images/avatar.png')}/>
  83. </View>
  84. <ListItemDivider/>
  85. <View style={styles.moreContainer}>
  86. <Text style={[styles.commonFontStyle]}>更多</Text>
  87. </View>
  88. </View>
  89. {
  90. this.state.loginUsername == this.userInfo.title ? (null) : (
  91. <View>
  92. <TouchableOpacity activeOpacity={0.5} onPress={() => {
  93. this.startChat()
  94. }}>
  95. <View style={styles.positiveBtn}>
  96. <Text style={styles.positiveBtnText}>发消息</Text>
  97. </View>
  98. </TouchableOpacity>
  99. <TouchableOpacity activeOpacity={0.5}>
  100. <View style={styles.normalBtn}>
  101. <Text style={styles.normalBtnText}>视频聊天</Text>
  102. </View>
  103. </TouchableOpacity>
  104. </View>
  105. )
  106. }
  107. </View>
  108. </ScrollView>
  109. </View>
  110. );
  111. }
  112. startChat() {
  113. this.props.navigation.navigate('Chatting', {'contactId': this.userInfo.title, 'name': this.userInfo.nick});
  114. }
  115. }
  116. const styles = StyleSheet.create({
  117. container: {
  118. flex: 1,
  119. flexDirection: 'column',
  120. backgroundColor: Global.pageBackgroundColor,
  121. },
  122. content: {
  123. flex: 1,
  124. flexDirection: 'column',
  125. },
  126. contactInfoContainer: {
  127. backgroundColor: '#FFFFFF',
  128. flexDirection: 'row',
  129. paddingLeft: 15,
  130. paddingRight: 15,
  131. paddingTop: 10,
  132. paddingBottom: 10,
  133. marginTop: 20,
  134. },
  135. avatar: {
  136. width: 65,
  137. height: 65,
  138. },
  139. contactInfoTextContainer: {
  140. flexDirection: 'column',
  141. paddingLeft: 15,
  142. paddingRight: 15,
  143. },
  144. contactNameText: {
  145. color: '#000000',
  146. fontSize: 16,
  147. },
  148. conatactNickNameText: {
  149. color: '#999999',
  150. marginTop: 5,
  151. fontSize: 14,
  152. },
  153. markContainer: {
  154. backgroundColor: '#FFFFFF',
  155. padding: 15,
  156. marginTop: 20,
  157. },
  158. regionContainer: {
  159. padding: 15,
  160. flexDirection: 'row',
  161. alignItems: 'center',
  162. },
  163. galleryContainer: {
  164. padding: 15,
  165. flexDirection: 'row',
  166. alignItems: 'center',
  167. },
  168. moreContainer: {
  169. padding: 15,
  170. flexDirection: 'row',
  171. alignItems: 'center',
  172. },
  173. markText: {
  174. color: '#000000',
  175. fontSize: 16,
  176. },
  177. regionText: {
  178. fontSize: 14,
  179. color: '#999999'
  180. },
  181. bottomContainer: {
  182. backgroundColor: '#FFFFFF',
  183. marginTop: 20,
  184. },
  185. commonFontStyle: {
  186. color: '#000000',
  187. fontSize: 16,
  188. width: width / 4,
  189. },
  190. galleryImg: {
  191. width: 60,
  192. height: 60,
  193. marginLeft: 5,
  194. marginRight: 5,
  195. },
  196. positiveBtn: {
  197. backgroundColor: '#19AD17',
  198. justifyContent: 'center',
  199. alignItems: 'center',
  200. borderRadius: 5,
  201. marginLeft: 15,
  202. marginRight: 15,
  203. marginTop: 15,
  204. height: 50,
  205. },
  206. positiveBtnText: {
  207. fontSize: 16,
  208. color: '#FFFFFF'
  209. },
  210. normalBtn: {
  211. backgroundColor: '#F8F8F8',
  212. justifyContent: 'center',
  213. alignItems: 'center',
  214. borderRadius: 5,
  215. marginLeft: 15,
  216. marginRight: 15,
  217. marginTop: 15,
  218. height: 50,
  219. },
  220. normalBtnText: {
  221. fontSize: 16,
  222. color: '#000000'
  223. }
  224. });