最近項目遇到需要使用ScrollView 嵌套 FlatList的功能,當(dāng)flatList滾動時,ScrollView也在滾動,最后在github上找到了解決辦法,防止忘記記錄一下!!
ScrollView 嵌套 FlatList滾動,當(dāng)flatList滾動時,ScrollView禁止?jié)L動
this.state = {
enableScrollViewScroll: true,
...
}
onEnableScroll = value => {
this.setState({
enableScrollViewScroll: value,
});
};
render() {
return(
<ScrollView
scrollEnabled={this.state.enableScrollViewScroll}
>
<FlatList
onTouchStart={() => {this.onEnableScroll(false);}}
onMomentumScrollEnd={() => {this.onEnableScroll(true);}}
...
/>
...
</ScrollView>
)
}