requireNativeComponent:在 React Native 中使用 flash 列表时的“AutoLayoutView”

Mah*_*yar 9 javascript react-native

我想用来flashlist将项目渲染到屏幕上,根据文档,我们唯一需要做的就是重命名组件并向estimatedItemSize组件添加属性,所以我这样做了,但出现了这个奇怪的错误。

组件代码:


export const RestaurantsScreen = () => {
  const { isLoading, error, clearError, sendRequest } = useHttpClient();
  const [fetchedRestaurants, setFetchedRestaurants] = useState([]);

...
...
...

      {!isLoading && fetchedRestaurants.length > 0 && (
        <FlashList
          data={fetchedRestaurants}
          renderItem={renderItemComponent}
          keyExtractor={(item) => item.name}
          initialNumToRender={3}
          estimatedItemSize={15}
        />
      )}
    </SafeArea>
  );
};

Run Code Online (Sandbox Code Playgroud)

错误是:

Invariant Violation: requireNativeComponent: "AutoLayoutView" was not found in the UIManager.

This error is located at:
    in AutoLayoutView (created by AutoLayoutView)
    in AutoLayoutView (created by ScrollComponent)
    in RCTView (created by View)
    in View (created by ScrollComponent)
    in ...
Run Code Online (Sandbox Code Playgroud)

它可以很好地与flatlist.

Gio*_*lis 11

原因是 flashlist 模块具有本机依赖项(这就是安装文档pod install提示您在 ios 目录中安装本机 deps的原因)。

每当您更改“本机”方面的任何内容时,您都需要通过 xCode (或使用yarn ios)重建应用程序。

之后您将不会再看到该错误


小智 -1

看到这条推文,看起来您需要构建一个自定义开发客户端:https://twitter.com/Baconbrix/status/1542574116850524162 ?s=20&t=pbf86KkE8JkhY5ZQ4Z_w_g