/** * Created by zack on 2018/4/29. */ import { View, Text, StyleSheet, FlatList, TouchableOpacity, Image, ScrollView } from 'react-native' import React, {Component} from 'react' import {NavigationBarHeight, TabBarHeight, ScreenDimensions} from '../../../utils/DimensionsTools' import FindSearchResultItem from './View/FindSearchResultItem' import BaseNavigationBarStyle from '../../base/BaseNavigationBarStyle' import MyAnswerListPageView from './View/MyAnswerListPageView' export default class MyAnswerViewController extends Component { constructor(props) { super(props) this.state = { currentPage: 0, } } // 监听滚动 onAnimationEnd(e){ // 求出水平方向上的偏移量 const offSetX = e.nativeEvent.contentOffset.x // 计算当前页码 const currentPage = offSetX / (ScreenDimensions.width) // 重新绘制UI this.setState({currentPage: currentPage}) } clickTagButtonActon(index) { let x = index * ScreenDimensions.width this.setState({currentPage: index}) this._scrollView.scrollTo({x: x, y: 0, animated: true}) } render() { return( {'回答获得2人阅读'} {'本月共2人浏览'} {'回答获得2人点赞'} {'本月共5人点赞'} { this.clickTagButtonActon(0) }} style={styles.TagButtonView}> {'收藏'} { this.clickTagButtonActon(1) }} style={styles.TagButtonView}> {'提问'} { this.clickTagButtonActon(2) }} style={styles.TagButtonView}> {'回答'} { this.clickTagButtonActon(3) }} style={styles.TagButtonView}> {'草稿'} { this._scrollView = o }} onMomentumScrollEnd={(e) => { this.onAnimationEnd(e) }} horizontal={true} pagingEnabled={true} style={styles.ScrollView}> ) } } const styles = StyleSheet.create({ View: { width: ScreenDimensions.width, height: ScreenDimensions.height, backgroundColor: '#efeff4', }, TopButtonBgView: { width: ScreenDimensions.width, height: 78, justifyContent: 'center', backgroundColor: 'white' }, TopButtonReadBgView: { marginLeft: 23, flexDirection: 'row', alignItems: 'center', }, TopButtonImageView: { marginRight: 12, }, TopButtonTitle: { fontSize: 17, color: '#505050' }, TopButtonSubTitle: { fontSize: 15, color: '#9c9c9c', marginTop: 13, marginLeft: 53, }, TopButtonCenterLineView: { width: ScreenDimensions.width, height: 0.5, backgroundColor: '#efeff4' }, TagButtonBgView: { width: ScreenDimensions.width, height: 45, marginTop: 8, borderBottomColor: '#efeff4', borderBottomWidth: 0.5, backgroundColor: 'white', flexDirection: 'row', alignItems: 'center', }, TagButtonView: { height: 45, justifyContent: 'center', alignItems: 'center' }, TagButtonText: { fontSize: 16, marginRight: 36 }, ScrollView: { width: ScreenDimensions.width, height: ScreenDimensions.height - NavigationBarHeight.height - 78 - 78 - 45 - 10, } })