Skip to content

Commit 4ad7cf1

Browse files
author
Riccardo Cipolleschi
committed
feat: add fabric component to app - ios
1 parent b2e7bbf commit 4ad7cf1

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

docs/the-new-architecture/pillars-fabric-components.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,11 @@ To run Codegen for the iOS platform, we need to open a terminal and run the foll
313313

314314
```sh
315315
cd MyApp
316-
yarn add ../RTNCenteredTextFlow
316+
yarn add ../RTNCenteredText
317317
cd ..
318318
node MyApp/node_modules/react-native/scripts/generate-artifacts.js \
319319
--path MyApp/ \
320-
--outputPath RTNCenteredTextFlow/generated/
320+
--outputPath RTNCenteredText/generated/
321321
```
322322

323323
This script first adds the `RTNCenteredText` module to the app with `yarn add`. Then, it invokes Codegen via the `generate-artifacts.js` script.
@@ -520,3 +520,59 @@ Differently from Native Components, Fabric requires us to manually implement the
520520
#### Android
521521
522522
### Adding the Fabric Component To Your App
523+
524+
This is the last step to finally see our Fabric Component running on our app.
525+
526+
#### iOS
527+
528+
To achieve this in iOS, we need to issue a couple of commands and then we can read the Component from JS.
529+
530+
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:
531+
532+
```sh
533+
cd MyApp
534+
yarn add ../RTNCenteredText
535+
```
536+
537+
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:
538+
539+
```sh
540+
cd ios
541+
RCT_NEW_ARCH_ENABLED=1 bundle exec pod install
542+
```
543+
544+
This command will look for all the dependencies of the project and it will install the iOS ones. The `RCT_NEW_ARCH_ENABLED=1` instruct **Cocoapods** that it has to run some additional operations to run the **CodeGen** that is required by **Fabric**.
545+
546+
:::note
547+
You may have to run `bundle install` once before you can use `RCT_NEW_ARCH_ENABLED=1 bundle exec pod install`. You won't need to run `bundle install` anymore, unless you need to change the ruby dependencies.
548+
:::
549+
550+
#### Android
551+
552+
#### JS
553+
Finally, we can read the Component in our JS application.
554+
To do so, we have to:
555+
556+
1. Import the Component in the js file that uses it. So, if we want to use it in the `App.js`, we need to add this line:
557+
558+
```js title="App.js"
559+
import RTNCenteredText from 'rnt-centered-text/js/RNTCenteredTextNativeComponent';
560+
```
561+
562+
2. Then, we need to use it in another React Native component. The syntax is the same as for any other component:
563+
```js title="App.js"
564+
// ... other code
565+
const App: () => Node = () => {
566+
// ... other App code ...
567+
return (
568+
// ...other RN elements...
569+
<RTNCenteredText
570+
text="Hello World!"
571+
style={{ width: '100%', height: 30 }}
572+
/>
573+
// ...other RN Elements
574+
);
575+
};
576+
```
577+
578+
Now, we can run the React Native app and see our Component on the screen.

docs/the-new-architecture/pillars.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ Finally, we dive a little deeper into the [CodeGen](pillars-codegen) process tha
2525
To integrate a TurboModule or a Fabric Component in an app, the app has to run with the New Architecture enabled.
2626

2727
To create a new app adopting the New Architecture, refer to the [Using the App Template](use-app-template) section.
28-
To migrate an existing app to the New Architecture, refer to the [Migration](/docsq/new-architecture-intro) guide.
28+
To migrate an existing app to the New Architecture, refer to the [Migration](/docs/new-architecture-intro) guide.
2929
:::

0 commit comments

Comments
 (0)