【问题标题】:How do I shorten the pull to refresh distance (threshold) in React Native Refresh Control如何缩短 React Native Refresh Control 中的拉动刷新距离(阈值)
【发布时间】:2020-01-03 06:15:15
【问题描述】:

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

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

请帮帮我。

【问题讨论】:

    标签: reactjs react-native scrollview react-native-android pull-to-refresh


    【解决方案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) { // you can replace zero with needed threshold
          onRefresh(); //your refresh function
        }
      };
    

    【讨论】:

      猜你喜欢
      • 2013-12-11
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 2019-04-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多