Skip to content

Commit e3408a9

Browse files
author
Riccardo Cipolleschi
committed
wip: migration guide review
1 parent f6f3c56 commit e3408a9

13 files changed

+183
-198
lines changed

docs/new-architecture-app-intro.md

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,25 @@ import NewArchitectureWarning from './\_markdown-new-architecture-warning.mdx';
77

88
<NewArchitectureWarning/>
99

10-
There’s a few prerequisites that should be addressed before the new architecture is enabled in your application.
10+
There’s a few prerequisites that should be addressed before the New Architecture is enabled in your application.
1111

1212
## Use a React Native nightly release
1313

1414
At this time, you must use a React Native nightly release in order to get access to the most up to date changes. Eventually, we will recommend targeting a minimum stable open source release.
1515

16-
This guide is written with the expectation that you’re using a specific nightly release. As new revisions of this guide are released, the target nightly release may be updated. The specific nightly version that we will be using throughout the rest of this guide is version `0.0.0-20220201-2008-79975d146`.
16+
This guide is written with the expectation that you’re using a specific nightly release. As new revisions of this guide are released, the target nightly release may be updated. The specific nightly version that we will be using throughout the rest of this guide is version `0.0.0-20220705-2052-71e89213a`.
1717

1818
Before upgrading your app to a specific nightly release, we recommend upgrading your app to the latest open source release. By upgrading to a published open source release first, you will be able to take advantage of tools like the [upgrade helper](https://react-native-community.github.io/upgrade-helper/) to determine what other changes may be required for your project.
1919

20-
As of this writing, the latest stable release is `0.67.2`. Once you have upgraded your project to this version successfully, you may proceed to targeting the `0.0.0-20220201-2008-79975d146` nightly release. You may target this nightly release the same way you’d target any other version of React Native:
20+
As of this writing, the latest stable release is `0.69.1`. Once you have upgraded your project to this version successfully, you may proceed to targeting the `0.0.0-20220705-2052-71e89213a` nightly release. You may target this nightly release the same way you’d target any other version of React Native:
2121

2222
```bash
23-
yarn add react-native@0.0.0-20220201-2008-79975d146
23+
yarn add react-native@0.0.0-20220705-2052-71e89213a
2424
```
2525

26-
## Install react-native-codegen
27-
28-
Make sure that you're using the latest version of the [`react-native-codegen`](https://www.npmjs.com/package/react-native-codegen) NPM package. At the time of writing it's `0.0.13`.
29-
30-
```bash
31-
yarn add react-native-codegen
32-
```
33-
34-
:::info
35-
36-
If you see an error like `***TypeError: RNCodegen.generateFromSchemas is not a function.***`, it means that you're using a older version of `react-native-codegen`.
37-
Make sure you don't have an older version installed under the `node_modules/react-native/node_modules` folder. You can remove that or reinstall everything in node_modules to fix the problem.
38-
39-
:::
40-
4126
### Android specifics
4227

43-
Using the new architecture on Android has some prerequisites that you need to meet:
28+
Using the New Architecture on Android has some prerequisites that you need to meet:
4429

4530
1. Using Gradle 7.x and Android Gradle Plugin 7.x
4631
2. Using the **new React Gradle Plugin**
@@ -54,18 +39,6 @@ cd android && ./gradlew wrapper --gradle-version 7.3 --distribution-type=all
5439

5540
While the AGP version should be updated inside the **top level** `build.gradle` file at the `com.android.tools.build:gradle` dependency line.
5641

57-
If you’re set with it, let’s now install the new Gradle plugin which is distributed through a NPM package called [**`react-native-gradle-plugin`**](https://www.npmjs.com/package/react-native-gradle-plugin). You can do so with:
58-
59-
```bash
60-
yarn add react-native-gradle-plugin
61-
```
62-
63-
You can control if you have the package already installed by doing:
64-
65-
```bash
66-
ls -la node_modules/react-native-gradle-plugin
67-
```
68-
6942
Now, you can edit your **top level** `settings.gradle` file to include the following line at the end of the file:
7043

7144
```groovy
@@ -82,7 +55,7 @@ buildscript {
8255
// ...
8356
dependencies {
8457
// Make sure that AGP is at least at version 7.x
85-
classpath("com.android.tools.build:gradle:7.0.4")
58+
classpath("com.android.tools.build:gradle:7.2.0")
8659
8760
// Add those lines
8861
classpath("com.facebook.react:react-native-gradle-plugin")
@@ -119,40 +92,18 @@ dependencies {
11992

12093
## Use Hermes
12194

122-
Hermes is an open-source JavaScript engine optimized for React Native. We highly recommend using Hermes in your application. With Hermes enabled, you will be able to use the JavaScript debugger in Flipper to directly debug your JavaScript code.
95+
Hermes is an open-source JavaScript engine optimized for React Native. Hermes is enabled by default and you have to explicitly disable it if you want to use JSC.
12396

124-
Please [follow the instructions on the React Native website](hermes) in order to enable Hermes in your application.
97+
We highly recommend using Hermes in your application. With Hermes enabled, you will be able to use the JavaScript debugger in Flipper to directly debug your JavaScript code.
98+
99+
Please [follow the instructions on the React Native website](hermes) to learn how to enable/disable Hermes.
125100

126101
:::caution
127102

128103
**iOS:** If you opt out of using Hermes, you will need to replace `HermesExecutorFactory` with `JSCExecutorFactory` in any examples used throughout the rest of this guide.
129104

130105
:::
131106

132-
## iOS: Enable C++17 language feature support
133-
134-
Your Xcode project settings need to be updated to support C++17 language features.
135-
136-
**Instructions**
137-
138-
1. Select your project in the Project navigator on the left (e.g. MyXcodeApp)
139-
2. Then, make sure your project is selected in the center pane (as opposed to a particular target in your project, e.g. MyXcodeApp under Project, not under Targets).
140-
3. Go to Build Settings
141-
4. Search for C++ Language Dialect or CLANG_CXX_LANGUAGE_STANDARD
142-
5. Make sure **C++17** is selected from the dropdown menu (or enter "c++17" directly into the value box).
143-
144-
If done correctly, your diff will show the following changes to your project file:
145-
146-
```ruby
147-
CLANG_CXX_LANGUAGE_STANDARD = "c++17"
148-
```
149-
150-
:::info
151-
152-
Your project should also be configured to support Folly. This should be done automatically once the library dependency is picked up, so no further changes to your project are necessary.
153-
154-
:::
155-
156107
## iOS: Use Objective-C++ (`.mm` extension)
157108

158109
TurboModules can be written using Objective-C or C++. In order to support both cases, any source files that include C++ code should use the `.mm` file extension. This extension corresponds to Objective-C++, a language variant that allows for the use of a combination of C++ and Objective-C in source files.

docs/new-architecture-app-modules-android.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ In this iteration of the guide we’re setting up the project to let you build f
1717

1818
:::
1919

20-
The code-gen will output some Java and some C++ code that now we need to build.
20+
The Codegen will output some Java and some C++ code that now we need to build.
2121

2222
Let’s edit your **module level** `build.gradle` to include the **two** `externalNativeBuild` blocks detailed below inside the `android{}` block:
2323

@@ -36,10 +36,15 @@ android {
3636
"GENERATED_SRC_DIR=$buildDir/generated/source",
3737
"PROJECT_BUILD_DIR=$buildDir",
3838
"REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid",
39-
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build"
39+
"REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build",
40+
"NODE_MODULES_DIR=$rootDir/../node_modules"
4041
cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1"
4142
cppFlags "-std=c++17"
4243
targets "myapplication_appmodules"
44+
// Fix for windows limit on number of character in file paths and in command lines
45+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
46+
arguments "NDK_APP_SHORT_COMMANDS=true"
47+
}
4348
}
4449
}
4550
}

docs/new-architecture-app-renderer-ios.md

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ end
3939

4040
## 2. Update your root view
4141

42-
The way to render your app with Fabric depends on your setup. Here is an example of how you can enable Fabric in your app with the `RN_FABRIC_ENABLED` compiler flag to enable/disable. Refer [RN-Tester’s AppDelegate](https://github.com/facebook/react-native/blob/main/packages/rn-tester/RNTester/AppDelegate.mm) as an example.
42+
How to render your app with Fabric depends on your setup. Here is an example of how you can enable Fabric in your app with the `RN_FABRIC_ENABLED` compiler flag to enable/disable. Refer [RN-Tester’s AppDelegate](https://github.com/facebook/react-native/blob/main/packages/rn-tester/RNTester/AppDelegate.mm) as an example.
4343

4444
```objc title="AppDelegate.mm"
4545
#ifdef RN_FABRIC_ENABLED
@@ -83,20 +83,6 @@ The way to render your app with Fabric depends on your setup. Here is an example
8383
#endif
8484
```
8585
86-
## 3. Add Babel Plugins
87-
88-
This will trigger the codegen that will run at the metro building time.
89-
90-
```javascript title="babel.config.js"
91-
module.exports = {
92-
presets: ['module:metro-react-native-babel-preset'],
93-
plugins: [
94-
'@babel/plugin-proposal-class-properties',
95-
'./node_modules/react-native/packages/babel-plugin-codegen'
96-
]
97-
};
98-
```
99-
10086
## 4. Run pod install
10187
10288
```bash

docs/new-architecture-appendix.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,31 @@ You may use the following table as a reference for which types are supported and
2727

2828
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.
2929

30-
## II. Invoking the code-gen during development
30+
## II. TypeScript to Native Type Mapping
31+
32+
You may use the following table as a reference for which types are supported and what they map to in each platform:
33+
34+
| TypeScript Type | Nullable Support? | Android (Java) | iOS | Note |
35+
| ---------------------------------------------- | -------------------------------------------------------- | ------------------------------------ | -------------------------------------------------------------- | ------------------------------------------------------------------------------ |
36+
| `string` | <code>string &#124; null </code> | `String` | `NSString` | |
37+
| `boolean` | <code>boolean &#124; null </code> | `Boolean` | `NSNumber` | |
38+
| `Float`, `Double`, or `Int32` | No | `double` | `NSNumber` | |
39+
| <code>{&#124; foo: string, ... &#124;}</code> | <code>{&#124; foo: string, ...&#124;} &#124; null</code> | | | Object literal. This is recommended over simply using Object, for type safety. |
40+
| `Object` | <code>Object &#124; null </code> | `ReadableMap` | `@{} (untyped dictionary)` | Recommended to use object literal (see above). |
41+
| `Array<*>` | <code>Array<\*> &#124; null </code> | `ReadableArray` | `NSArray` (or `RCTConvertVecToArray` when used inside objects) | |
42+
| `Function` | <code>Function &#124; null </code> | | | |
43+
| `Promise<*>` | <code>Promise<\*> &#124; null </code> | `com.facebook.react.bridge.Promise` | `RCTPromiseResolve` and `RCTPromiseRejectBlock` | |
44+
| Type aliases of the above | Yes | | | |
45+
| Type Unions <code>'SUCCESS'&#124;'FAIL'</code> | Only as callbacks. | | | Type unions only supported as callbacks. |
46+
| Callbacks: `( ) =>` | Yes | `com.facebook.react.bridge.Callback` | `RCTResponseSenderBlock` | Callback functions are not type checked, and are generalized as Objects. |
47+
48+
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.
49+
50+
## III. Invoking the code-gen during development
3151

3252
> This section contains information specific to v0.66 of React Native.
3353
34-
The code-gen is typically invoked at build time, but you may find it useful to generate your native interface code on demand for troubleshooting.
54+
The Codegen is typically invoked at build time, but you may find it useful to generate your native interface code on demand for troubleshooting.
3555

3656
If you wish to invoke the codegen manually, you have two options:
3757

@@ -40,7 +60,7 @@ If you wish to invoke the codegen manually, you have two options:
4060

4161
### Invoking a Gradle task directly
4262

43-
You can trigger the code-gen by invoking the following task:
63+
You can trigger the Codegen by invoking the following task:
4464

4565
```bash
4666
./gradlew generateCodegenArtifactsFromSchema --rerun-tasks
@@ -82,12 +102,12 @@ node node_modules/react-native/scripts/generate-specs-cli.js \
82102
[--libraryType all(default)|modules|components]
83103
```
84104

85-
> **NOTE:** The output artifacts of the code-gen are inside the build folder and should not be committed.
105+
> **NOTE:** The output artifacts of the Codegen are inside the build folder and should not be committed.
86106
> They should be considered only for reference.
87107
88108
##### Example
89109

90-
The following is a basic example of invoking the code-gen script to generate native iOS interface code for a library that provides native modules. The JavaScript spec sources for this library are located in a `js/` subdirectory, and this library’s native code expects the native interfaces to be available in the `ios` subdirectory.
110+
The following is a basic example of invoking the Codegen script to generate native iOS interface code for a library that provides native modules. The JavaScript spec sources for this library are located in a `js/` subdirectory, and this library’s native code expects the native interfaces to be available in the `ios` subdirectory.
91111

92112
```bash
93113
# Generate schema - only needs to be done whenever JS specs change
@@ -104,7 +124,7 @@ node node_modules/react-native/scripts/generate-specs-cli.js \
104124

105125
In the above example, the code-gen script will generate several files: `MyLibSpecs.h` and `MyLibSpecs-generated.mm`, as well as a handful of `.h` and `.cpp` files, all located in the `ios` directory.
106126

107-
## III. Note on Existing Apps
127+
## IV. Note on Existing Apps
108128

109129
This guide provides instructions for migrating an application that is based on the default app template that is provided by React Native. If your app has deviated from the template, or you are working with an application that was never based off the template, then the following sections might help.
110130

docs/new-architecture-intro.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
id: new-architecture-intro
3-
title: Adopting the New Architecture
3+
title: Migrating to the New Architecture
44
---
55

66
import NewArchitectureWarning from './\_markdown-new-architecture-warning.mdx';
@@ -28,4 +28,5 @@ The guide is divided into three sections:
2828
- Enabling the New Renderer (Fabric) in your App
2929
- [Android](new-architecture-app-renderer-android)
3030
- [iOS](new-architecture-app-renderer-ios)
31+
- [**Troubleshooting**](new-architecture-troubleshooting)
3132
- [**Appendix**](new-architecture-appendix)

0 commit comments

Comments
 (0)