1、render部分
onScroll在滚动的过程中,每帧最多调用一次此回调函数。调用的频率可以用scrollEventThrottle属性来控制,数字越大,跟踪滚动位置的代码的准确性就越高
render() {
return (
<View style={styles.container}>
{this.renderNavBar()}
<ScrollView
ref={view => {
this.ScrollView = view;
}}
horizontal
style={styles.wrapper}
showsHorizontalScrollIndicator={false}
pagingEnabled
onMomentumScrollEnd={event => this.scrollEnd(event)}
>
<QuotationList data={marketStockReqData} />
<QuotationList data={userStockReqData} />
</ScrollView>
</View>
);
}
2、scrollEnd计算offset偏移量
scrollEnd = event => {
const offsetX = event.nativeEvent.contentOffset.x;
const currentPage = Math.floor(offsetX / screenW);
this.setState({
tabIndex: currentPage
});
};
3、点击segement时滚动到对应offset
onMarketStockTab = () => {
this.ScrollView.scrollTo({ x: 0, y: 0, animated: true });
this.setState({
tabIndex: 0
});
};
onUserStockTab = () => {
this.ScrollView.scrollTo({ x: screenW, y: 0, animated: true });
this.setState({
tabIndex: 1
});
};
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。