No Description

PicAndTextDetailViewController.js 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /**
  2. * Created by zack on 2018/5/22.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. Platform,
  9. ScrollView,
  10. FlatList,
  11. Image,
  12. TouchableOpacity
  13. } from 'react-native'
  14. import React, {Component} from 'react'
  15. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools'
  16. import BaseNavigationBarStyle from '../../base/BaseNavigationBarStyle'
  17. import PicAndTextNavigationBar from './View/PicAndTextNavigationBar'
  18. import PicAndTextDetailHeaderItem from './View/PicAndTextDetailHeaderItem'
  19. import PicAndTextDetailCommentItem from './View/PicAndTextDetailCommentItem'
  20. import HttpTools from '../../../network/HttpTools'
  21. import {auth, question, imgText, comment} from '../../../network/API'
  22. export default class PicAndTextDetailViewController extends Component {
  23. constructor(props) {
  24. super(props)
  25. this.state = {
  26. title: props.title,
  27. commentCount: 0,
  28. commentId: props.commentId,
  29. itemId: props.itemId,
  30. dataSources: [],
  31. userIcon: '',
  32. picItemUserName: '',
  33. }
  34. }
  35. componentDidMount() {
  36. this.getPicAndTextDetail()
  37. }
  38. createPicAndTextComment(modeId) {
  39. const param = JSON.stringify({
  40. content: "comment content",
  41. model_id: modeId,
  42. model_type: "img_txt",
  43. related_id: ""
  44. })
  45. HttpTools.post(comment, param, (response) => {
  46. console.log(response)
  47. }, (error) => {
  48. console.log(error)
  49. })
  50. }
  51. getPicAndTextDetail() {
  52. let url = imgText + '/' + this.state.itemId
  53. HttpTools.get(url, {}, (response) => {
  54. let headerItem = Object.assign({key: 0}, response)
  55. this.setState({picItemUserName: response.user_name ,userIcon: response.user_avatar,dataSources: [headerItem, {key: 1,}]})
  56. this.getPicAndTextCommentList()
  57. }, (error) => {
  58. })
  59. }
  60. getPicAndTextCommentList() {
  61. const param = {
  62. model_id: this.state.itemId,
  63. model_type: 'img_txt',
  64. }
  65. HttpTools.get(comment, param, (response) => {
  66. if (response && response.length) {
  67. let commentListWithIndex = response.map((item, index) => {
  68. return Object.assign(item, {key: index + 2})
  69. })
  70. this.setState({
  71. dataSources: this.state.dataSources.concat(commentListWithIndex),
  72. commentCount: commentListWithIndex.length,
  73. })
  74. }
  75. }, (error) => {
  76. })
  77. }
  78. didClickBottomButton(index) {
  79. if (index === 0) { //send message
  80. }else if (index === 1){// star
  81. }else if (index === 2) { //forward
  82. }else if (index === 3) { //add comment
  83. // this.props.navigator.showModal({
  84. // screen: 'QuestionCreateViewController',
  85. // title: '提问',
  86. // backButtonTitle: '',
  87. // passProps: {
  88. // questionName: '如何学习英语?'
  89. // },
  90. // navigatorStyle: BaseNavigationBarStyle
  91. // })
  92. this.createPicAndTextComment(this.state.itemId)
  93. }
  94. }
  95. didClickImageViewContainer(imageUrls) {
  96. this.props.navigator.push({
  97. screen: 'PicAndTextImageSwiperViewController',
  98. backButtonTitle: '',
  99. navigatorStyle:{
  100. navBarHidden: true,
  101. drawUnderNavBar: true,
  102. drawUnderTabBar: true,
  103. },
  104. passProps: {
  105. imageUrls: imageUrls
  106. },
  107. })
  108. }
  109. renderItem(item) {
  110. const index = item.key
  111. if (index === 0) {
  112. return(
  113. <PicAndTextDetailHeaderItem
  114. imageUrls = {item.urls}
  115. title = {item.text}
  116. didClickImageViewContainer = {() => {
  117. this.didClickImageViewContainer([])
  118. }}
  119. />
  120. )
  121. }else if (index === 1) {
  122. return(
  123. <View style={{width: ScreenDimensions.width, height: 40, backgroundColor: 'white', alignItems: 'center', flexDirection: 'row'}}>
  124. <Text style={{marginLeft: 23,}}>{this.state.commentCount + '条评论'}</Text>
  125. <View style={{ width: ScreenDimensions.width, height: 0.5, backgroundColor: '#efeff4', position: 'absolute', left: 0, bottom: 0}} />
  126. </View>
  127. )
  128. }else{
  129. return(
  130. <PicAndTextDetailCommentItem
  131. title = {item.content}
  132. userName = {item.user_name}
  133. userIcon = {item.user_avatar}
  134. commentCount = {item.comment_count}
  135. likes = {item.likes}
  136. shares = {item.shares}
  137. isLiked = {item.is_liked}
  138. />
  139. )
  140. }
  141. }
  142. render() {
  143. return(
  144. <View style={styles.View}>
  145. <PicAndTextNavigationBar
  146. userIcon = {this.state.userIcon}
  147. userName = {this.state.picItemUserName}
  148. didClickLeftButton = {() => {
  149. this.props.navigator.pop()
  150. }}
  151. />
  152. <View style={styles.ListView}>
  153. <FlatList
  154. data = {this.state.dataSources}
  155. renderItem={({item}) => this.renderItem(item)}
  156. keyExtractor = {(item,index) =>{
  157. return 'key' + item.key + index
  158. }}
  159. ListFooterComponent = {() => {
  160. return(
  161. <View style={{width: ScreenDimensions.width, height: 44, backgroundColor: 'white'}} />
  162. )
  163. }}
  164. />
  165. </View>
  166. <View style={styles.BottomBgView}>
  167. <TouchableOpacity onPress={() => {
  168. this.didClickBottomButton(3)
  169. }} style={styles.InputBgView}>
  170. <Image style={styles.PenImageView} source={require('../../../resources/images/TabBar/PicAndText/pen.png')}/>
  171. <Text style={styles.PlaceHolder}>{'写评论...'}</Text>
  172. <Image style={styles.EmojiImageView} source={require('../../../resources/images/TabBar/PicAndText/Express.png')}/>
  173. </TouchableOpacity>
  174. <View style={styles.RightIconsBgView}>
  175. <TouchableOpacity onPress={() => {
  176. this.didClickBottomButton(0)
  177. }} style={{marginRight: 30}}>
  178. <Image source={require('../../../resources/images/TabBar/PicAndText/mess.png')}/>
  179. </TouchableOpacity>
  180. <TouchableOpacity onPress={() => {
  181. this.didClickBottomButton(1)
  182. }} style={{marginRight: 30}}>
  183. <Image source={require('../../../resources/images/TabBar/PicAndText/star.png')}/>
  184. </TouchableOpacity>
  185. <TouchableOpacity onPress={() => {
  186. this.didClickBottomButton(2)
  187. }} >
  188. <Image source={require('../../../resources/images/TabBar/PicAndText/Forward.png')}/>
  189. </TouchableOpacity>
  190. </View>
  191. <View style={styles.BottomTopLineView}/>
  192. </View>
  193. </View>
  194. )
  195. }
  196. }
  197. const styles = StyleSheet.create({
  198. View: {
  199. width: ScreenDimensions.width,
  200. height: ScreenDimensions.height,
  201. backgroundColor: 'white',
  202. },
  203. ListView: {
  204. width: ScreenDimensions.width,
  205. height: ScreenDimensions.height - NavigationBarHeight.height - 48,
  206. marginTop: NavigationBarHeight.height,
  207. },
  208. BottomBgView: {
  209. width: ScreenDimensions.width,
  210. height: 48,
  211. flexDirection: 'row',
  212. alignItems: 'center',
  213. justifyContent: 'space-between'
  214. },
  215. BottomTopLineView: {
  216. width: ScreenDimensions.width,
  217. height: 0.5, backgroundColor: '#efeff4',
  218. position: 'absolute',
  219. left: 0,
  220. top: 0
  221. },
  222. InputBgView: {
  223. width: ScreenDimensions.width - 22 - 30 - 140,
  224. height: 34,
  225. borderRadius: 17,
  226. backgroundColor: '#dedede',
  227. flexDirection: 'row',
  228. alignItems: 'center',
  229. marginLeft: 22
  230. },
  231. PenImageView: {
  232. marginLeft: 14,
  233. },
  234. PlaceHolder:{
  235. marginLeft: 8,
  236. fontSize: 16,
  237. color: '#3c3c3c'
  238. },
  239. RightIconsBgView: {
  240. flexDirection: 'row',
  241. alignItems: 'center',
  242. marginRight: 20,
  243. },
  244. EmojiImageView: {
  245. position: 'absolute',
  246. right: 10,
  247. }
  248. })