Replies: 1 comment 3 replies
-
Does it make sense to also move the iOS template |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
tl;dr: From React Native 0.71, you will be able to enable the New Architecture without having to add any C++ code in your app. Similarly the app template has been cleaned of all the C++ code and the CMake files, you can still add it if needed
Hey all,
As the release of 0.71 is coming closer, we'd like to share some of the recent improvements for the New Architecture that we'll be shipped in 0.71 so you can get a sneak peak of how they will look like once 0.71 lands.
What has changed
Here a screenshot of how the Android template will change between 0.70 and 0.71 (iOS folder is omitted for brevity):
(So much red! 🟩🟥🟥🟥 red == good).
Practically, we did the following:
CMakeLists.txt
file needed to build those files.build.gradle
file needed to enabled the NDK.All the C++ files have been moved inside the framework in the
/defaults
package.Those files provide a convenience wrapper over the API inside React Native core by making registration of custom components easier.
The
OnLoad.cpp
and theCmakeLists.txt
files have been moved inside thedefault-app-setup
inside the framework. Those two files are autolinking-aware, and takes care of properly registering C++ components/modules coming from 3rd party packages. They're working in conjuction with the React Native CLI.The custom
build.gradle
logic has been moved inside the React Native Gradle Plugin which we were already using for the Codegen. More on the React Native Gradle Plugin in the new dedicate page in the websiteWhy is this important
Practically, we reduced the template LOC size by ~600 lines. This is crucial as less code == less things can go wrong during upgrades and less anti-patterns can spread around.
While removing code is always good, removing code from the template is even more crucial as it has a greater order of magnitude impact as those files gets copied over and over in new projects.
This also comes with a series of wins:
build.gradle
file by LOC and entirely removing theCMakeLists.txt
file from user space. Smaller build logic in user space => Less things can get misconfigured and go wrong during a react-native upgrade.What if you really want to have C++ code inside their app
In general, app developers should not need to use C++ code at all.
You should just include library (which can contain C++ code inside their module/component implementation), and write code in JS or platform (Java/Kotlin/ObjC).
However, if you still needs to include custom C++ code in your app you can still do it. You'll have to copy the files from the
default-app-setup
folder in user space and expand the default React Native's CMake setup. Beward that you'll be effectively "ejecting" from our setup,so you'll be responsible of their own upgrade to the CMake/C++ files.
We consider this an advanced use case, and we'll publish more docs around it in the future if needed.
How was this possible
I'd like to stress how this was not just moving files inside the framework, but it was possible thanks to:
We're happy to collect feedback on this specific change here and answer questions/follow-up if there are any.
Beta Was this translation helpful? Give feedback.
All reactions