Skip to content

Commit c982253

Browse files
cipolleschiRiccardo Cipolleschi
andauthored
[RN][New Architecture] Update Playbook with 0.72 changes (facebook#3765)
Co-authored-by: Riccardo Cipolleschi <cipolleschi@fb.com>
1 parent 6873109 commit c982253

File tree

4 files changed

+71
-308
lines changed

4 files changed

+71
-308
lines changed

docs/new-architecture-app-intro.md

Lines changed: 63 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ title: Prerequisites for Applications
44
---
55

66
import NewArchitectureWarning from './\_markdown-new-architecture-warning.mdx';
7-
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
89
import constants from '@site/core/TabsConstants';
910

1011
<NewArchitectureWarning/>
@@ -19,174 +20,106 @@ This guide is written with the expectation that you’re using the [**latest** R
1920

2021
You can find instructions on how to upgrade in the page [upgrading to new versions](/docs/upgrading).
2122

22-
## Use Hermes
23+
Remember to re-install the dependencies after upgrading (run `npm install` or `yarn`).
2324

24-
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.
25-
26-
We highly recommend using Hermes in your application. With Hermes enabled, you can use the JavaScript debugger in Flipper to directly debug your JavaScript code.
27-
28-
Please [follow the instructions on the Hermes page](hermes) to learn how to enable/disable Hermes.
29-
30-
:::caution
25+
:::important
3126

32-
**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.
27+
Whenever you have to rename some files in the `ios` folder, please **use Xcode to rename them**. This ensure that the file references are updated in the Xcode project as well. You might need to clean the build folder (**Project****Clean Build Folder** or <kbd>Cmd ⌘</kbd> + <kbd>Shift ⇪</kbd> + <kbd>K</kbd>) before re-building the app. If the file is renamed outside of Xcode, you may need to click on the old `.m` file reference and Locate the new file.
3328

3429
:::
3530

36-
## iOS - Build the Project
31+
## Android - Enable the New Architecture
3732

38-
After upgrading the project, there are a few changes you need to apply:
33+
If you successfully updated your project to the latest version of React Native, you **already meet** all the prerequisites to use the New Architecture on Android.
3934

40-
1. Target the proper iOS version. Open the `Podfile` and apply this change:
35+
You will only need to update your `android/gradle.properties` file as follows:
4136

4237
```diff
43-
- platform :ios, '11.0'
44-
+ platform :ios, '12.4'
38+
# Use this property to enable support to the new architecture.
39+
# This will allow you to use TurboModules and the Fabric render in
40+
# your application. You should enable this flag either if you want
41+
# to write custom TurboModules/Fabric components OR use libraries that
42+
# are providing them.
43+
-newArchEnabled=false
44+
+newArchEnabled=true
4545
```
4646

47-
2. Create a `.xcode.env` file to export the location of the NODE_BINARY. Navigate to the `ios` folder and run this command:
48-
49-
```sh
50-
echo 'export NODE_BINARY=$(command -v node)' > .xcode.env
51-
```
47+
## iOS - Enable the New Architecture
5248

53-
If you need it, you can also open the file and replace the `$(command -v node)` with the path to the node executable.
54-
React Native also supports a local version of this file `.xcode.env.local`. This file is not synced with the repository to let you customize your local setup, if it differs from the Continuous Integration or the team one.
49+
If you successfully updated your project to the latest version of React Native, you **already meet** all the prerequisites to use the New Architecture on iOS.
5550

56-
2. Fix an API change in the `AppDelegate.m`. Open this file and apply this change:
51+
You will only need to reinstall your pods by running `pod install` with the right flag:
5752

58-
```diff
59-
#if DEBUG
60-
- return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
61-
+ return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
62-
#else
53+
```bash
54+
# Run pod install with the flag:
55+
RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
6356
```
6457

65-
## iOS - Use Objective-C++ (`.mm` extension)
58+
## Running the App
6659

67-
Turbo Native Modules can be written using Objective-C or C++. In order to support both cases, any source files in the user project space 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.
60+
It’s now time to run your app to verify that everything works correctly:
6861

69-
:::important
70-
71-
**Use Xcode to rename existing files** to ensure file references persist in your project. You might need to clean the build folder (_Project → Clean Build Folder_) before re-building the app. If the file is renamed outside of Xcode, you may need to click on the old `.m` file reference and Locate the new file.
72-
73-
:::
62+
<Tabs groupId="run-app" queryString defaultValue={constants.defaultPackageManager} values={constants.packageManagers} >
63+
<TabItem value="yarn">
7464

75-
For example, if you use the template, your project structure for what concerns iOS should look like this:
65+
```bash
66+
# To run android
67+
yarn android
7668

69+
# To run iOS
70+
yarn ios
7771
```
78-
AppName
79-
├── ...
80-
├── ios
81-
│ ├── Podfile
82-
│ ├── Podfile.lock
83-
│ ├── Pods
84-
│ │ └── ...
85-
│ ├── AppName
86-
│ │ ├── AppDelegate.h
87-
│ │ ├── AppDelegate.mm
88-
│ │ ├── Images.xcassets
89-
│ │ ├── Info.plist
90-
│ │ ├── LaunchScreen.storyboard
91-
│ │ └── main.m
92-
│ ├── AppName.xcodeproj
93-
│ ├── AppName.xcworkspace
94-
│ ├── AppNameTests
95-
│ └── build
96-
└── ...
97-
```
98-
99-
All the `.m` files within the `AppName` inner folder should be renamed from `.m` to `.mm`. If you have packages that contains Objective-C code at the same level of the `AppName` folder, they should be renamed from `.m` to `.mm` too.
10072

101-
## iOS - Make your AppDelegate conform to `RCTAppDelegate`
73+
</TabItem>
74+
<TabItem value="npm">
10275

103-
The final step to configure iOS for the New Architecture is to extend a base class provided by React Native, called `RCTAppDelegate`.
104-
105-
This class provides a base implementation for all the required functionalities of the new architecture. If you need to customize some of them, you can override those methods, invoke `[super methodNameWith:parameters:];` collecting the returned value and customize the bits you need to customize.
106-
107-
1. Open the `ios/<AppName>/AppDelegate.h` file and update it as it follows:
76+
```bash
77+
# To run android
78+
npm run android
10879

109-
```diff
110-
- #import <React/RCTBridgeDelegate.h>
111-
+ #import <RCTAppDelegate.h>
112-
#import <UIKit/UIKit.h>
80+
# To run iOS
81+
npm run ios
82+
```
11383

114-
- @interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
115-
+ @interface AppDelegate : RCTAppDelegate
84+
</TabItem>
85+
</Tabs>
11686

117-
- @property (nonatomic, strong) UIWindow *window;
87+
In your Metro terminal log, you will now see the following log to confirm that Fabric is running correctly:
11888

119-
@end
12089
```
121-
122-
2. Open the `ios/<AppName>/AppDelegate.mm` (remember that you have to rename the `AppDelegate.m` to `AppDelegate.mm` first) file and replace its content with the following:
123-
124-
```objc
125-
#import "AppDelegate.h"
126-
#import <React/RCTBundleURLProvider.h>
127-
128-
@implementation AppDelegate
129-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
130-
{
131-
self.moduleName = @"NameOfTheApp";
132-
return [super application:application didFinishLaunchingWithOptions:launchOptions];
133-
}
134-
135-
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
136-
{
137-
#if DEBUG
138-
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];
139-
#else
140-
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
141-
#endif
142-
}
143-
144-
- (BOOL)concurrentRootEnabled
145-
{
146-
return true;
147-
}
148-
149-
@end
90+
BUNDLE ./App.tsx
91+
LOG Running "App" with {"fabric":true,"initialProps":{"concurrentRoot": "true"},"rootTag":1}
15092
```
15193

152-
:::note
153-
The `moduleName` has to be the same string used in the `[RCTRootView initWithBridge:moduleName:initialProperties]` call in the original `AppDelegate.mm` file.
154-
:::
94+
## Advanced - Pass your component in the interop layer
15595

156-
## iOS - Run pod install
96+
If you followed the previous steps but your app uses some custom Native Components that have not been migrated to the New Architecture completely, you are going to see some reddish/pinkish boxes saying that the component is not compatible with Fabric. This is happening because custom Native Components written for the legacy architecture can't run as-is in the New Architecture.
15797

158-
```bash
159-
// Run pod install with the flags
160-
RCT_NEW_ARCH_ENABLED=1 pod install
161-
```
98+
Starting from **React Native `0.72.0`**, we worked on a interoperability layer to let you use legacy components in the New Architecture without having to wait for them to be migrated.
16299

163-
## Android - Prerequisites
100+
You can read more about the interoperability layer and how to use it [here](https://github.com/reactwg/react-native-new-architecture/discussions/135). Follow this guide to register your components and then rerun your app with the commands:
164101

165-
If you successfully updated your project to React Native `0.71.0`, you **already meet** all the prerequisites to use the New Architecture on Android.
102+
<Tabs groupId="run-app" queryString defaultValue={constants.defaultPackageManager} values={constants.packageManagers} >
103+
<TabItem value="yarn">
166104

167-
You will only need to update your `android/gradle.properties` file as follows:
105+
```bash
106+
# To run android
107+
yarn android
168108

169-
```diff
170-
# Use this property to enable support to the new architecture.
171-
# This will allow you to use TurboModules and the Fabric render in
172-
# your application. You should enable this flag either if you want
173-
# to write custom TurboModules/Fabric components OR use libraries that
174-
# are providing them.
175-
-newArchEnabled=false
176-
+newArchEnabled=true
109+
# To run iOS
110+
yarn ios
177111
```
178112

179-
That's it!
180-
181-
It’s now time to run your Android app to verify that everything works correctly:
113+
</TabItem>
114+
<TabItem value="npm">
182115

183116
```bash
184-
yarn react-native run-android
185-
```
186-
187-
In your Metro terminal log, you will now see the following log to confirm that Fabric is running correctly:
117+
# To run android
118+
npm run android
188119

120+
# To run iOS
121+
npm run ios
189122
```
190-
BUNDLE ./App.js
191-
LOG Running "App" with {"fabric":true,"initialProps":{"concurrentRoot": "true"},"rootTag":1}
192-
```
123+
124+
</TabItem>
125+
</Tabs>

docs/new-architecture-appendix.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ If you wish to invoke the codegen manually, you have two options:
125125
1. Invoking a Gradle task directly (Android).
126126
2. Invoking a script manually.
127127

128-
### Invoking a Gradle task directly
128+
### Android - Invoking a Gradle task directly
129129

130130
You can trigger the Codegen by invoking the following task:
131131

0 commit comments

Comments
 (0)