You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/the-new-architecture/pillars-fabric-components.md
+67-5Lines changed: 67 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -534,6 +534,10 @@ cd android
534
534
535
535
This script first adds the package to the app, in the same way iOS does. Then, after moving to the `android` folder, it invokes a Gradle task to generate the codegen.
536
536
537
+
:::note
538
+
To run the **CodeGen**, you need to enable the **New Architecture** in the Android app. This can be done by opening the `gradle.properties` files and by switching the `newArchEnabled` property from `false` to `true`.
539
+
:::
540
+
537
541
The generated code is stored in the `MyApp/node_modules/rnt-centered-text/android/build/generated/source/codegen` folder and it has this structure:
538
542
539
543
```title="Android generated code"
@@ -740,9 +744,7 @@ This is the last piece of Native Code for Android. It defines the Package object
740
744
741
745
This is the last step to finally see our Fabric Component running on our app.
742
746
743
-
#### iOS
744
-
745
-
To achieve this in iOS, we need to issue a couple of commands and then we can read the Component from JS.
747
+
#### Shared
746
748
747
749
First of all, we need to add the NPM package which contains the Component to the app. This can be done with the following command:
748
750
@@ -751,7 +753,11 @@ cd MyApp
751
753
yarn add ../RTNCenteredText
752
754
```
753
755
754
-
This command will add the `RTNCenteredText` Component to the `node_modules` of your app. Then, we need to install the new dependencies in our iOS project. To do so, we need to run these commands:
756
+
This command will add the `RTNCenteredText` Component to the `node_modules` of your app.
757
+
758
+
#### iOS
759
+
760
+
Then, we need to install the new dependencies in our iOS project. To do so, we need to run these commands:
755
761
756
762
```sh
757
763
cd ios
@@ -766,7 +772,63 @@ You may have to run `bundle install` once before you can use `RCT_NEW_ARCH_ENABL
766
772
767
773
#### Android
768
774
769
-
#### JS
775
+
Android configuration requires slightly more steps in order to be able to use our new Component.
776
+
777
+
First, we need to enable the **New Architecture**, because **Fabric** requires it to run properly. This can be done by:
778
+
779
+
1. Open the `android/gradle.properties` file
780
+
2. Scroll down to the end of the file and switch the `newArchEnabled` property from `false` to `true`.
781
+
782
+
Then, we need to instruct the `Android.mk` file that it needs to build also the new library.
783
+
This can be with these steps:
784
+
785
+
1. Open the `android/app/src/main/jni/Android.mk` file
786
+
1. Add this line to include the library at the beginning of the file:
787
+
788
+
```diff
789
+
include $(REACT_ANDROID_DIR)/Android-prebuilt.mk
790
+
791
+
# If you wish to add a custom TurboModule or Fabric component in your app you
792
+
# will have to include the following autogenerated makefile.
793
+
# include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk
1. In the same file, scroll down until you find a list of `libreact` libraries. There, we have to add the the library that has been generated. To do so, we need to add this line:
800
+
```diff
801
+
libreact_codegen_rncore \
802
+
+libreact_codegen_RTNCenteredText \
803
+
libreact_debug \
804
+
```
805
+
806
+
:::note
807
+
The name of the library will be `libreact_codegen_<libraryname>` where `<libraryname>` is the value that has been set in the config.
808
+
Also, this step won't be necessary anymore as soon as we release a version of React Native which supports autolinking for Android.
809
+
:::
810
+
811
+
Finally, we need to configure the Fabric component registry to load the Fabric Component at runtime. This can be done by:
812
+
813
+
1. Open the `MyApp/android/app/src/main/jni/MainComponentsRegistry.cpp`
0 commit comments