Skip to content

Commit 1de360f

Browse files
blakefcipolleschi
andauthored
Turbo Native Modules - Documentation ported from reactwg (facebook#4283)
* [NA] Turbo Native Modules: add docs * feat: Add New Architecture Appendix Port of https://github.com/reactwg/react-native-new-architecture/blob/main/docs/appendix.md * fix: update codegen docs with current CLI * docs: improve turbo native modules file layout * docs: Add syntax highlighing comments for diffs Made to look similar to Github diffs * docs: Add Fabric Native Modules placeholders * TM: Android: Add video of built app * TM: Sidebar simpler labels * TM: Fix internal links * TM: fix links + add codegen notes * TM: fix language linter issues * TM: Add iOS documentation Add mp4 + webm videos Add css tweaks * Fix: first round of feedback * fix: lint error * TM: Consolidate appendix into a single table * chore: fix links * chore: fixup final round of feedback * TNM: add code example file paths * Fix empty spaces * import TurboModule as type * Fix punctuation * Fix linter * Fix sidebar and titles * Split pod install from output * put back extract library --------- Co-authored-by: Riccardo Cipolleschi <[email protected]> Co-authored-by: Riccardo Cipolleschi <[email protected]>
1 parent 49de307 commit 1de360f

25 files changed

+1009
-28
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from "react";
2+
import IOSContent from "./turbo-native-modules-ios.md";
3+
import AndroidContent from "./turbo-native-modules-android.md";
4+
5+
export function TurboNativeModulesIOS() {
6+
return <IOSContent />;
7+
}
8+
9+
export function TurboNativeModulesAndroid() {
10+
return <AndroidContent />;
11+
}

docs/appendix.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Appendix
2+
3+
## I. Terminology
4+
5+
- **Spec** - TypeScript or Flow code that describes the API for a Turbo Native Module or Fabric Native component. Used by **Codegen** to generate boilerplate code.
6+
7+
- **Turbo Native Modules** - Native libraries that have no User Interface (UI) for the user. Examples would be persistent storage, notifications, network events. These are accessible to your JavaScript application code as functions and objects.
8+
- **Fabric Native Component** - Native platform views that are available to your application JavaScript code through React Components.
9+
10+
- **Legacy Native Components** - Components which are running on the old React Native architecture.
11+
- **Legacy Native Modules** - Modules which are running on the old React Native architecture.
12+
13+
## II. Codegen Typings
14+
15+
You may use the following table as a reference for which types are supported and what they map to in each platform:
16+
17+
| Flow | TypeScript | Flow Nullable Support | TypeScript Nullable Support | Android (Java) | iOS (ObjC) |
18+
| -------------------------------------------------------------------------- | --------------------------------------------------- | ------------------------------------------------------- | ---------------------------------------------------- | ------------------------------------ | -------------------------------------------------------------- |
19+
| `string` | `string` | `?string` | <code>string &#124; null</code> | `string` | `NSString` |
20+
| `boolean` | `boolean` | `?boolean` | <code>boolean &#124; null</code> | `Boolean` | `NSNumber` |
21+
| Object Literal<br /><code>&#123;&#124; foo: string, ...&#124;&#125;</code> | <code>&#123; foo: string, ...&#125; as const</code> | <code>?&#123;&#124; foo: string, ...&#124;&#125;</code> | <code>?&#123; foo: string, ...&#125; as const</code> | \- | \- |
22+
| Object [[1](#notes)] | Object [[1](#notes)] | `?Object` | <code>Object &#124; null</code> | `ReadableMap` | `@` (untyped dictionary) |
23+
| <code>Array&lt;T&gt;</code> | <code>Array&lt;T&gt;</code> | <code>?Array&lt;T&gt;</code> | <code>Array&lt;T&gt; &#124; null</code> | `ReadableArray` | `NSArray` (or `RCTConvertVecToArray` when used inside objects) |
24+
| `Function` | `Function` | `?Function` | <code>Function &#124; null</code> | \- | \- |
25+
| <code>Promise&lt;T&gt;</code> | <code>Promise&lt;T&gt;</code> | <code>?Promise&lt;T&gt;</code> | <code>Promise&lt;T&gt; &#124; null</code> | `com.facebook.react.bridge.Promise` | `RCTPromiseResolve` and `RCTPromiseRejectBlock` |
26+
| Type Unions<br /><code>'SUCCESS'&#124;'FAIL'</code> | Type Unions<br /><code>'SUCCESS'&#124;'FAIL'</code> | Only as callbacks | | \- | \- |
27+
| Callbacks<br />`() =>` | Callbacks<br />`() =>` | Yes | | `com.facebook.react.bridge.Callback` | `RCTResponseSenderBlock` |
28+
| `number` | `number` | No | | `double` | `NSNumber` |
29+
30+
### Notes:
31+
32+
<b>[1]</b> We strongly recommend using Object literals intead of Objects.
33+
34+
:::info
35+
You may also find it useful to refer to the JavaScript specifications for the core modules in React Native. These are located inside the `Libraries/` directory in the React Native repository.
36+
:::
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
id: fabric-native-modules-android
3+
title: 'Fabric Native Modules: Android'
4+
---
5+
6+
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants';
7+
8+
:::caution
9+
This is work-in-progress... 👷
10+
:::

docs/fabric-native-modules-ios.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
id: fabric-native-modules-ios
3+
title: 'Fabric Native Modules: iOS'
4+
---
5+
6+
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants';
7+
8+
:::caution
9+
This is work-in-progress... 👷
10+
:::

docs/fabric-native-modules.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
id: fabric-native-modules-introduction
3+
title: 'Fabric Native Modules'
4+
---
5+
6+
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants';
7+
8+
:::caution
9+
This is work-in-progress... 👷
10+
:::

docs/native-platforms.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
id: native-platform
3+
title: Native Platform
4+
---
5+
6+
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants';
7+
8+
Your application may need access to platform features that aren’t directly available from React Native or one of the hundreds of [third-party libraries](https://reactnative.directory/) maintained by the community. Maybe you want to reuse some existing Objective-C, Swift, Java, Kotlin or C++ code from the JavaScript runtime. Whatever your reason, React Native exposes a powerful set of API to connect your native code to your JavaScript application code.
9+
10+
This guide introduces:
11+
12+
- **Turbo Native Modules:** native libraries that have no User Interface (UI) for the user. Examples would be persistent storage, notifications, network events. These are accessible to your user as JavaScript functions and objects.
13+
- **Fabric Native Component:** native platform views, widgets and controllers that are available to your application's JavaScript code through React Components.
14+
15+
:::note
16+
You might have previously been familiar with:
17+
18+
- [Legacy Native Modules](./legacy/native-modules-intro);
19+
- [Legacy Native Components](./legacy/native-components-android);
20+
21+
These are our deprecated native module and component API. You can still use many of these legacy libraries with the New Architecture thanks to our interop layers. You should consider:
22+
23+
- using alternative libraries,
24+
- upgrading to newer library versions that have first-class support for the New Architecture, or
25+
- port these libraries yourself to Turbo Native Modules or Fabric Native Components.
26+
27+
:::
28+
29+
1. Turbo Native Modules
30+
- [Introduction](turbo-native-modules.md)
31+
- [Android](turbo-native-modules-android.md)
32+
- [iOS](turbo-native-modules-ios.md)
33+
2. Fabric Native Components
34+
- [Introduction](fabric-native-modules.md)
35+
- [Android](fabric-native-modules-android.md)
36+
- [iOS](fabric-native-modules-ios.md)

docs/the-new-architecture/codegen-cli.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,38 @@
22

33
Calling Gradle or manually calling a script might be hard to remember and it requires a lot of cerimony.
44

5-
To simplify it, we created a CLI tool that can help you running those tasks: the **Codegen** cli.
6-
7-
```shell
8-
npx react-native codegen [--path path] [--platform string] [--outputPath path]
5+
To simplify it, we created a CLI tool that can help you running those tasks: the **Codegen** cli. This command runs [react-native-codegen](https://www.npmjs.com/package/react-native-codegen) for your project. The following options are available:
6+
7+
```sh
8+
npx @react-native-community/cli codegen --help
9+
Usage: rnc-cli codegen [options]
10+
11+
Options:
12+
--verbose Increase logging verbosity
13+
--path <path> Path to the React Native project root. (default: "/Users/MyUsername/projects/my-app")
14+
--platform <string> Target platform. Supported values: "android", "ios", "all". (default: "all")
15+
--outputPath <path> Path where generated artifacts will be output to.
16+
-h, --help display help for command
917
```
1018

11-
This command runs [react-native-codegen](https://www.npmjs.com/package/react-native-codegen) for your project. The following options are available:
12-
13-
- `--path` - Path to `package.json`. The default path is the current working directory.
14-
- `--platform` - Target platform. Supported values: `android`, `ios`, `all`. The default value is `all`.
15-
- `--outputPath` - Output path. The default value is the value defined in `codegenConfig.outputDir`.
16-
1719
## Examples
1820

1921
- Read `package.json` from the current working directory, generate code based on its codegenConfig.
2022

2123
```shell
22-
npx react-native codegen
24+
npx @react-native-codegen/cli codegen
2325
```
2426

2527
- Read `package.json` from the current working directory, generate iOS code in the location defined in the codegenConfig.
2628

2729
```shell
28-
npx react-native codegen --platform ios
30+
npx @react-native-codegen/cli codegen --platform ios
2931
```
3032

3133
- Read `package.json` from `third-party/some-library`, generate Android code in `third-party/some-library/android/generated`.
3234

3335
```shell
34-
npx react-native codegen \
36+
npx @react-native-codegen/cli codegen \
3537
--path third-party/some-library \
3638
--platform android \
3739
--outputPath third-party/some-library/android/generated

docs/the-new-architecture/pure-cxx-modules.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Pure C++ Turbo Native Modules
1+
# Cross-Platform Native Modules (C++)
22

33
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants';
44

docs/the-new-architecture/using-codegen.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,20 @@ This structure has been generated by using the value `all` for the `codegenConfi
132132

133133
**Codegen** for iOS relies on some Node scripts that are invoked during the build process. The scripts are located in the `SampleApp/node_modules/react-native/scripts/` folder.
134134

135-
The main script is the `generate-Codegen-artifacts.js` script. To invoke the script, you can run this command from the root folder of your app:
135+
The main script is the `generate-codegen-artifacts.js` script. To invoke the script, you can run this command from the root folder of your app:
136136

137137
```bash
138-
node node_modules/react-native/scripts/generate-Codegen-artifacts.js \
139-
--path <path/to/your/app> \
140-
--outputPath <an/output/path> \
141-
--targetPlatform <android | ios>
138+
node node_modules/react-native/scripts/generate-codegen-artifacts.js
139+
140+
Usage: generate-codegen-artifacts.js -p [path to app] -t [target platform] -o [output path]
141+
142+
Options:
143+
--help Show help [boolean]
144+
--version Show version number [boolean]
145+
-p, --path Path to the React Native project root. [required]
146+
-t, --targetPlatform Target platform. Supported values: "android", "ios",
147+
"all". [required]
148+
-o, --outputPath Path where generated artifacts will be output to.
142149
```
143150

144151
where:
@@ -152,7 +159,7 @@ where:
152159
Running the script with these arguments:
153160

154161
```shell
155-
node node_modules/react-native/scripts/generate-Codegen-artifacts.js \
162+
node node_modules/react-native/scripts/generate-codegen-artifacts.js \
156163
--path . \
157164
--outputPath ios/ \
158165
--targetPlatform ios

0 commit comments

Comments
 (0)