No Description

AnswerQuestionItem.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /**
  2. * Created by zack on 2018/4/29.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. Image,
  9. TouchableOpacity,
  10. FlatList,
  11. Platform
  12. } from 'react-native'
  13. import React, {Component} from 'react'
  14. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../../utils/DimensionsTools'
  15. import {CachedImage} from 'react-native-img-cache'
  16. import ImageLoader from 'react-native-smart-image-loader'
  17. export default class AnswerQuestionItem extends Component {
  18. constructor(props) {
  19. super(props)
  20. this.state = {
  21. title: props.title,
  22. subTitle: props.subTitle,
  23. imageUrls: props.imageUrls,
  24. commentCount: props.commentCount,
  25. likes: props.likes
  26. }
  27. }
  28. componentWillReceiveProps(props) {
  29. this.setState({
  30. title: props.title,
  31. subTitle: props.subTitle,
  32. imageUrls: props.imageUrls,
  33. commentCount: props.commentCount,
  34. likes: props.likes
  35. })
  36. }
  37. shouldComponentUpdate(nextProps) {
  38. if (nextProps.title !== this.state.title ||
  39. nextProps.subTitle !== this.state.subTitle ||
  40. nextProps.imageUrls !== this.state.imageUrls ||
  41. nextProps.commentCount !== this.state.commentCount ||
  42. nextProps.likes !== this.state.likes
  43. ) {
  44. return true
  45. }
  46. return false
  47. }
  48. renderImageViews() {
  49. let imageViews = []
  50. for (let i = 0; i < this.state.imageUrls.length; i ++) {
  51. let imageLoader = (
  52. <ImageLoader
  53. key = {i}
  54. style={[styles.ImageView, {marginBottom: (i < 3 ? 8 : 0), marginRight: (i > 0 && (i+ 1)%3 === 0) ? 0 : 8}]}
  55. options={{
  56. src: this.state.imageUrls[i],
  57. }}
  58. />)
  59. imageViews.push(imageLoader)
  60. }
  61. return imageViews
  62. }
  63. render() {
  64. let desc = this.state.commentCount + '人回答' + ' ' + this.state.likes + '人收藏'
  65. return(
  66. <View style={styles.View}>
  67. <Text style={styles.TitleText}>{this.state.title}</Text>
  68. <Text style={styles.SubTitleText}>{this.state.subTitle}</Text>
  69. <View style={styles.ImageContainerView}>
  70. {this.renderImageViews()}
  71. </View>
  72. <Text style={styles.AnswerNumberText}>{desc}</Text>
  73. <View style={styles.BottomLineView} />
  74. </View>
  75. )
  76. }
  77. }
  78. const styles = StyleSheet.create({
  79. View: {
  80. width: ScreenDimensions.width,
  81. backgroundColor: 'white'
  82. },
  83. TitleText: {
  84. marginTop: 25,
  85. fontSize: 17,
  86. color: '#000000',
  87. marginLeft: 22,
  88. marginRight: 22,
  89. },
  90. SubTitleText: {
  91. marginTop: 22,
  92. fontSize: 15,
  93. color: '#505050',
  94. marginLeft: 22,
  95. marginRight: 22,
  96. },
  97. AnswerNumberText: {
  98. marginLeft: 24,
  99. marginTop: 22,
  100. fontSize: 15,
  101. color: '#9c9c9c',
  102. marginBottom: 13,
  103. },
  104. BottomLineView: {
  105. position: 'absolute',
  106. width: ScreenDimensions.width,
  107. height: 0.5,
  108. backgroundColor: '#d7d7d7',
  109. left: 0,
  110. bottom: 0,
  111. },
  112. ImageContainerView: {
  113. marginTop: 30,
  114. width: ScreenDimensions.width - 30,
  115. marginLeft: 15,
  116. flexDirection: 'row',
  117. flexWrap: 'wrap'
  118. },
  119. ImageView: {
  120. width: (ScreenDimensions.width - 30 - 16)/3.0,
  121. height: (ScreenDimensions.width - 30 - 16)/3.0,
  122. }
  123. })