No Description

MyAnswerViewController.js 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /**
  2. * Created by zack on 2018/4/29.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. FlatList,
  9. TouchableOpacity,
  10. Image,
  11. ScrollView
  12. } from 'react-native'
  13. import React, {Component} from 'react'
  14. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools'
  15. import FindSearchResultItem from './View/FindSearchResultItem'
  16. import BaseNavigationBarStyle from '../../base/BaseNavigationBarStyle'
  17. import MyAnswerListPageView from './View/MyAnswerListPageView'
  18. export default class MyAnswerViewController extends Component {
  19. constructor(props) {
  20. super(props)
  21. this.state = {
  22. currentPage: 0,
  23. }
  24. }
  25. // 监听滚动
  26. onAnimationEnd(e){
  27. // 求出水平方向上的偏移量
  28. const offSetX = e.nativeEvent.contentOffset.x
  29. // 计算当前页码
  30. const currentPage = offSetX / (ScreenDimensions.width)
  31. // 重新绘制UI
  32. this.setState({currentPage: currentPage})
  33. }
  34. clickTagButtonActon(index) {
  35. let x = index * ScreenDimensions.width
  36. this.setState({currentPage: index})
  37. this._scrollView.scrollTo({x: x, y: 0, animated: true})
  38. }
  39. render() {
  40. return(
  41. <View style={styles.View}>
  42. <TouchableOpacity style={[styles.TopButtonBgView, {marginTop: NavigationBarHeight.height}]}>
  43. <View style={styles.TopButtonReadBgView}>
  44. <Image source={require("../../../resources/images/TabBar/Community/Answer/eye-normal.png")} style={styles.TopButtonImageView} />
  45. <Text style={styles.TopButtonTitle}>{'回答获得2人阅读'}</Text>
  46. </View>
  47. <Text style={styles.TopButtonSubTitle}>{'本月共2人浏览'}</Text>
  48. </TouchableOpacity>
  49. <View style={styles.TopButtonCenterLineView}/>
  50. <TouchableOpacity style={styles.TopButtonBgView}>
  51. <View style={styles.TopButtonReadBgView}>
  52. <Image source={require("../../../resources/images/TabBar/Community/Answer/like-normal.png")} style={styles.TopButtonImageView} />
  53. <Text style={styles.TopButtonTitle}>{'回答获得2人点赞'}</Text>
  54. </View>
  55. <Text style={styles.TopButtonSubTitle}>{'本月共5人点赞'}</Text>
  56. </TouchableOpacity>
  57. <View style={styles.TagButtonBgView}>
  58. <TouchableOpacity onPress={() => {
  59. this.clickTagButtonActon(0)
  60. }} style={styles.TagButtonView}>
  61. <Text style={[styles.TagButtonText, {marginLeft: 23, color: this.state.currentPage === 0 ? '#ef1313' : '#000000'}]}>{'收藏'}</Text>
  62. </TouchableOpacity>
  63. <TouchableOpacity onPress={() => {
  64. this.clickTagButtonActon(1)
  65. }} style={styles.TagButtonView}>
  66. <Text style={[styles.TagButtonText, {color: this.state.currentPage === 1 ? '#ef1313' : '#000000'}]}>{'提问'}</Text>
  67. </TouchableOpacity>
  68. <TouchableOpacity onPress={() => {
  69. this.clickTagButtonActon(2)
  70. }} style={styles.TagButtonView}>
  71. <Text style={[styles.TagButtonText, {color: this.state.currentPage === 2 ? '#ef1313' : '#000000'}]}>{'回答'}</Text>
  72. </TouchableOpacity>
  73. <TouchableOpacity onPress={() => {
  74. this.clickTagButtonActon(3)
  75. }} style={styles.TagButtonView}>
  76. <Text style={[styles.TagButtonText, {color: this.state.currentPage === 3 ? '#ef1313' : '#000000'}]}>{'草稿'}</Text>
  77. </TouchableOpacity>
  78. </View>
  79. <ScrollView ref = {(o) => {
  80. this._scrollView = o
  81. }} onMomentumScrollEnd={(e) => {
  82. this.onAnimationEnd(e)
  83. }} horizontal={true} pagingEnabled={true} style={styles.ScrollView}>
  84. <MyAnswerListPageView
  85. selectedTagIndex = {0}
  86. dataSources = {[{index: 0}, {index: 1}, {index: 2}, {index: 3}, {index: 4}, {index: 5}, {index: 6}, {index: 1}, {index: 2}]}
  87. />
  88. <MyAnswerListPageView
  89. selectedTagIndex = {1}
  90. dataSources = {[{index: 0}, {index: 1}, {index: 2}, {index: 3}, {index: 4}, {index: 5}, {index: 6}, {index: 1}, {index: 2}]}
  91. />
  92. <MyAnswerListPageView
  93. selectedTagIndex = {2}
  94. dataSources = {[{index: 0}, {index: 1}, {index: 2}, {index: 3}, {index: 4}, {index: 5}, {index: 6}, {index: 1}, {index: 2}]}
  95. />
  96. <MyAnswerListPageView
  97. selectedTagIndex = {3}
  98. dataSources = {[]}//{[{index: 0}, {index: 1}, {index: 2}, {index: 3}, {index: 4}, {index: 5}, {index: 6}, {index: 1}, {index: 2}]}
  99. />
  100. </ScrollView>
  101. </View>
  102. )
  103. }
  104. }
  105. const styles = StyleSheet.create({
  106. View: {
  107. width: ScreenDimensions.width,
  108. height: ScreenDimensions.height,
  109. backgroundColor: '#efeff4',
  110. },
  111. TopButtonBgView: {
  112. width: ScreenDimensions.width,
  113. height: 78,
  114. justifyContent: 'center',
  115. backgroundColor: 'white'
  116. },
  117. TopButtonReadBgView: {
  118. marginLeft: 23,
  119. flexDirection: 'row',
  120. alignItems: 'center',
  121. },
  122. TopButtonImageView: {
  123. marginRight: 12,
  124. },
  125. TopButtonTitle: {
  126. fontSize: 17,
  127. color: '#505050'
  128. },
  129. TopButtonSubTitle: {
  130. fontSize: 15,
  131. color: '#9c9c9c',
  132. marginTop: 13,
  133. marginLeft: 53,
  134. },
  135. TopButtonCenterLineView: {
  136. width: ScreenDimensions.width,
  137. height: 0.5,
  138. backgroundColor: '#efeff4'
  139. },
  140. TagButtonBgView: {
  141. width: ScreenDimensions.width,
  142. height: 45,
  143. marginTop: 8,
  144. borderBottomColor: '#efeff4',
  145. borderBottomWidth: 0.5,
  146. backgroundColor: 'white',
  147. flexDirection: 'row',
  148. alignItems: 'center',
  149. },
  150. TagButtonView: {
  151. height: 45,
  152. justifyContent: 'center',
  153. alignItems: 'center'
  154. },
  155. TagButtonText: {
  156. fontSize: 16,
  157. marginRight: 36
  158. },
  159. ScrollView: {
  160. width: ScreenDimensions.width,
  161. height: ScreenDimensions.height - NavigationBarHeight.height - 78 - 78 - 45 - 10,
  162. }
  163. })