No Description

AnswerPageView.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. } from 'react-native'
  12. import React, {Component} from 'react'
  13. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools'
  14. import AnswerPageViewListItem from './View/AnswerPageViewListItem'
  15. import UserHeaderView from './View/UserHeaderView'
  16. import HttpTools from '../../../network/HttpTools'
  17. import {auth, question} from '../../../network/API'
  18. export default class AnswerPageView extends Component {
  19. constructor(props) {
  20. super(props)
  21. this.state = {
  22. dataSources: [],
  23. }
  24. }
  25. getQuestionList() {
  26. const param = ({
  27. page: 1,
  28. limit: 20
  29. })
  30. HttpTools.get(question, param, (response) => {
  31. if (response && response.length) {
  32. this.setState({dataSources: response})
  33. }
  34. }, (error) => {
  35. })
  36. }
  37. renderItem(item) {
  38. return(
  39. <AnswerPageViewListItem
  40. title = {item.title}
  41. imageUrls= {item.img_urls}
  42. likes= {item.likes && item.likes.length}
  43. didSelectedItem = {() => {
  44. this.props.didSelectedItem(item.id)
  45. }}
  46. />
  47. )
  48. }
  49. render() {
  50. return(
  51. <View style={styles.View}>
  52. <UserHeaderView
  53. didClickUserHeaderView = {() => {
  54. this.props.didClickUserHeaderView()
  55. }}
  56. />
  57. <View style={styles.TagBgView}>
  58. <TouchableOpacity onPress={() => {
  59. this.props.didClickTagButton(0)
  60. }} style= {styles.TagButtonView}>
  61. <Image source={require('../../../resources/images/TabBar/Community/Answer/ques.png')} style={styles.TagButtonImageView}/>
  62. <Text style={styles.TagButtonTitleText}>{'提问'}</Text>
  63. </TouchableOpacity>
  64. <TouchableOpacity onPress={() => {
  65. this.props.didClickTagButton(1)
  66. }} style= {styles.TagButtonView}>
  67. <View style={[styles.TagLeftLineView, {left: 0,}]} />
  68. <Image source={require('../../../resources/images/TabBar/Community/Answer/ques.png')} style={styles.TagButtonImageView}/>
  69. <Text style={styles.TagButtonTitleText}>{'回答'}</Text>
  70. <View style={[styles.TagLeftLineView, {right: 0,}]} />
  71. </TouchableOpacity>
  72. <TouchableOpacity onPress={() => {
  73. this.props.didClickTagButton(2)
  74. }} style= {styles.TagButtonView}>
  75. <Image source={require('../../../resources/images/TabBar/Community/Answer/ques.png')} style={styles.TagButtonImageView}/>
  76. <Text style={styles.TagButtonTitleText}>{'发现'}</Text>
  77. </TouchableOpacity>
  78. </View>
  79. <View style={styles.ListView}>
  80. <FlatList
  81. data = {this.state.dataSources}
  82. renderItem={({item}) => this.renderItem(item)}
  83. keyExtractor = {(item,index) =>{
  84. return 'key' + item.key + index
  85. }}
  86. ListFooterComponent = {() => {
  87. return(
  88. <View style={{width: ScreenDimensions.width, height: 44, backgroundColor: 'white'}} />
  89. )
  90. }}
  91. />
  92. </View>
  93. </View>
  94. )
  95. }
  96. }
  97. const styles = StyleSheet.create({
  98. View: {
  99. width: ScreenDimensions.width,
  100. height: ScreenDimensions.height - NavigationBarHeight.height - TabBarHeight.height,
  101. backgroundColor: '#ffffff',
  102. },
  103. TagBgView: {
  104. width: ScreenDimensions.width,
  105. height: 56,
  106. flexDirection: 'row',
  107. justifyContent: 'space-between',
  108. backgroundColor: '#eef0ef'
  109. },
  110. TagButtonView: {
  111. width: ScreenDimensions.width/3.0,
  112. height: 48,
  113. alignItems: 'center',
  114. justifyContent: 'center',
  115. flexDirection: 'row',
  116. backgroundColor: '#ffffff'
  117. },
  118. TagButtonImageView: {
  119. width: 17,
  120. height: 17,
  121. },
  122. TagButtonTitleText: {
  123. fontSize: 15,
  124. color: '#27211c',
  125. marginLeft: 9,
  126. },
  127. TagLeftLineView: {
  128. height: 30,
  129. top: 9,
  130. width: 1,
  131. backgroundColor: '#d7d7d7',
  132. position: 'absolute'
  133. },
  134. ListView: {
  135. height: ScreenDimensions.height - NavigationBarHeight.height - TabBarHeight.height - 56 - 78,
  136. width: ScreenDimensions.width
  137. }
  138. })