react-native - react native : Refresh Controll not

我想下拉一个 scrollView 并刷新这个组件,所以我按照官方文档提到了 react-n 中的 onRefresh 和 RefreshContorol

刷新确实锻炼但滚动不工作。然而,当我删除 contentContainerStyle={{flex: 1}} 时,滚动开始工作但刷新控制不起作用。有什么办法可以解决吗?

export default function App() {
  const [refreshing, setRefreshing] = React.useState(false);

  const onRefresh = React.useCallback(() => {
    setRefreshing(true);

    wait(2000).then(() => setRefreshing(false));
  }, [refreshing]);

  return (
    <SafeAreaView style={styles.container}>
      <ScrollView
        contentContainerStyle={styles.scrollView}
        refreshControl={
          <RefreshControl refreshing={refreshing} onRefresh={onRefresh} />
        }
      >
        <Text>Pull down to see RefreshControl indicator</Text>
      </ScrollView>
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    marginTop: Constants.statusBarHeight,
  },
  scrollView: {
    flex: 1,
    backgroundColor: 'pink',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

最佳答案

确保使用 React Native 中的 ScrollView 而不是 React Native Gesture Handler。

关于react-native - react native : Refresh Controll not working with ScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66140444/

相关文章:

c++ - 为什么需要 std::make_unique 来初始化成员 std::unique 数组

vuejs3 - vue3 中 shallowReactive 和 shallowRef 的区别?

haskell - 为什么 map 使用的这个函数需要返回一个(单例)列表而不是一个元素?

c# - 如何使 IEnumerable 和 IQueryable 异步?

google-cloud-platform - 如何查看 Google Cloud Function

javascript - 对象可能是 'null' : TypeScript, React useR

reactjs - 有没有 Ionicons : Icon props?

javascript - Axios 响应未定义

list - 在 Elixir 中使用类型规范中的原子列表

flutter - 如何根据 flutter 中的文本高度调整容器高度?