No Description

PicAndTextDetailCommentItem.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /**
  2. * Created by zack on 2018/5/22.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. FlatList,
  9. Platform,
  10. TouchableOpacity,
  11. ImageBackground,
  12. Image
  13. } from 'react-native'
  14. import React, {Component} from 'react'
  15. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../../utils/DimensionsTools'
  16. import ImageLoader from 'react-native-smart-image-loader'
  17. import {CachedImage} from 'react-native-img-cache'
  18. export default class PicAndTextDetailCommentItem extends Component {
  19. constructor(props) {
  20. super(props)
  21. this.state = {
  22. userName: props.userName,
  23. userIcon: props.userIcon,
  24. title: props.title,
  25. commentCount: props.commentCount,
  26. likes: props.likes,
  27. shares: props.shares,
  28. isLiked: props.isLiked
  29. }
  30. }
  31. componentWillReceiveProps(props) {
  32. this.setState({
  33. userName: props.userName,
  34. userIcon: props.userIcon,
  35. title: props.title,
  36. commentCount: props.commentCount,
  37. likes: props.likes,
  38. shares: props.shares,
  39. isLiked: props.isLiked
  40. })
  41. }
  42. shouldComponentUpdate(nextProps) {
  43. if (nextProps.userName !== this.state.userName ||
  44. nextProps.title !== this.state.title ||
  45. nextProps.commentCount !== this.state.commentCount ||
  46. nextProps.likes !== this.state.likes ||
  47. nextProps.shares !== this.state.shares ||
  48. nextProps.userIcon !== this.state.userIcon ||
  49. nextProps.isLiked !== this.state.isLiked
  50. ) {
  51. return true
  52. }
  53. return false
  54. }
  55. render() {
  56. return(
  57. <View style={styles.View}>
  58. <ImageLoader
  59. style={[styles.HeaderImageView, {borderRadius: 24,}]}
  60. options={{
  61. src: this.state.userIcon,
  62. }}
  63. />
  64. <View style={styles.CommentBgView}>
  65. <Text style={styles.UserName}>{this.state.userName}</Text>
  66. <Text style={styles.CommentContent}>{this.state.title}</Text>
  67. <Text style={styles.TimeText}>{'2018/12/27 18:00'}</Text>
  68. </View>
  69. <TouchableOpacity style={styles.LikeBgView}>
  70. <Image source={this.state.isLiked ? require('../../../../resources/images/TabBar/PicAndText/like_hover.png') : require('../../../../resources/images/TabBar/PicAndText/like.png')}/>
  71. <Text style={styles.LikeNumberText}>{this.state.likes}</Text>
  72. </TouchableOpacity>
  73. <View style={styles.BottomLineView}/>
  74. </View>
  75. )
  76. }
  77. }
  78. const styles = StyleSheet.create({
  79. View: {
  80. width: ScreenDimensions.width,
  81. flexDirection: 'row',
  82. justifyContent: 'space-between',
  83. backgroundColor: 'white'
  84. },
  85. HeaderImageView: {
  86. width: 48,
  87. height: 48,
  88. marginLeft: 24,
  89. marginTop: 16,
  90. },
  91. CommentBgView: {
  92. marginLeft: 34,
  93. marginTop: 16,
  94. width: ScreenDimensions.width - 24 - 48 - 34 - 20 - 22,
  95. marginBottom: 16,
  96. },
  97. UserName: {
  98. fontSize: 15,
  99. color: '#000000',
  100. },
  101. CommentContent: {
  102. fontSize: 15,
  103. color: '#000000',
  104. marginTop: 15,
  105. },
  106. TimeText: {
  107. fontSize: 13,
  108. color: '#9c9c9c',
  109. marginTop: 12,
  110. },
  111. LikeBgView: {
  112. marginTop: 16,
  113. marginRight: 22,
  114. },
  115. LikeNumberText: {
  116. fontSize: 12,
  117. color: '#9c9c9c',
  118. marginTop: 8,
  119. textAlign: 'center'
  120. },
  121. BottomLineView: {
  122. width: ScreenDimensions.width,
  123. height: 0.5,
  124. backgroundColor: '#efeff4',
  125. position: 'absolute',
  126. left: 0,
  127. bottom: 0,
  128. }
  129. })