首页 > 解决方案 > 如何缩短 React Native Refresh Control 中的拉动刷新距离(阈值)

问题描述

我正在尝试使用 ScrollView 中的刷新控件来实现拉动刷新。我需要修改刷新控制的拉距/阈值。我已经检查了相关的道具来实现它,但我找不到任何与此相关的道具。

<ScrollView
          contentContainerStyle={styles.subContainer}
          bounces={true}
          horizontal={false}
          refreshControl={
            <RefreshControl
              refreshing={false}
              tintColor={'transparent'}
              onRefresh={() => {
                onSwipeDown();
              }}
            />
          }
        >
          {props.children}
</ScrollView>

请帮帮我。

标签: reactjsreact-nativescrollviewreact-native-androidpull-to-refresh

解决方案


我们可以通过 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) { // you can replace zero with needed threshold
      onRefresh(); //your refresh function
    }
  };

推荐阅读