React Native创建自定义组件/库 [英] React Native Create Custom Component/Library

查看:592
本文介绍了React Native创建自定义组件/库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在React Native中,某些第三方组件会编译自己的库,这些库可以包含在您的主React项目中.此类第三方库的示例如下:

In React Native, there are certain third-party components which compile their own libraries that can be included in your main React project. Examples of such third-party libraries are these:

  • https://github.com/naoufal/react-native-touch-id
  • https://github.com/lazaronixon/react-native-qrcode-reader
  • https://github.com/brentvatne/react-native-modal

现在,我非常想使用链接库(仅适用于iOS)创建自己的React Native组件,因此我只需要使用此方法链接的Cocoa库: http://moduscreate.com/react_native_custom_components_ios/

Now, I would very much like to create my own React Native component with a linked library (iOS only, so I only need the Cocoa library that I would link using this method: https://facebook.github.io/react-native/docs/linking-libraries-ios.html), and so far, all I found is this: http://moduscreate.com/react_native_custom_components_ios/

但是,生成的项目未指定库目标,并且无法链接到其他项目.

The resulting project does not, however, specify a library target, and is not linkable to a different project.

我也尝试过复制Touch ID存储库并尝试更改该用户的代码,但是,我发现它没有其他项目的引用就无法编译,而该项目又是要编译的项目.

I have also tried copying the Touch ID repository and try changing that one's code, but alas, I found it to be uncompilable without being referenced from a different project, which in turn would be the one to be compiled.

在哪里可以找到有关该操作方法的所有指南?谢谢!

Where can I find any guides at all regarding how to do that? Thanks!

推荐答案

1.命令:新库

React-native-cli提供 new-library 命令:

react-native new-library --name <YourNewLibraryName>

通过从Libraries目录中生成示例库. rel ="noreferrer">反应本地库.

Calling this will generate a sample library in your Libraries directory by copying sample file over from the react-native library.

React Native有一些专门用于编写母语的文档模块本地UI组件 ,具体取决于您要实现的目标.

React Native has a couple docs specifically for writing Native Modules and Native UI Components, depending on what you want to achieve.

完成操作后,通过遵循您已经提到的说明.

Link your component once you're done by following the instructions you already mentioned.

这篇关于React Native创建自定义组件/库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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