From 66171e7e012b9d17a9b7ce310eed7a60e0f11c08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Fri, 16 Jul 2021 09:06:03 +0800 Subject: [PATCH] =?UTF-8?q?post:=E5=A2=9E=E5=8A=A0React=20Native=E6=96=87?= =?UTF-8?q?=E7=AB=A0=E5=86=85=E5=AE=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/_posts/react-native-traps.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 +``` + +完成连接以后,就可以在项目中正常的使用完成安装的库了。