暫無描述

PicAndTextPageView.js 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /**
  2. * Created by zack on 2018/5/21.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. Image,
  9. TouchableOpacity,
  10. FlatList,
  11. Modal
  12. } from 'react-native'
  13. import React, {Component} from 'react'
  14. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools'
  15. import HttpTools from '../../../network/HttpTools'
  16. import {auth, question, imgText, login} from '../../../network/API'
  17. import PicAndTextListItem from './View/PicAndTextListItem'
  18. export default class FollowPageView extends Component {
  19. constructor(props) {
  20. super(props)
  21. this.state = {
  22. isLikeModalVisible: false,
  23. dataSources: [],
  24. }
  25. this.itemId = ''
  26. }
  27. componentDidMount() {
  28. }
  29. getPicAndTextList() {
  30. const param = {
  31. page: 1,
  32. limit: 10,
  33. }
  34. HttpTools.get(imgText, param, (response) => {
  35. if (response) {
  36. this.setState({dataSources: response})
  37. }
  38. }, (error) => {
  39. })
  40. }
  41. getUserInfo(callback) {
  42. const param = JSON.stringify({
  43. username: '15303737970',
  44. password: '471155401'
  45. })
  46. HttpTools.post(login, param, (response) => {
  47. global.token = response.token
  48. callback && callback()
  49. }, (error) => {
  50. })
  51. }
  52. createPicAndText() {
  53. const param = JSON.stringify({
  54. text: "美国队长的实际战力到底在什么水平?",
  55. urls: [
  56. "https://links123-images.oss-cn-hangzhou.aliyuncs.com/avatar/2017/8/20/e89274364bb5e2ceb378b8864ac05e39.jpg",
  57. "https://links123-images.oss-cn-hangzhou.aliyuncs.com/avatar/2017/8/20/e89274364bb5e2ceb378b8864ac05e39.jpg"
  58. ]
  59. })
  60. HttpTools.post(imgText, param, (response) => {
  61. }, (error) => {
  62. })
  63. }
  64. clickBottomButton(index, itemId, isLiked) {
  65. if (index === 0) { //赞
  66. this.addLike(itemId)
  67. let newDataSources = this.state.dataSources.map((item) => {
  68. if (item.id === itemId) {
  69. item.is_liked = isLiked === 1 ? 0 : 1
  70. }
  71. return item
  72. })
  73. let list = []
  74. for (let i = 0 ; i < newDataSources.length; i ++) {
  75. list.push(newDataSources[i])
  76. }
  77. this.setState({dataSources: list})
  78. }else if (index === 1) { //评论
  79. this.props.didSelectedPicAndTextItem(itemId)
  80. }else if (index === 2) { //转发
  81. this.addShares(itemId)
  82. }else if (index === 3) { // 眼睛
  83. this.itemId = itemId
  84. this.setState({isLikeModalVisible: true})
  85. }
  86. }
  87. addLike(itemId, isLiked) {
  88. let url = ''
  89. if (isLiked) { //取消点赞
  90. url = 'img_txt/' + itemId + '/dislike'
  91. }else {
  92. url = 'img_txt/' + itemId + '/like'
  93. }
  94. const param = JSON.stringify({
  95. id: itemId
  96. })
  97. HttpTools.post(url, param, (response) => {
  98. }, (error) => {
  99. })
  100. }
  101. addShares(itemId) {
  102. let url = 'img_txt/' + itemId + '/share'
  103. const param = JSON.stringify({
  104. id: itemId
  105. })
  106. HttpTools.post(url, param, (response) => {
  107. }, (error) => {
  108. })
  109. }
  110. addBlock(itemId) {
  111. let url = 'img_txt/' + itemId + '/block'
  112. const param = JSON.stringify({
  113. id: itemId
  114. })
  115. HttpTools.post(url, param, (response) => {
  116. }, (error) => {
  117. })
  118. }
  119. addJunk(itemId) {
  120. let url = 'img_txt/' + itemId + '/junk'
  121. const param = JSON.stringify({
  122. id: itemId
  123. })
  124. HttpTools.post(url, param, (response) => {
  125. }, (error) => {
  126. })
  127. }
  128. clickLikeModalView(index) {
  129. if (index === 0) {
  130. this.addBlock(this.itemId)
  131. }else if (index === 1) {
  132. this.addJunk(this.itemId)
  133. }else if (index === 2) { //取消关注
  134. }else {
  135. this.setState({isLikeModalVisible: false})
  136. }
  137. }
  138. renderItem(item) {
  139. return(
  140. <PicAndTextListItem
  141. title = {item.text}
  142. userName = {item.user_name}
  143. imageUrls = {item.urls}
  144. userIcon = {item.user_avatar}
  145. commentCount = {item.comment_count}
  146. likes = {item.likes}
  147. shares = {item.shares}
  148. isLiked = {item.is_liked}
  149. clickBottomButton = {(index) => {
  150. this.clickBottomButton(index, item.id, item.is_liked)
  151. }}
  152. didClickImageViewContainer = {(imageUrls) => {
  153. this.props.didClickImageViewContainer(imageUrls)
  154. }}
  155. />
  156. )
  157. }
  158. render() {
  159. return(
  160. <View style={styles.View}>
  161. <View style={styles.ListView}>
  162. <FlatList
  163. data = {this.state.dataSources}
  164. renderItem={({item}) => this.renderItem(item)}
  165. keyExtractor = {(item,index) =>{
  166. return 'key' + item.key + index
  167. }}
  168. ListFooterComponent = {() => {
  169. return(
  170. <View style={{width: ScreenDimensions.width, height: 44, backgroundColor: 'white'}} />
  171. )
  172. }}
  173. />
  174. </View>
  175. <Modal
  176. animationType={"fade"}
  177. transparent={true}
  178. visible={this.state.isLikeModalVisible}
  179. onDismiss={() => {
  180. }}
  181. onRequestClose={() => {}}
  182. onShow={() => {} }
  183. >
  184. <TouchableOpacity activeOpacity={1} onPress={() => {this.clickLikeModalView(100)}}
  185. style={{width: ScreenDimensions.width, height: ScreenDimensions.height, backgroundColor: 'rgba(0,0,0,0.15)',
  186. justifyContent: 'center',
  187. alignItems: 'center'
  188. }}
  189. >
  190. <View style={{
  191. width: 320,
  192. height: 180,
  193. backgroundColor: 'white',
  194. borderRadius: 10,
  195. }}>
  196. <TouchableOpacity onPress={() => {
  197. this.clickLikeModalView(0)
  198. }} style={{height: 60, flexDirection: 'row', alignItems: 'center'}}>
  199. <Image source={require('../../../resources/images/TabBar/PicAndText/close.png')} style={{width: 15, height: 15, backgroundColor: 'white', marginLeft: 34}}/>
  200. <View style={{justifyContent: 'center',
  201. marginLeft: 17}}>
  202. <Text style={{fontSize: 15, color: '#000000'}}>{'不感兴趣'}</Text>
  203. <Text style={{fontSize: 12, color: '#b8b8b8', marginTop: 8}}>{'减少这类内容'}</Text>
  204. </View>
  205. </TouchableOpacity>
  206. <TouchableOpacity onPress={() => {
  207. this.clickLikeModalView(1)
  208. }} style={{height: 60, flexDirection: 'row', alignItems: 'center'}}>
  209. <Image source={require('../../../resources/images/TabBar/PicAndText/warning.png')} style={{width: 15, height: 15, backgroundColor: 'white', marginLeft: 34}}/>
  210. <View style={{justifyContent: 'center',
  211. marginLeft: 17}}>
  212. <Text style={{fontSize: 15, color: '#000000'}}>{'反馈垃圾内容'}</Text>
  213. <Text style={{fontSize: 12, color: '#b8b8b8', marginTop: 8}}>{'低俗,标题党等'}</Text>
  214. </View>
  215. </TouchableOpacity>
  216. <TouchableOpacity onPress={() => {
  217. this.clickLikeModalView(2)
  218. }} style={{height: 60, flexDirection: 'row', alignItems: 'center'}}>
  219. <Image source={require('../../../resources/images/TabBar/PicAndText/cancle.png')} style={{width: 15, height: 15, backgroundColor: 'white', marginLeft: 34}}/>
  220. <View style={{ justifyContent: 'center',
  221. marginLeft: 17}}>
  222. <Text style={{fontSize: 15, color: '#000000'}}>{'取消关注 Zack'}</Text>
  223. </View>
  224. </TouchableOpacity>
  225. <View style={{width: 210, height: 0.5, backgroundColor: '#efeff4', position: 'absolute', left: 0, top: 60}} />
  226. <View style={{width: 210, height: 0.5, backgroundColor: '#efeff4', position: 'absolute', left: 0, top: 120}} />
  227. </View>
  228. </TouchableOpacity>
  229. </Modal>
  230. </View>
  231. )
  232. }
  233. }
  234. const styles = StyleSheet.create({
  235. View: {
  236. width: ScreenDimensions.width,
  237. height: ScreenDimensions.height,
  238. backgroundColor: '#ffffff',
  239. alignItems: 'center',
  240. },
  241. ListView: {
  242. width: ScreenDimensions.width,
  243. height: ScreenDimensions.height - NavigationBarHeight.height - TabBarHeight.height,
  244. },
  245. BlankImageView: {
  246. marginTop: NavigationBarHeight.height + 80,
  247. width: 175,
  248. height: 143,
  249. },
  250. TitleText: {
  251. fontSize: 17,
  252. color: '#05120b',
  253. marginTop: 45,
  254. },
  255. FollowButton: {
  256. marginTop: 25,
  257. width: 230,
  258. height: 46,
  259. backgroundColor: '#ffffff',
  260. borderWidth: 1.0,
  261. borderColor: '#fc4747',
  262. borderRadius: 23,
  263. justifyContent: 'center',
  264. alignItems: 'center'
  265. },
  266. FollowButtonText: {
  267. fontSize: 17,
  268. color: '#fc4747',
  269. },
  270. })