Skip to content

Commit 696e5b2

Browse files
author
Riccardo Cipolleschi
committed
[RN][New Architecture] Update Playbook with 0.72 changes
1 parent 4edd396 commit 696e5b2

File tree

4 files changed

+46
-316
lines changed

4 files changed

+46
-316
lines changed

docs/new-architecture-app-intro.md

Lines changed: 38 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -19,174 +19,74 @@ This guide is written with the expectation that you’re using the [**latest** R
1919

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

22-
## Use Hermes
22+
Remember to run `yarn` after upgrading.
2323

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
24+
:::important
3125

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.
26+
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 `⌘ + ⇪ + k`) 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.
3327

3428
:::
3529

36-
## iOS - Build the Project
30+
## Android - Enable the New Architecture
3731

38-
After upgrading the project, there are a few changes you need to apply:
32+
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.
3933

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

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

47-
2. Create a `.xcode.env` file to export the location of the NODE_BINARY. Navigate to the `ios` folder and run this command:
46+
## iOS - Enable the New Architecture
4847

49-
```sh
50-
echo 'export NODE_BINARY=$(command -v node)' > .xcode.env
51-
```
52-
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.
48+
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.
5549

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

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

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

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.
68-
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-
:::
59+
It’s now time to run your app to verify that everything works correctly:
7460

75-
For example, if you use the template, your project structure for what concerns iOS should look like this:
61+
```bash
62+
# To run android
63+
yarn android
7664

65+
# To run iOS
66+
yarn ios
7767
```
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.
100-
101-
## iOS - Make your AppDelegate conform to `RCTAppDelegate`
102-
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:
10868

109-
```diff
110-
- #import <React/RCTBridgeDelegate.h>
111-
+ #import <RCTAppDelegate.h>
112-
#import <UIKit/UIKit.h>
113-
114-
- @interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
115-
+ @interface AppDelegate : RCTAppDelegate
116-
117-
- @property (nonatomic, strong) UIWindow *window;
69+
In your Metro terminal log, you will now see the following log to confirm that Fabric is running correctly:
11870

119-
@end
12071
```
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
72+
BUNDLE ./App.tsx
73+
LOG Running "App" with {"fabric":true,"initialProps":{"concurrentRoot": "true"},"rootTag":1}
15074
```
15175

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-
:::
76+
## Advanced - Pass your component in the interop layer
15577

156-
## iOS - Run pod install
78+
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.
15779

158-
```bash
159-
// Run pod install with the flags
160-
RCT_NEW_ARCH_ENABLED=1 pod install
161-
```
80+
Starting from React Native 0.72, 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.
16281

163-
## Android - Prerequisites
82+
<!-- TODO: Add link to the WG as soon as we publish it. -->
16483

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.
166-
167-
You will only need to update your `android/gradle.properties` file as follows:
168-
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
177-
```
178-
179-
That's it!
180-
181-
It’s now time to run your Android app to verify that everything works correctly:
84+
You can read more about the interoperability layer and how to use it [here](). Follow this guide to register your components and then rerun your app with the commands:
18285

18386
```bash
184-
yarn react-native run-android
185-
```
87+
# To run android
88+
yarn android
18689

187-
In your Metro terminal log, you will now see the following log to confirm that Fabric is running correctly:
188-
189-
```
190-
BUNDLE ./App.js
191-
LOG Running "App" with {"fabric":true,"initialProps":{"concurrentRoot": "true"},"rootTag":1}
90+
# To run iOS
91+
yarn ios
19292
```

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)