Ei kuvausta

CommunityViewController.js 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. /**
  2. * Created by zack on 2018/4/19.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. Platform,
  9. ScrollView
  10. } from 'react-native'
  11. import React, {Component} from 'react'
  12. import BaseNavigationBar from '../base/BaseNavigationBar'
  13. import AnswerPageView from './Answer/AnswerPageView'
  14. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../utils/DimensionsTools'
  15. import FollowPageView from './Follow/FollowPageView'
  16. import SmallVideoViewController from "./SmallVideo/SmallVideoViewController"
  17. import HttpTools from '../../network/HttpTools'
  18. import {auth, question} from '../../network/API'
  19. import {GlobalUserStorageTool, UserStorageKey} from '../../utils/GlobalUserStorageTool'
  20. import {UserInfo} from '../../utils/GlobalKey'
  21. import PicAndTextPageView from './PicAndTextViewController/PicAndTextPageView'
  22. import BaseNavigationBarStyle from '../base/BaseNavigationBarStyle'
  23. import ShortVideoListControll from "./ShortVideo/ShortVideoListControll"
  24. export default class CommunityViewController extends Component {
  25. static navigatorButtons = {
  26. leftButtons: [
  27. {
  28. icon: require('../../resources/images/left.png'), // for icon button, provide the local image asset name
  29. id: 'add' //Android has four type of left button,you sure specify the button type.
  30. },
  31. ]
  32. };
  33. constructor(props) {
  34. super(props)
  35. this.state = {
  36. navigationBarMenu: [
  37. {title: '小视频', index: 0},
  38. {title: '短视频', index: 1},
  39. {title: '直播', index: 2},
  40. {title: '图文', index: 3},
  41. {title: '问答', index: 4},
  42. {title: '关注', index: 5},
  43. ],
  44. questionList: []
  45. }
  46. }
  47. componentDidMount() {
  48. this.props.navigator.setOnNavigatorEvent(event => {
  49. if (event.type === 'NavBarButtonPress') {
  50. if (event.id === 'add') {
  51. }
  52. }else if (event.type === 'ScreenChangedEvent') {
  53. if (event.id === 'willAppear') {
  54. this.showTabBar()
  55. }else if (event.id === 'willDisappear') {
  56. }
  57. }
  58. })
  59. this.getUserInfo(() => {
  60. })
  61. }
  62. getUserInfo(callback) {
  63. const param = JSON.stringify({
  64. username: '15303737970',
  65. password: '471155401'
  66. })
  67. HttpTools.postUserInfo(auth, param, (response) => {
  68. global.token = response.token
  69. GlobalUserStorageTool.save(UserInfo, response)
  70. callback && callback()
  71. }, (error) => {
  72. })
  73. }
  74. hideTabBar() {
  75. this.props.navigator.toggleTabs({
  76. to:'hidden',
  77. animated: true
  78. })
  79. }
  80. showTabBar() {
  81. this.props.navigator.toggleTabs({
  82. to:'shown',
  83. animated: true
  84. })
  85. }
  86. goToMinePage() {
  87. this.hideTabBar()
  88. GlobalUserStorageTool.load(UserStorageKey.UserInfo, (response) => {
  89. if (response && response.nickname) { //已经登录成功
  90. this.props.navigator.push({
  91. screen: 'MineViewController',
  92. title: '基本资料',
  93. backButtonTitle: '',
  94. navigatorStyle: BaseNavigationBarStyle,
  95. passProps: {
  96. UserInfo: response
  97. }
  98. })
  99. } else {
  100. this.props.navigator.push({
  101. screen: 'LoginViewController',
  102. title: '我的',
  103. backButtonTitle: '',
  104. navigatorStyle: {
  105. navBarHidden: true
  106. },
  107. passProps: {
  108. }
  109. })
  110. }
  111. }, (error) => {
  112. this.props.navigator.push({
  113. screen: 'LoginByVerificationCodeViewController',
  114. title: '我的',
  115. backButtonTitle: '',
  116. navigatorStyle: {
  117. navBarHidden: true
  118. },
  119. passProps: {
  120. }
  121. })
  122. })
  123. }
  124. didClickTagButton(index) {
  125. this.hideTabBar()
  126. if (index === 0) {
  127. if (Platform.OS === 'ios') {
  128. this.props.navigator.showModal({
  129. screen: 'QuestionCreateViewController',
  130. backButtonTitle: '',
  131. title: '提问',
  132. passProps: {
  133. },
  134. navigatorStyle: BaseNavigationBarStyle
  135. })
  136. }else {
  137. this.props.navigator.push({
  138. screen: 'QuestionCreateViewController',
  139. backButtonTitle: '',
  140. title: '提问',
  141. passProps: {
  142. },
  143. navigatorStyle: BaseNavigationBarStyle
  144. })
  145. }
  146. }else if (index === 1) {
  147. this.props.navigator.push({
  148. screen: 'FindViewController',
  149. backButtonTitle: '',
  150. passProps: {
  151. },
  152. navigatorStyle: BaseNavigationBarStyle
  153. })
  154. }else{
  155. this.props.navigator.push({
  156. screen: 'MoreViewController',
  157. backButtonTitle: '',
  158. passProps: {
  159. },
  160. navigatorStyle: BaseNavigationBarStyle
  161. })
  162. }
  163. }
  164. didClickUserHeaderView() {
  165. this.hideTabBar()
  166. this.props.navigator.push({
  167. screen: 'MyAnswerViewController',
  168. backButtonTitle: '',
  169. title: '回答',
  170. passProps: {
  171. },
  172. navigatorStyle: BaseNavigationBarStyle
  173. })
  174. }
  175. didClickFollowMoreButton() {
  176. let navigatorStyle = Object.assign({navBarHidden: true,}, BaseNavigationBarStyle)
  177. this.props.navigator.push({
  178. screen: 'FollowListViewController',
  179. backButtonTitle: '',
  180. title: '',
  181. passProps: {
  182. },
  183. navigatorStyle: navigatorStyle
  184. })
  185. }
  186. callSmallback(){
  187. this.hideTabBar()
  188. this.props.navigator.push({
  189. screen: 'VideoDetailsViewContorller',
  190. title: '',
  191. backButtonTitle: '',
  192. navigatorStyle:{
  193. navBarHidden: true,
  194. },
  195. passProps: {
  196. data:"hahaha"
  197. },
  198. })
  199. }
  200. didSelectedNavigationBarItem(index) {
  201. //点击导航器顶部的menu
  202. }
  203. //跳转到问题详情
  204. didSelectedQuestionItem(itemId) {
  205. this.hideTabBar()
  206. this.props.navigator.push({
  207. screen: 'AnswerDetailViewController',
  208. title: '问题详情',
  209. backButtonTitle: '',
  210. navigatorStyle:BaseNavigationBarStyle,
  211. passProps: {
  212. questionId: itemId
  213. },
  214. })
  215. }
  216. //跳转到图文详情
  217. didSelectedPicAndTextItem(itemId) {
  218. this.hideTabBar()
  219. this.props.navigator.push({
  220. screen: 'PicAndTextDetailViewController',
  221. backButtonTitle: '',
  222. navigatorStyle:{
  223. navBarHidden: true,
  224. drawUnderNavBar: true,
  225. drawUnderTabBar: true,
  226. },
  227. passProps: {
  228. itemId: itemId,
  229. },
  230. })
  231. }
  232. //跳转到图片查看器
  233. didClickImageViewContainer(imageUrls) {
  234. this.hideTabBar()
  235. this.props.navigator.push({
  236. screen: 'PicAndTextImageSwiperViewController',
  237. backButtonTitle: '',
  238. navigatorStyle:{
  239. navBarHidden: true,
  240. drawUnderNavBar: true,
  241. drawUnderTabBar: true,
  242. },
  243. passProps: {
  244. imageUrls: imageUrls
  245. },
  246. })
  247. }
  248. render() {
  249. return (
  250. <View style={styles.View}>
  251. <BaseNavigationBar
  252. dataSources = {this.state.navigationBarMenu}
  253. selectedIndex = {0}
  254. didClickedMineItem = {() => {
  255. this.goToMinePage()
  256. }}
  257. didSelectedItem = {(index) => [
  258. ]}
  259. />
  260. <ScrollView pagingEnabled={true} horizontal={true} style={styles.ScrollView}>
  261. <ShortVideoListControll/>
  262. <SmallVideoViewController callSmallback={()=>{
  263. this.callSmallback()
  264. }}/>
  265. <AnswerPageView
  266. didClickTagButton={(index) => {
  267. this.didClickTagButton(index)
  268. }}
  269. didClickUserHeaderView = {() => {
  270. this.didClickUserHeaderView()
  271. }}
  272. didSelectedItem = {(itemId) => {
  273. this.didSelectedQuestionItem(itemId)
  274. }}
  275. />
  276. <FollowPageView
  277. didClickFollowButton = {() => {
  278. this.didClickFollowMoreButton()
  279. }}
  280. />
  281. <PicAndTextPageView
  282. didSelectedPicAndTextItem = {(itemId) => {
  283. this.didSelectedPicAndTextItem(itemId)
  284. }}
  285. didClickImageViewContainer = {() => {
  286. this.didClickImageViewContainer()
  287. }}
  288. />
  289. </ScrollView>
  290. </View>
  291. );
  292. }
  293. }
  294. const styles = StyleSheet.create({
  295. View: {
  296. width: ScreenDimensions.width,
  297. height: ScreenDimensions.height,
  298. backgroundColor: 'white'
  299. },
  300. ScrollView: {
  301. marginTop: NavigationBarHeight.height,
  302. width: ScreenDimensions.width,
  303. height: ScreenDimensions.height - NavigationBarHeight.height - TabBarHeight.height,
  304. backgroundColor: '#ffffff',
  305. },
  306. })