Ei kuvausta

ChatViewController.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * Created by zack on 2018/4/19.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. Image,
  9. TouchableOpacity,
  10. } from 'react-native'
  11. import React, {Component} from 'react'
  12. import BaseNavigationBar from '../base/BaseNavigationBar'
  13. import {GlobalUserStorageTool, UserStorageKey} from '../../utils/GlobalUserStorageTool'
  14. import BaseNavigationBarStyle from '../base/BaseNavigationBarStyle'
  15. import {heightPxToDp,widthPxToDp,deviceWidth} from '../../utils/ScreenUtils'
  16. import _const from '../../const/_const'
  17. import ChatMainTopLayout from './chatTopLayout'
  18. import ChatRoomList from "./tabPages/chatRoomList";
  19. import ChatUtil from '../../utils/ChatUtils'
  20. export default class ChatViewController extends Component {
  21. constructor(props) {
  22. super(props)
  23. this.state = {
  24. navigationBarMenu: [
  25. {title: '聊吧', index: 0},
  26. {title: '找群', index: 1},
  27. {title: '找同学', index: 2},
  28. {title: '找老师', index: 3},
  29. {title: '联系人', index: 4},
  30. ],
  31. currentIndex:0,
  32. }
  33. }
  34. componentDidMount() {
  35. ChatUtil.connect().then(res=>{
  36. console.log('chat:::::',res)
  37. ChatUtil.setSession().then(result=>{
  38. console.log('sid:::',result)
  39. })
  40. }
  41. ).catch(err=>{console.warn(err)})
  42. console.log(GlobalUserStorageTool.load(UserStorageKey.UserInfo,(res)=>{console.log(res)},(err)=>{console.log(err)}))
  43. this.props.navigator.setOnNavigatorEvent(event => {
  44. if (event.type === 'NavBarButtonPress') {
  45. }else if (event.type === 'ScreenChangedEvent') {
  46. if (event.id === 'willAppear') {
  47. this.showTabBar()
  48. }else if (event.id === 'willDisappear') {
  49. }
  50. }
  51. })
  52. }
  53. hideTabBar() {
  54. this.props.navigator.toggleTabs({
  55. to:'hidden',
  56. animated: true
  57. })
  58. }
  59. showTabBar() {
  60. this.props.navigator.toggleTabs({
  61. to:'shown',
  62. animated: true
  63. })
  64. }
  65. goToMinePage() {
  66. this.hideTabBar()
  67. GlobalUserStorageTool.load(UserStorageKey.UserInfo, (response) => {
  68. if (response && response.nickname) { //已经登录成功
  69. this.props.navigator.push({
  70. screen: 'MineViewController',
  71. title: '基本资料',
  72. backButtonTitle: '',
  73. navigatorStyle: BaseNavigationBarStyle,
  74. passProps: {
  75. UserInfo: response
  76. }
  77. })
  78. } else {
  79. this.props.navigator.push({
  80. screen: 'LoginViewController',
  81. title: '我的',
  82. backButtonTitle: '',
  83. navigatorStyle: {
  84. navBarHidden: true
  85. },
  86. passProps: {
  87. }
  88. })
  89. }
  90. }, (error) => {
  91. this.props.navigator.push({
  92. screen: 'LoginByVerificationCodeViewController',
  93. title: '我的',
  94. backButtonTitle: '',
  95. navigatorStyle: {
  96. navBarHidden: true
  97. },
  98. passProps: {
  99. }
  100. })
  101. })
  102. }
  103. getPage=()=>{
  104. const currentIndex=this.state.currentIndex
  105. switch (currentIndex){
  106. case 0:
  107. return <ChatRoomList/>
  108. case 1:
  109. return <View>
  110. <Text>1</Text>
  111. </View>
  112. case 2:
  113. return <View>
  114. <Text>2</Text>
  115. </View>
  116. case 3:
  117. return <View>
  118. <Text>3</Text>
  119. </View>
  120. case 4:
  121. return <View>
  122. <Text>4</Text>
  123. </View>
  124. }
  125. }
  126. render() {
  127. return (
  128. <View style={{flex: 1, alignItems: 'center'}}>
  129. <BaseNavigationBar
  130. dataSources = {this.state.navigationBarMenu}
  131. selectedIndex = {this.state.currentIndex}
  132. didClickedMineItem = {() => {
  133. this.goToMinePage()
  134. }}
  135. didSelectedItem = {(index) => {
  136. this.setState({currentIndex:index})
  137. }}
  138. />
  139. {this.getPage()}
  140. </View>
  141. );
  142. }
  143. }