Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Native Modules Documentation #2261

Merged
merged 44 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e87ce68
feat: updating Native Modules docs
laurajohannet Oct 20, 2020
0d0d3b7
feat: update native modules documentation (missed the docs changes)
laurajohannet Oct 20, 2020
fc827e7
converting nativemodules to native modules
laurajohannet Oct 20, 2020
159e0c1
language lint tweaks
laurajohannet Oct 20, 2020
bfbfad1
Update docs/native-modules-ios.md
lauramedalia Oct 23, 2020
0e75f3c
Update website/versioned_docs/version-0.63/native-modules-android.md
lauramedalia Oct 23, 2020
c3b77f2
Update docs/native-modules-ios.md
lauramedalia Oct 23, 2020
7355271
Update docs/native-modules-ios.md
lauramedalia Oct 23, 2020
dcf1d80
Update docs/native-modules-ios.md
lauramedalia Oct 23, 2020
0ec1384
Update docs/native-modules-ios.md
lauramedalia Oct 23, 2020
e4c9890
Update docs/native-modules-ios.md
lauramedalia Oct 23, 2020
09f357e
Apply suggestions from code review
lauramedalia Oct 23, 2020
a259813
Apply suggestions from code review (android)
lauramedalia Oct 23, 2020
ac8517a
feat: apply code review comments that needed grammer. changes
laurajohannet Oct 23, 2020
ef92268
Merge branch 'native-modules-edits' of github.com:lauramedalia/react-…
laurajohannet Oct 23, 2020
408852a
feat: updating intro
laurajohannet Oct 23, 2020
909d133
feat: apply comment changes
laurajohannet Oct 23, 2020
4d69c24
feat: remove () from method names
laurajohannet Oct 25, 2020
6b3a3d7
feat: cleaning up docs/responding to comments
laurajohannet Oct 25, 2020
bf32ead
feat: adding the new titles to the original docs
laurajohannet Oct 30, 2020
911f2ab
feat: updating base doc title
laurajohannet Oct 30, 2020
38a7b97
feat: cleaning up notes and removing references to other mobile plat…
laurajohannet Nov 1, 2020
3c2b3ac
feat: updating some we's to you's
laurajohannet Nov 1, 2020
111532d
pulling direct manipulation out
laurajohannet Nov 6, 2020
7e5885d
fixing some outstanding yous and wes
laurajohannet Nov 6, 2020
ff2ed73
updating these to new titles
laurajohannet Nov 6, 2020
9754892
move ios/android native components section under native components
laurajohannet Nov 12, 2020
6f399bc
Adding platform agnostic note back (it was removed when removing cont…
laurajohannet Nov 12, 2020
5018cea
Merge remote-tracking branch 'upstream/master' into native-modules-edits
laurajohannet Nov 15, 2020
59574c3
fixing an out of date link to the getting started guides
laurajohannet Nov 18, 2020
4805bcf
correcting link
laurajohannet Nov 19, 2020
56afb60
adding turbomodules note
laurajohannet Nov 19, 2020
64e59b6
adding parentheses for method names
laurajohannet Nov 26, 2020
d5100df
native module consistency
laurajohannet Nov 27, 2020
a3f12f1
editing run ios/android commands
laurajohannet Nov 28, 2020
8b47329
using correct code block for java
laurajohannet Nov 28, 2020
2b0dbc5
removing this file, must have stuck around after a merge conflict but…
laurajohannet Nov 28, 2020
07e790b
only editing in 0.63 moving forward
laurajohannet Nov 28, 2020
e17e0a4
original_id is not needed
laurajohannet Nov 28, 2020
4022313
cleaning up white space
laurajohannet Nov 28, 2020
2e6f651
using correct Apostrophe characters
laurajohannet Nov 28, 2020
df1dd5d
moving argument types to a table
laurajohannet Nov 28, 2020
4ab243a
adding note about where we are adding the method
laurajohannet Nov 28, 2020
63dc05f
adding a link to info on turbo modules
laurajohannet Nov 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
615 changes: 407 additions & 208 deletions docs/native-modules-android.md

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions docs/native-modules-intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
id: native-modules-intro
title: Native Modules Intro
---

Sometimes a React Native app needs to access a native platform API that is not available by default in Javascript, for example the native APIs to access Apple or Android pay. Maybe you want to reuse some existing Objective-C, Swift, Java or C++ libraries without having to reimplement it in JavaScript, or write some high performance, multi-threaded code for things like image processing.

The NativeModule system exposes instances of Java/Objective-C/C++ (native) classes to JavaScript (JS) as JS objects, thereby allowing you to execute arbitrary native code from within JS. While we don't expect this feature to be part of the usual development process, it is essential that it exists. If React Native doesn't export a native API that your JS app needs you should be able to export it yourself!

## Native Module Setup

There are two ways to write a native module for your React Native application:

1. Directly within your React Native application’s iOS/Android projects
2. As a NPM package that can be installed as a dependency by your/other React Native applications

This guide will first walk you through implementing a native module directly within a React Native application. However the native module you build in the following guide can be distributed as an NPM package. Check out the [Setting Up a Native Module as a NPM Package](native-modules-setup) guide if you are interested in doing so.

## Getting Started

In the following sections we will walk you through guides on how to build a native module directly within a React Native application. As a prerequisite, you will need a React Native application to work within. You can follow the steps [here](environment-setup) to setup a React Native application if you do not already have one.

Imagine that you want to access the iOS/Android native calendar APIs from Javascript within a React Native application in order to create calendar events. React Native does not expose a Javascript API to communicate with the native calendar libraries. However, through native modules, you can write native code that communicates with native calendar APIs. Then you can invoke that native code through Javascript in your React Native application.

In the following sections you will create such a Calendar native module for both [Android](native-modules-android) and [iOS](native-modules-ios).
651 changes: 365 additions & 286 deletions docs/native-modules-ios.md

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions website/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
"native-modules-android": {
"title": "Native Modules"
},
"native-modules-intro": {
"title": "Native Modules Intro"
},
"native-modules-ios": {
"title": "Native Modules"
},
Expand Down Expand Up @@ -2297,6 +2300,9 @@
"version-0.5/version-0.5-native-modules-android": {
"title": "Native Modules"
},
"version-0.5/version-0.5-native-modules-intro": {
"title": "Native Modules Intro"
},
"version-0.5/version-0.5-native-modules-ios": {
"title": "Native Modules"
},
Expand Down Expand Up @@ -4035,13 +4041,16 @@
"title": "Native UI Components"
},
"version-0.63/version-0.63-native-modules-android": {
"title": "Native Modules"
"title": "Android Native Modules"
},
"version-0.63/version-0.63-native-modules-intro": {
"title": "Native Modules Intro"
},
"version-0.63/version-0.63-native-modules-ios": {
"title": "Native Modules"
"title": "iOS Native Modules"
},
"version-0.63/version-0.63-native-modules-setup": {
"title": "Native Modules Setup"
"title": "Native Modules NPM Package Setup"
},
"version-0.63/version-0.63-navigation": {
"title": "Navigating Between Screens"
Expand Down
5 changes: 3 additions & 2 deletions website/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@
"JavaScript Runtime": ["javascript-environment", "timers", "hermes"],
"Connectivity": ["network", "security"],
"Native Components and Modules": [
"native-modules-intro",
"native-modules-android",
"native-modules-ios",
"native-modules-setup",
"direct-manipulation"
],
"Guides (Android)": [
"native-modules-android",
"native-components-android",
"headless-js-android",
"signed-apk-android",
"removing-default-permissions"
],
"Guides (iOS)": [
"native-modules-ios",
"native-components-ios",
"linking-libraries-ios",
"running-on-simulator-ios",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions website/versioned_docs/version-0.5/native-modules-intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
id: version-0.5-native-modules-intro
title: Native Modules Intro
original_id: native-modules-intro
---

Sometimes a React Native app needs to access a native platform API that is not available by default in Javascript, for example the native APIs to access Apple or Android pay. Maybe you want to reuse some existing Objective-C, Swift, Java or C++ libraries without having to reimplement it in JavaScript, or write some high performance, multi-threaded code for things like image processing.

The NativeModule system exposes instances of Java/Objective-C/C++ (native) classes to JavaScript (JS) as JS objects, thereby allowing you to execute arbitrary native code from within JS. While we don't expect this feature to be part of the usual development process, it is essential that it exists. If React Native doesn't export a native API that your JS app needs you should be able to export it yourself!

## Native Module Setup

There are two ways to write a native module for your React Native application:

1. Directly within your React Native application’s iOS/Android projects
2. As a NPM package that can be installed as a dependency by your/other React Native applications

This guide will first walk you through implementing a native module directly within a React Native application. However the native module you build in the following guide can be distributed as an NPM package. Check out the [Setting Up a Native Module as a NPM Package](native-modules-setup) guide if you are interested in doing so.

## Getting Started

In the following sections we will walk you through guides on how to build a native module directly within a React Native application. As a prerequisite, you will need a React Native application to work within. You can follow the steps [here](environment-setup) to setup a React Native application if you do not already have one.

Imagine that you want to access the iOS/Android native calendar APIs from Javascript within a React Native application in order to create calendar events. React Native does not expose a Javascript API to communicate with the native calendar libraries. However, through native modules, you can write native code that communicates with native calendar APIs. Then you can invoke that native code through Javascript in your React Native application.

In the following sections you will create such a Calendar native module for both [Android](native-modules-android) and [iOS](native-modules-ios).
Loading