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

[FEAT][TNA] Fabric Component - Add Native Code (iOS) #3148

Merged

Conversation

cipolleschi
Copy link
Contributor

This PR adds the Native code for a Fabric Component.

It explains how to use the CodeGen manually, to check what RN will generate, and it proceed by creating the native code.

This PR only contains the iOS part. The Android part will come in a different PR.

@netlify
Copy link

netlify bot commented Jun 6, 2022

Deploy Preview for react-native failed.

Name Link
🔨 Latest commit e8af588
🔍 Latest deploy log https://app.netlify.com/sites/react-native/deploys/629e079785a2280008c90063

@cipolleschi cipolleschi force-pushed the feat/tna-fabric-comp-native-code-ios branch 2 times, most recently from 7ee938b to e8af588 Compare June 6, 2022 13:56
@cipolleschi cipolleschi changed the base branch from main to feat/tna-fabric-comp-config June 6, 2022 14:49
@cipolleschi cipolleschi changed the title [Feat][TNA] Fabric Component iOS Native Code [FEAT][TNA] Fabric Component - Add Native Code (iOS) Jun 7, 2022
Copy link
Contributor

@cortinico cortinico left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@cipolleschi cipolleschi force-pushed the feat/tna-fabric-comp-native-code-ios branch from e8af588 to c2de0d4 Compare June 13, 2022 13:50
docs/the-new-architecture/pillars-fabric-components.md Outdated Show resolved Hide resolved
docs/the-new-architecture/pillars-fabric-components.md Outdated Show resolved Hide resolved
docs/the-new-architecture/pillars-fabric-components.md Outdated Show resolved Hide resolved
docs/the-new-architecture/pillars-fabric-components.md Outdated Show resolved Hide resolved
cd ..
node MyApp/node_modules/react-native/scripts/generate-artifacts.js \
--path MyApp/ \
--outputPath RTNCenteredTextFlow/generated/
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure I understand why we add the component module to the app, but then have codegen output the generated code to the component module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To run the CodeGen, we need a React Native app (which can access the React Native code). A module alone does not have that dependency, therefore we need to add the module to the app.

Once that is done, we can invoke the CodeGen manually to see what it will outputs, so that we can use the right filenames and types.
By invoking the codegen manually, we need to define an output folder and I thought it was easier to use the module folder as root.

As specified in the caution block above, the code generated manually should not be committed to the code versioning system and will be discarded. React Native relies on the code generated automatically when building the app.

Copy link
Contributor

Choose a reason for hiding this comment

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

Cool, that makes sense -- it might be good to briefly explain the intention here, the reader may wonder (as I did) if this process is necessary in the normal course of development

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 added a couple of paragraphs before the iOS section to describe that. Let me know what do you think!

docs/the-new-architecture/pillars-fabric-components.md Outdated Show resolved Hide resolved
docs/the-new-architecture/pillars-fabric-components.md Outdated Show resolved Hide resolved
docs/the-new-architecture/pillars-fabric-components.md Outdated Show resolved Hide resolved
##### Write the Native iOS Code

Now that we can see the iOS code we need, it's time to write the Native code for our Fabric Component.
We need to create three files:
Copy link
Contributor

Choose a reason for hiding this comment

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

We should say specifically where: in the top level of the ios directory?

I'm also wondering something that I think would be good to explicitly state: is the reader intended to be using XCode to work on this in the RTNCenteredText/ios directory and be able to use the imports? I'm not sure what the intended way is to do that, particularly when the generated code is in another directory that's a sibling with ios/android

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should say specifically where: in the top level of the ios directory?

Good point. It will be in the centered-text/ios folder.

I'm also wondering something that I think would be good to explicitly state: is the reader intended to be using XCode to work on this in the RTNCenteredText/ios directory and be able to use the imports? I'm not sure what the intended way is to do that, particularly when the generated code is in another directory that's a sibling with ios/android

For this sample, I didn't used Xcode at all. The problem with Xcode is that we have to tell them to create an .xcodeproject file (for a static library) otherwise Xcode won't be able to work with those properly. In any case, they won't be able to build the module from Xcode because they miss the React Native dependencies.

So, at the end of the day, I don't think we should suggest them to use Xcode... It could create more confusion with the errors it will display.

Copy link
Contributor

Choose a reason for hiding this comment

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

What's your flow for writing this code? Do you use any other tooling to help make sure it's correct?

I think it's important for a guide like this to demonstrate what the regular development flow should be like, or people are likely to feel stuck after they aren't just copying files

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, you are completely right, but that's a pain point, unfortunately. Currently, there is no easy way to do that.

The tool I use is VisualStudio code and then I have a test app that I use as test bed. Basically, I yarn add the module, install the dependencies and I try to build it. If there are errors, I fix them in the Development Pods folder until they are ok and then I have to copy-and-paste the files back in the RTNCenteredText folder.

That's far from being ideal and I think it is a little bit too convoluted to explain it to the users... what do you think?

@cipolleschi cipolleschi force-pushed the feat/tna-fabric-comp-native-code-ios branch from c2de0d4 to b54eeb4 Compare June 17, 2022 02:36
@cipolleschi cipolleschi force-pushed the feat/tna-fabric-comp-config branch 3 times, most recently from 6e41e16 to d48e335 Compare June 17, 2022 21:12
@cipolleschi cipolleschi force-pushed the feat/tna-fabric-comp-native-code-ios branch from b54eeb4 to 6403af3 Compare June 17, 2022 21:16
@cipolleschi cipolleschi force-pushed the feat/tna-fabric-comp-native-code-ios branch from 6403af3 to b2e7bbf Compare June 17, 2022 21:37
* feat: add fabric component to app - ios

* [FEAT][TNA] Fabric Component - Add Native Code (Android) (#3152)

* feat: add native code for android

* [FEAT][TNA] Fabric Component - Add Component to App (Android) (#3153)

* feat: Add fabric component to app - Android

* feat: improve structure and consistency (#3154)
@cipolleschi cipolleschi merged commit 955956b into feat/tna-fabric-comp-config Jun 27, 2022
cipolleschi pushed a commit that referenced this pull request Jun 27, 2022
* feat: add section on configuration

* [FEAT][TNA] Fabric Component - Add Native Code (iOS) (#3148)

* feat: Add native code for iOS

* [FEAT][TNA] Fabric Component - Add Component to App (iOS) (#3149)

* feat: add fabric component to app - ios

* [FEAT][TNA] Fabric Component - Add Native Code (Android) (#3152)

* feat: add native code for android

* [FEAT][TNA] Fabric Component - Add Component to App (Android) (#3153)

* feat: Add fabric component to app - Android

* feat: improve structure and consistency (#3154)
cipolleschi pushed a commit that referenced this pull request Jun 27, 2022
…Specs (#3133)

* [Feat] Add JavaScript for Fabric Components

* [FEAT][TNA] Fabric Component - Add Configuration Files (#3136)

* feat: add section on configuration

* [FEAT][TNA] Fabric Component - Add Native Code (iOS) (#3148)

* feat: Add native code for iOS

* [FEAT][TNA] Fabric Component - Add Component to App (iOS) (#3149)

* feat: add fabric component to app - ios

* [FEAT][TNA] Fabric Component - Add Native Code (Android) (#3152)

* feat: add native code for android

* [FEAT][TNA] Fabric Component - Add Component to App (Android) (#3153)

* feat: Add fabric component to app - Android

* feat: improve structure and consistency (#3154)
@cipolleschi cipolleschi deleted the feat/tna-fabric-comp-native-code-ios branch November 25, 2022 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants