React Native FlatList启用了反向选项

时间:2018-04-28 21:08:32

标签: react-native react-native-flatlist

我有一个FlatList,如下所示:

[1524948093.974][WARNING]: chrome quit unexpectedly, leaving behind temporary directories for debugging:
[1524948093.974][SEVERE]: Port leaked: 12545
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: failed to wait for extension background page to load: chrome-extension://cjpalhdlnbpafiamejdnhcphjbkeiagm/background.html
from unknown error: page could not be found: chrome-extension://cjpalhdlnbpafiamejdnhcphjbkeiagm/background.html
  (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 x86_6

但是当我到达平面列表的顶部时,OnEndReached方法不会被调用。 请帮忙

3 个答案:

答案 0 :(得分:1)

我所能想到的只是在onScroll使用checkIfBeginningReached = ({ nativeEvent }) => { const { layoutMeasurement, contentOffset } = nativeEvent; const currentPos = layoutMeasurement.height + contentOffset.y; const listLength = ITEM_HEIGHT * this.state.items.length; const reactThreshold = listLength - (ITEM_HEIGHT * THRESHOLD); if (currentPos >= reactThreshold) { this.fetchMoreItems(this.state.items.length); } } (性能提防):https://snack.expo.io/@zvona/inverted-list-onbeginreached

实际功能如下:

nativeEvent

在那之上,我们从{{1}}中获取必要的信息(哪种方式保留了所有相关信息)。然后我们只计算当前位置的像素,整个列表内容的长度(以像素为单位),然后计算阈值点。

总之,这个特定的解决方案需要两件事: 1)列表具有固定且相同大小的元素 2)列表不是多列。

演示中的所有其他功能只是伪造/模仿一个用例(从服务器获取50多个项目,延迟500ms)。但如果可能的话,我会改进我的答案。但这应该让你开始。

答案 1 :(得分:0)

OnEndReachedThreshold必须是0到1之间的数字。由于您要倒置单位列表,因此onEndReachedThreshold将是用户到列表顶部的距离(以百分比为单位)。因此,当用户滚动浏览了可见列表的50%时,值为0.5将触发OnEndReached函数。

要以50%的比例触发该功能,您的代码应读取以下内容:

<FlatList inverted data={messages} keyExtractor={this._keyExtractor} renderItem={({ item }) => ( <Text style={styles.item}>{item}</Text> )} onEndReached={this.handleLoadMore} onEndReachedThreshold={0.5} />

答案 2 :(得分:0)

我的解决方案在这里:

isCloseToBottom = ({layoutMeasurement, contentOffset, contentSize}) => {
const paddingToBottom = 1
return layoutMeasurement.height + contentOffset.y >=
  contentSize.height - paddingToBottom}