首页 > 解决方案 > React Native Draggable Flatlist 仅适用于 ScrollView 但错误?

问题描述

我使用 React Native Draggable Flatlist:

https://github.com/computerjazz/react-native-draggable-flatlist

此代码有效,但出现错误:

const MyComponent = ({ items }) => {
  const renderItem = ({ item, index, drag, isActive }) => {
    return (
      <View style={{ flexDirection: "row" }}>
        <TouchableOpacity
          style={{
            backgroundColor: isActive ? "blue" : "gold",
            marginBottom: 10
          }}
          onPressIn={drag}
        >
          <Text>Move</Text>
        </TouchableOpacity>
        <InputText index={index} text={item} />
      </View>
    );
  };

  return (
    <ScrollView>
      <DraggableFlatList
        data={items}
        renderItem={renderItem}
        keyExtractor={(item, index) => `${index}`}
        onDragEnd={(e) => console.log(e)}
      />
    </ScrollView>
  );
};

VirtualizedLists 永远不应该嵌套在具有相同方向的普通 ScrollViews 中 - 请改用另一个 VirtualizedList 支持的容器。

如果我更改ScrollView为,View则错误消失,但是现在我看不到任何项目。

标签: react-native-flatlistreact-native-draggable-flatlist

解决方案


推荐阅读