No Description

FollowListViewController.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /**
  2. * Created by zack on 2018/5/2.
  3. */
  4. import {
  5. View,
  6. Text,
  7. StyleSheet,
  8. Platform,
  9. ScrollView,
  10. FlatList
  11. } from 'react-native'
  12. import React, {Component} from 'react'
  13. import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools'
  14. import BaseNavigationBarStyle from '../../base/BaseNavigationBarStyle'
  15. import FollowPageViewNavigationBar from './View/FollowPageViewNavigationBar'
  16. import RecommendItem from './View/RecommendItem'
  17. export default class FollowListViewController extends Component {
  18. constructor(props) {
  19. super(props)
  20. this.state = {
  21. selectedTagIndex: 0,
  22. }
  23. }
  24. renderFamousListItem() {
  25. return(
  26. <RecommendItem />
  27. )
  28. }
  29. renderRecommendListItem() {
  30. return(
  31. <RecommendItem />
  32. )
  33. }
  34. // 监听滚动
  35. onAnimationEnd(e){
  36. // 求出水平方向上的偏移量
  37. const offSetX = e.nativeEvent.contentOffset.x
  38. // 计算当前页码
  39. const currentPage = offSetX / (ScreenDimensions.width)
  40. // 重新绘制UI
  41. this.setState({selectedTagIndex: currentPage})
  42. }
  43. didSelectedTagIndex(index) {
  44. let x = index * ScreenDimensions.width
  45. this.setState({selectedTagIndex: index})
  46. this._scrollView.scrollTo({x: x, y: 0, animated: true})
  47. }
  48. render() {
  49. return(
  50. <View style={styles.View}>
  51. <FollowPageViewNavigationBar
  52. selectedTagIndex = {this.state.selectedTagIndex}
  53. didSelectedTagIndex = {(index) => {
  54. this.didSelectedTagIndex(index)
  55. }}
  56. didClickLeftButton = {() => {
  57. this.props.navigator.pop()
  58. }}
  59. />
  60. <ScrollView onMomentumScrollEnd={(e) => {
  61. this.onAnimationEnd(e)
  62. }} ref = {(o) => {this._scrollView = o}} horizontal={true} pagingEnabled={true} style = {styles.ScrollView}>
  63. <View style={styles.ListView}>
  64. <FlatList
  65. data = {['a', 'b', 'c']}
  66. renderItem={({item}) => this.renderRecommendListItem(item)}
  67. keyExtractor = {(item,index) =>{
  68. return 'key' + item.key + index
  69. }}
  70. ListFooterComponent = {() => {
  71. return(
  72. <View style={{width: ScreenDimensions.width, height: 44, backgroundColor: 'white'}} />
  73. )
  74. }}
  75. />
  76. </View>
  77. <View style={styles.ListView}>
  78. <FlatList
  79. data = {['a', 'b', 'c']}
  80. renderItem={({item}) => this.renderFamousListItem(item)}
  81. keyExtractor = {(item,index) =>{
  82. return 'key' + item.key + index
  83. }}
  84. ListFooterComponent = {() => {
  85. return(
  86. <View style={{width: ScreenDimensions.width, height: 44, backgroundColor: 'white'}} />
  87. )
  88. }}
  89. />
  90. </View>
  91. </ScrollView>
  92. </View>
  93. )
  94. }
  95. }
  96. const styles = StyleSheet.create({
  97. View: {
  98. width: ScreenDimensions.width,
  99. height: ScreenDimensions.height,
  100. backgroundColor: '#ffffff',
  101. alignItems: 'center',
  102. },
  103. ScrollView: {
  104. marginTop: NavigationBarHeight.height,
  105. width: ScreenDimensions.width,
  106. height: ScreenDimensions.height - NavigationBarHeight.height - TabBarHeight.height,
  107. },
  108. ListView: {
  109. width: ScreenDimensions.width,
  110. height: ScreenDimensions.height - NavigationBarHeight.height - TabBarHeight.height,
  111. },
  112. })