react-native ScrollView 嵌套 FlatList滾動

最近項目遇到需要使用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>
  ) 
}

借鑒地址:https://github.com/facebook/react-native/issues/19971

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容