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
+218-1Lines changed: 218 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -307,7 +307,7 @@ The code generated by the **CodeGen** in this step should not be committed to th
307
307
308
308
#### iOS
309
309
310
-
##### Generate the code
310
+
##### Generate the code - iOS
311
311
312
312
To run Codegen for the iOS platform, we need to open a terminal and run the following command:
313
313
@@ -519,6 +519,223 @@ Differently from Native Components, Fabric requires us to manually implement the
519
519
520
520
#### Android
521
521
522
+
Android follows some similar steps to iOS. We have to generate the code for Android, and then we have to write some native code to make it works.
523
+
524
+
##### Generate the Code - Android
525
+
526
+
To generate the code for Android, we need to manually invoke the CodeGen. This is done similarly to what we did for iOS: first, we need to add the package to the app and then we need to invoke a script.
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
+
537
+
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
+
539
+
```title="Android generated code"
540
+
codegen
541
+
├── java
542
+
│ └── com
543
+
│ └── facebook
544
+
│ └── react
545
+
│ └── viewmanagers
546
+
│ ├── RTNCenteredTextManagerDelegate.java
547
+
│ └── RTNCenteredTextManagerInterface.java
548
+
├── jni
549
+
│ ├── Android.mk
550
+
│ ├── CMakeLists.txt
551
+
│ ├── RTNCenteredText-generated.cpp
552
+
│ ├── RTNCenteredText.h
553
+
│ └── react
554
+
│ └── renderer
555
+
│ └── components
556
+
│ └── RTNCenteredText
557
+
│ ├── ComponentDescriptors.h
558
+
│ ├── EventEmitters.cpp
559
+
│ ├── EventEmitters.h
560
+
│ ├── Props.cpp
561
+
│ ├── Props.h
562
+
│ ├── ShadowNodes.cpp
563
+
│ └── ShadowNodes.h
564
+
└── schema.json
565
+
```
566
+
567
+
You can see that the content of the `codegen/jni/react/renderer/components/RTNCenteredTextSpecs` looks similar to the files created by the iOS counterpart. Other interesting pieces are the `Android.mk` and `CMakeList.txt` files, which we need to configure the Fabric Component in the app, and the `RTNCenteredTextManagerDelegate.java` and `RTNCenteredTextManagerInterface.java` that we need to use in our manager.
568
+
569
+
See the [CodeGen](./pillars-codegen) section for further details on the generated files.
570
+
571
+
##### Write the Native Android Code
572
+
573
+
The native code for the Android side of a Fabric Components requires four pieces:
574
+
575
+
1. An `AndroidManifest.xml` file.
576
+
2. A `RTNCenteredText.java` that represents the actual view.
577
+
3. A `RTNCenteredTextManager.java` to instantiate the view.
578
+
4. A `RTNCenteredTextPackage.java` that React Native uses to configure the library.
579
+
580
+
The final structure within the Android library should be like this.
This class represents the actual view Android is going to represent on screen. It inherit from `TextView` and we configure the basic aspects of it using a private `configureComponent()` function
The `RTNCenteredTextManager` is a class used by React Native to instantiate the native component. It is the class that leverage the **CodeGen** in order to implement all the proper interfaces (See the `RTNCenteredTextManagerInterface` interface in the `implements` clause) and it uses the `RTNCenteredTextManagerDelegate`.
703
+
704
+
It is also responsible to export all the constructs required by ReactNative: the class itself is annotated with `@ReactModule` and the `setText` method is annothated with `@ReactProp`.
0 commit comments