在另一个 React-Native 库中使用 React-Native 库 [英] Using React-Native library inside another React-Native library

查看:52
本文介绍了在另一个 React-Native 库中使用 React-Native 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 React-Native 应用程序然后我使用这个种子创建了一个 React-Native 库 github.com/frostney/react-native-create-library

I created a React-Native application Then I created a React-Native Library using this seed github.com/frostney/react-native-create-library

现在,我需要使用这个包 https://github.com/toystars/react-native-geo-fence图书馆内.

Now, I need to use this package https://github.com/toystars/react-native-geo-fence Inside of the Library.

问题是:该库不是 react-native 应用程序,geo-fence 库需要链接.

Problem is: The library is not a react-native application, and the geo-fence lib needs linking.

当然,我无法更改 React-Native 应用程序,也无法直接在其中使用地理围栏.

I cant change the React-Native App and can not use the geo-fence directly inside of it, of course.

逻辑需要保留在我创建的库中.

The logic will need to stay inside the Library i created.

当我链接我创建的库(已经带有地理围栏包)时,使用我创建的应用程序,应用程序中没有发生地理围栏 gradle 设置和 android 配置.

When i linked the Library i created (with the geo fence package on it already), with the App i created, the geo-fence gradle settings and android configurations didn't happen at the APP.

  • 这仅涉及 Android

推荐答案

无法将 react-native 库链接到另一个 react-native 库.

It is not possible to link a react-native library to another react-native library.

因此,正确的步骤是添加任何需要链接的第三方 react-native 库,您想在自己的 react-native 库中使用这些库,作为 package.json 上的 peerDependency.

So the correct procedure is to add any third party react-native library, that requires link, that you want to use inside your own react-native library, as peerDependency on package.json.

这样,第三方库将直接安装在应用程序上,并链接到应用程序,但使用第三方库的逻辑将在您自己的内部.

This way the third party lib will be installed directly at the app, and will be linked, necessarily to the app, but the logic using the third party lib will be inside your own.

因此您可以创建一个库,添加 react-native-geo-fence 作为您的库的 peerDependency,然后根据需要进行编码.在此之后,使用您的 lib 的应用程序必须安装它并手动链接 react-native-geo-fence,然后就是这样.

So you can create a lib, add react-native-geo-fence as peerDependency of your lib, then code as you wish. After this, the app using your lib, will have to install it and link manually the react-native-geo-fence, then that's it.

这篇关于在另一个 React-Native 库中使用 React-Native 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆