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

Guide to creating a New Architecture app from template #3056

Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
06a3766
Start new template guide
lindboe Apr 5, 2022
f6aff0d
Update title
lindboe Apr 7, 2022
e7446f2
Use tabs for target OS
lindboe Apr 7, 2022
be2eb18
Capitalize New Architecture, simplify
lindboe Apr 7, 2022
8754e60
Preliminary section for Hermes
lindboe Apr 7, 2022
a93abdd
Reword to emphasize importance of Hermes usage
lindboe Apr 8, 2022
5e9a0d9
Show new arch in use
lindboe Apr 11, 2022
a1463d8
Add build speed article link
lindboe Apr 11, 2022
77dd04d
Add pro tip for pod install alias
lindboe Apr 11, 2022
7e0ccf0
Restructure, repeat less
lindboe Apr 11, 2022
e98f1b1
Note about Expo
lindboe Apr 11, 2022
86a434c
Include command on uninstalling global CLI
lindboe Apr 12, 2022
3854b96
How to learn more
lindboe Apr 12, 2022
2105e4f
Remove headers in tabs
lindboe Apr 12, 2022
ea370fb
Make header more clear
lindboe Apr 12, 2022
eaa0ee2
Use quote block less often
lindboe Apr 12, 2022
7ea7ef0
Opt for instructions using XCode
lindboe Apr 12, 2022
02a9b4e
Fix lint issue
lindboe Apr 12, 2022
f845267
Improve wording
lindboe Apr 12, 2022
c0a3d43
Use product name
lindboe Apr 12, 2022
d5bc865
Fix line wraps
lindboe Apr 12, 2022
eea036b
Reword based on feedback
lindboe Apr 12, 2022
f5e1324
Note use of bundle install
lindboe Apr 12, 2022
aada4dc
Pod removal instructions
lindboe Apr 12, 2022
df4c17e
Convert quotes to admonitions
lindboe Apr 12, 2022
9e06f9d
Convert Note: to admonitions
lindboe Apr 12, 2022
cbb01bc
Feedback: Change admonitions to caution
lindboe Apr 13, 2022
1ea529b
PR feedback
lindboe Apr 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/_getting-started-linux-android.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import RemoveGlobalCLI from './\_remove-global-cli.md';

## Installing dependencies

You will need Node, the React Native command line interface, a JDK, and Android Studio.
Expand Down Expand Up @@ -77,7 +79,7 @@ React Native has a built-in command line interface. Rather than install and mana

<h2>Creating a new application</h2>

> If you previously installed a global `react-native-cli` package, please remove it as it may cause unexpected issues.
<RemoveGlobalCLI />

React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using `npx`, which ships with Node.js. Let's create a new React Native project called "AwesomeProject":

Expand Down
4 changes: 3 additions & 1 deletion docs/_getting-started-macos-android.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import RemoveGlobalCLI from './\_remove-global-cli.md';

## Installing dependencies

You will need Node, Watchman, the React Native command line interface, a JDK, and Android Studio.
Expand Down Expand Up @@ -89,7 +91,7 @@ React Native has a built-in command line interface. Rather than install and mana

<h2>Creating a new application</h2>

> If you previously installed a global `react-native-cli` package, please remove it as it may cause unexpected issues.
<RemoveGlobalCLI />

React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using `npx`, which ships with Node.js. Let's create a new React Native project called "AwesomeProject":

Expand Down
4 changes: 2 additions & 2 deletions docs/_getting-started-macos-ios.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import M1Cocoapods from './\_markdown-m1-cocoapods.mdx';
import M1Cocoapods from './\_markdown-m1-cocoapods.mdx'; import RemoveGlobalCLI from './\_remove-global-cli.md';

## Installing dependencies

Expand Down Expand Up @@ -55,7 +55,7 @@ React Native has a built-in command line interface. Rather than install and mana

## Creating a new application

> If you previously installed a global `react-native-cli` package, please remove it as it may cause unexpected issues.
<RemoveGlobalCLI />

You can use React Native's built-in command line interface to generate a new project. Let's create a new React Native project called "AwesomeProject":

Expand Down
4 changes: 3 additions & 1 deletion docs/_getting-started-windows-android.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import RemoveGlobalCLI from './\_remove-global-cli.md';

<h2>Installing dependencies</h2>

You will need Node, the React Native command line interface, a JDK, and Android Studio.
Expand Down Expand Up @@ -108,7 +110,7 @@ React Native has a built-in command line interface. Rather than install and mana

<h2>Creating a new application</h2>

> If you previously installed a global `react-native-cli` package, please remove it as it may cause unexpected issues.
<RemoveGlobalCLI />

React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using `npx`, which ships with Node.js. Let's create a new React Native project called "AwesomeProject":

Expand Down
5 changes: 5 additions & 0 deletions docs/_remove-global-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
> If you previously installed a global `react-native-cli` package, please remove it as it may cause unexpected issues:
>
> ```shell
> npm uninstall -g react-native-cli @react-native-community/cli
cortinico marked this conversation as resolved.
Show resolved Hide resolved
> ```
133 changes: 130 additions & 3 deletions docs/the-new-architecture/use-app-template.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,134 @@
---
id: use-app-template
title: Using the New App Template
title: Creating a New Architecture App
---

This section describes the new app template generated by the React Native CLI and how to use it properly.
It should explain how to create a new app, which command should be issued to install the dependencies and to run it on the different platforms.
import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import constants from '@site/core/TabsConstants';

import RemoveGlobalCLI from '.././\_remove-global-cli.md';

This page will help you create a new React Native app that uses the New Architecture.

## Development environment

Before continuing, make sure you've followed all the steps in [Setting up the
development environment](getting-started.md), under the **React Native CLI
Quickstart** tab.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Before continuing, make sure you've followed all the steps in [Setting up the
development environment](getting-started.md), under the **React Native CLI
Quickstart** tab.
Before continuing, make sure you've followed all the steps in [Setting up the development environment](getting-started.md), under the **React Native CLI Quickstart** tab.


If following the setup guide, stop when you reach the section **Running your React Native
Application**, and resume following this guide.
cipolleschi marked this conversation as resolved.
Show resolved Hide resolved

**Note**: The New Architecture cannot currently be enabled in an Expo app.

## Creating a new application

<RemoveGlobalCLI />

If you already have your development environment set up, create a new React Native project from the template:

```shell
npx react-native init AwesomeProject
lindboe marked this conversation as resolved.
Show resolved Hide resolved
```

If specifying a versioned template, use version 0.68 or later.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
If specifying a versioned template, use version 0.68 or later.
**Note:** the New Architecture is available from version 0.68 or later.

I found personally confusing the If specifying a version. What does that mean? Should we push for using a versioned template? Or in case a user wants to use a versioned template, we are suggesting using version 0.68 or later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter, based on the discussion at #3056 (comment)

The intro is also supposed to mention compatibility with 0.68+, so we could just move it to there.


## Configuration

Follow the steps below to enable the New Architecture and build the app.

### Enable Hermes

Hermes is an open-source JavaScript engine optimized for React Native. [Hermes will be the default engine in the future](https://github.com/reactwg/react-native-new-architecture/discussions/4), and we highly recommend you use it.

Please [follow the instructions on the React Native website](hermes.md) in order to enable Hermes in your application.

### Enable the New Architecture

#### Target OS

<Tabs groupId="platform" defaultValue={constants.defaultPlatform} values={constants.platforms} className="pill-tabs">
<TabItem value="ios">

Navigate to the `ios` directory and run the following:

```shell
# from `ios` directory
RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
lindboe marked this conversation as resolved.
Show resolved Hide resolved
lindboe marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted to go with bundle exec here because I've seen several places that say that's what to do going forward, but I noticed 1. No setup instructions exist that tell you to run bundle install, but I did need to do that, and 2. I don't think other places in the docs mention using bundle exec instead now.

It doesn't seem like a huge deal, if you don't bundle install first the bundle exec failure will tell you to, but wondering if that's maybe something to follow up on later?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good call. I have to summon @cortinico about this because I haven't joined the team yet when the decision was taken, so he could have more context on this.

For what concerns the doc, I'd rather stay consistent. It's okay to suggest to use bundle exec but, if that's the first time in the guide, I will also add that they should run bundle install once before.

Suggested change
RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
bundle install && RCT_NEW_ARCH_ENABLED=1 bundle exec pod install

```

Then build and run the app as usual:

```shell
npx react-native run-ios
```

> **Tip**: You need to re-run `pod install` each time a dependency with native
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cortinico: do we have any :::-box to wrap these tips nicely, instead of using quotes?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we do. I saw you folks already sorted this out, but in case you're wondering how this feature works for the future https://docusaurus.io/docs/markdown-features/admonitions

> code changes. Make this command easier to run by adding it to `scripts` to your
> project's `package.json` file:
>
> ```
> "scripts": {
> "pod-install": "RCT_NEW_ARCH_ENABLED=1 bundle exec pod install"
> }
> ```
>
> and run it with `yarn pod-install`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> and run it with `yarn pod-install`.
> and run it with `yarn pod-install`. Following `pod install` execution won't require to run `bundle install` again: this instruction should be executed only once.

To follow-up from my previous comment.


#### Troubleshooting

##### `react-native run-ios` fails

If you see a build failure from `react-native run-ios`, there may be cached files from a previous build with
the old architecture. Clean the build cache and try again:
lindboe marked this conversation as resolved.
Show resolved Hide resolved

1. Open the project `ios/project.xcworkspace` in Xcode
2. In XCode, choose Product > Clean Build Folder
3. Try building and running the app again

cipolleschi marked this conversation as resolved.
Show resolved Hide resolved
</TabItem>
<TabItem value="android">

Set the `newArchEnabled` property to `true` by **either**:

- Changing the corresponding line in `android/gradle.properties`
- Setting the environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`

Then build and run the app as usual:
lindboe marked this conversation as resolved.
Show resolved Hide resolved

```shell
npx react-native run-android
lindboe marked this conversation as resolved.
Show resolved Hide resolved
```

> **Note**: You may notice longer build times with the New Architecture, due to
> additional step of C++ compilation with the Android NDK. To improve your build
> time, see
> [Speeding Up Your Build Phase](docs/build-speed.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> **Note**: You may notice longer build times with the New Architecture, due to
> additional step of C++ compilation with the Android NDK. To improve your build
> time, see
> [Speeding Up Your Build Phase](docs/build-speed.md).
:::info
You may notice longer build times with the New Architecture, due to additional step of C++ compilation with the Android NDK. To improve your build time, see [Speeding Up Your Build Phase](docs/build-speed.md).
:::

The :::info syntax wraps the block in a nicely styled box. There are different alternatives available, but I can't find a reference for them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good to know, thanks!


</TabItem>
</Tabs>

### Confirming the New Architecture is in use

After you build and run the app, when Metro serves the JavaScript bundle, you
should see `"fabric": true` in the Metro logs:
lindboe marked this conversation as resolved.
Show resolved Hide resolved

<img src="/docs/assets/metro-new-arch.png" alt="Metro shows fabric: true" width="600" />

### Want to know more?
cipolleschi marked this conversation as resolved.
Show resolved Hide resolved

If you'd like to view the code changes relevant for the New Architecture, take a
look at the [upgrade
helper from version 0.67.4 to 0.68.0](https://react-native-community.github.io/upgrade-helper/?from=0.67.4&to=0.68.0).
Files that were added for the New Architecture are marked with a yellow banner.
lindboe marked this conversation as resolved.
Show resolved Hide resolved

For further explanations of what each file is doing, check out these guides to walk through the changes step-by-step:

#### Android

- [Enabling TurboModules on Android](new-architecture-app-modules-android.md)
lindboe marked this conversation as resolved.
Show resolved Hide resolved
- [Enabling Fabric on Android](new-architecture-app-renderer-android.md)

#### iOS

- [Enabling TurboModules on iOS](new-architecture-app-modules-ios.md)
- [Enabling Fabric on iOS](new-architecture-app-renderer-ios.md)
Binary file added website/static/docs/assets/metro-new-arch.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.