gpt4 book ai didi

react-native - 如何通过向上滚动使用 react-native-gifted-chat 加载更多消息?

转载 作者:行者123 更新时间:2023-12-05 04:01:45 24 4
gpt4 key购买 nike

我想在滚动到顶部时加载更多消息。有一个 Prop onLoadEarlier 我在这里传递了一个函数来加载更多消息,但它不起作用。打开聊天框时确实会调用此函数,但我想在滚动到顶部时执行一个函数。

最佳答案

您可以在 listViewProps 中使用 scrollEventThrottleonScroll 属性来调用回调,当您点击 中的 Scrollview 顶部时天才聊天。对我来说很好。

<GiftedChat
messages={this.state.messages}
listViewProps={{
scrollEventThrottle: 400,
onScroll: ({ nativeEvent }) => {
if (this.isCloseToTop(nativeEvent)) {
this.setState({refreshing: true});
this.loadMoreChat();
}
}
}}
onSend={messages => this.onSend(messages)}
user={{
_id: 2,
}}
/>

isCloseToTop({ layoutMeasurement, contentOffset, contentSize }) {
const paddingToTop = 80;
return contentSize.height - layoutMeasurement.height - paddingToTop <= contentOffset.y;
}

代码引用取自 here .

关于react-native - 如何通过向上滚动使用 react-native-gifted-chat 加载更多消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55042213/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com