2016-07-22 111 views
2

由于某些原因,我不明白,即使它在滚动的顶部,我的ListView仍然会触发,我需要将它包裹在ScrollView中,因为我希望我的ToolBar在隐藏时用户也在ListView中向下滚动。反应原生ListView onEndReached继续射击

这是render()方法的内容:

<ScrollView> 
    <ActivityContainer> 
     <ListView 
     onEndReachedThreshold={100} 
     pageSize={10} 
     initialListSize={20} 
     onEndReached={() => { 
         console.log("fired"); // keeps firing 
         }} 
     enableEmptySections={true}/> 
    </ActivityContainer> 
</ScrollView> 

还试图在这样的看法环绕整个事情:

<ScrollView> 
    <View> 
    <ActivityContainer> 
     <ListView 
     onEndReachedThreshold={100} 
     pageSize={10} 
     initialListSize={20} 
     onEndReached={() => { 
         console.log("fired"); // keeps firing 
         }} 
     enableEmptySections={true}/> 
    </ActivityContainer> 
    </View> 
</ScrollView> 

编辑:我不需要renderHeader因为我m试图滚动ListView顶部的所有内容,它有许多组件和视图以及子视图,而不是列表视图的标题。

回答

3

见,如果这个工程:

<ListView 
    onEndReachedThreshold={100} 
    pageSize={10} 
    renderHeader={() => <ToolbarAndroid />} 
    initialListSize={20} 
    onEndReached={() => { 
    console.log("fired"); // keeps firing 
    }} 
    enableEmptySections={true}/> 
+0

我想'onEndReached'持续触发的原因是由于嵌套ListView和ScrollView造成的一些问题。你有没有注意到这是否停止了,即使它打破了这个观点? – lalkmim

+0

我明白了,我只是问当两个部件“不合格”时停止发射的问题是否会停止。我知道你有两个问题:射击和布局。 – lalkmim

+0

问题是工具栏是在一个Activity容器中,它内部有工具栏和其他组件,并且包含了所有组件,包括ListView,我无法将它作为列表视图的标题 – octohedron

0

使用哈希寻呼ListView中时> 1列

目前,我在本地做出反应,但V44没有试过最新版本。

在你的构造试试这个...

constructor(props) { 
    this.pagesLoaded = {} 
    this.currentPage = 1 
    // etc 
} 

然后在您的数据获取方法试试这个...

getData() { 
    if (this.pagesLoaded[this.state.currentPage]) return 
    this.pagesLoaded[this.state.currentPage] = true 
    // fetch data 
} 

这样当onEndReached被过度烧制,也不会物。这看起来像是ListView中的一个bug,因为我已经在它周围设置了尺寸,并且它没有在ScrollView之内,所以它纯粹发生在组件内,即使设置了getItemLayout支撑。