Skip to content

Commit d83cd3e

Browse files
committed
Merge pull request #300 from tadeuzagallo/doc-link-libraries
[ReactNative][Docs] Document how to link libraries
2 parents af447ff + b06cdf0 commit d83cd3e

File tree

5 files changed

+68
-1
lines changed

5 files changed

+68
-1
lines changed

docs/Libraries.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
id: libraries
3+
title: Linking Libraries
4+
layout: docs
5+
category: Guides
6+
permalink: docs/linking-libraries.html
7+
next: debugging
8+
---
9+
10+
Not every app uses all the native capabilities, and including the code to support
11+
all those features would impact in the binary size... But we still want to make
12+
easy to add these features whenever you need them.
13+
14+
With that in mind we exposed many of these features as independent static libraries.
15+
16+
For most of the libs it will be as simples as dragging two files, sometimes a third
17+
step will be necessary, but no more than that.
18+
19+
_All the libraries we ship with React Native live on the `Libraries` folder in
20+
the root of the repository. Some of them are pure JavaScript, and you just need
21+
to `require` it. Other libraries also rely on some native code, in that case
22+
you'll have to add these files to your app, otherwise the app will throw an
23+
error as soon as you try to use the library._
24+
25+
## Here the few steps to link your libraries that contain native code
26+
27+
### Step 1
28+
29+
If the library has native code, there must be a `.xcodeproj` file inside it's
30+
folder.
31+
Drag this file to your project on Xcode (usually under the `Libaries` group
32+
on Xcode);
33+
34+
![](/react-native/img/AddToLibraries.png)
35+
36+
### Step 2
37+
38+
Click on your main project file (the one that represents the `.xcodeproj`)
39+
select `Build Phases` and drag the static library from the `Products` folder
40+
insed the Library you are importing to `Link Binary With Libraries`
41+
42+
![](/react-native/img/AddToBuildPhases.png)
43+
44+
### Step 3
45+
46+
Not every library will need this step, what you need to consider is:
47+
48+
_Do I need to know the contents of the library at compile time?_
49+
50+
What that means is, are you using this library on the native site or just in
51+
JavaScript? If you are just using it in JavaScript, you are good to go!
52+
53+
54+
This step is not necessary for all libraries that we ship we React Native but
55+
`PushNotificationIOS` and `LinkingIOS`.
56+
57+
In the case of the `PushNotificationIOS` for example, you have to call a method
58+
on the library from your `AppDelegate` every time a new push notifiation is
59+
received.
60+
61+
For that we need to know the library's headers. To achieve that you have to go
62+
to your project's file, select `Build Settings` and search for `Header Search
63+
Paths`. There you should include the path to you library (if it has relevant
64+
files on subdirectories remember to make it `recursive`, like `React` on the
65+
example).
66+
67+
![](/react-native/img/AddToSearchPaths.png)

docs/NativeModulesIOS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Native Modules (iOS)
44
layout: docs
55
category: Guides
66
permalink: docs/nativemodulesios.html
7-
next: debugging
7+
next: libraries
88
---
99

1010
Sometimes an app needs access to platform API, and React Native doesn't have a corresponding wrapper yet. Maybe you want to reuse some existing Objective-C or C++ code without having to reimplement it in JavaScript. Or write some high performance, multi-threaded code such as image processing, network stack, database or rendering.
598 KB
Loading
820 KB
Loading
568 KB
Loading

0 commit comments

Comments
 (0)