英文:
How do I shorten the pull to refresh distance (threshold) in React Native Refresh Control
问题
我正在尝试使用ScrollView中的Refresh Control来实现下拉刷新。我需要修改刷新控件的拉动距离/阈值。我已经检查了相关的属性来实现这一点,但我找不到任何与此相关的属性。
<ScrollView
contentContainerStyle={styles.subContainer}
bounces={true}
horizontal={false}
refreshControl={
<RefreshControl
refreshing={false}
tintColor={'transparent'}
onRefresh={() => {
onSwipeDown();
}}
/>
}
>
{props.children}
</ScrollView>
英文:
I am trying to implement pull to refresh using Refresh Control in ScrollView. I need to modify the pulling distance/threshold of refresh control. I have checked for the related props to achieve it, but I can't any props related to this.
<ScrollView
contentContainerStyle={styles.subContainer}
bounces={true}
horizontal={false}
refreshControl={
<RefreshControl
refreshing={false}
tintColor={'transparent'}
onRefresh={() => {
onSwipeDown();
}}
/>
}
>
{props.children}
</ScrollView>
Please help me guys.
答案1
得分: 1
我们可以通过onScroll事件监听器来实现这个功能。
<ScrollView
contentContainerStyle={styles.subContainer}
bounces={true}
horizontal={false}
onScroll={onSwipeDown}
>
{props.children}
</ScrollView>
onSwipeDown方法
const onSwipeDown = event => {
console.log(event.nativeEvent.contentOffset.y);
if (event.nativeEvent.contentOffset.y < 0) { // 你可以用需要的阈值来替代零
onRefresh(); // 你的刷新函数
}
};
英文:
We can achieve this by onScroll event listener.
<ScrollView
contentContainerStyle={styles.subContainer}
bounces={true}
horizontal={false}
onScroll={onSwipeDown}
>
{props.children}
</ScrollView>
onSwipeDown method
const onSwipeDown = event => {
console.log(event.nativeEvent.contentOffset.y);
if (event.nativeEvent.contentOffset.y < 0) { // you can replace zero with needed threshold
onRefresh(); //your refresh function
}
};
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论