1、render部分
onScroll在滾動(dòng)的過(guò)程中,每幀最多調(diào)用一次此回調(diào)函數(shù)。調(diào)用的頻率可以用scrollEventThrottle屬性來(lái)控制,數(shù)字越大,跟蹤滾動(dòng)位置的代碼的準(zhǔn)確性就越高
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計(jì)算offset偏移量
scrollEnd = event => {
const offsetX = event.nativeEvent.contentOffset.x;
const currentPage = Math.floor(offsetX / screenW);
this.setState({
tabIndex: currentPage
});
};
3、點(diǎn)擊segement時(shí)滾動(dòng)到對(duì)應(yīng)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
});
};
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。