diff --git a/source/_posts/react-native-traps.md b/source/_posts/react-native-traps.md index 513f7ee..e49cc3e 100644 --- a/source/_posts/react-native-traps.md +++ b/source/_posts/react-native-traps.md @@ -38,3 +38,21 @@ source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git' ``` 即可完成CocoaPods镜像的切换。 + +## 连接原生依赖库 + +在React Native中有一些库是带有原生代码的,这些库除了需要使用`npm install`完成安装以外,还需要将原生代码连接进不同平台的应用中。 + +连接带有原生代码的库非常简单,只需要使用`react native link`命令。例如平时经常会使用的`react-native-safe-area-context`库和`react-native-vector-icons`库,在安装的时候就需要使用以下命令。 + +```bash +# 安装react-native-safe-area-context +npm install react-native-safe-area-context +npx react-native link react-native-safe-area-context + +# 安装react-native-vector-icons +npm install react-native-vector-icons +npx react-native link react-native-vector-icons +``` + +完成连接以后,就可以在项目中正常的使用完成安装的库了。