Skip to content

📚 [Guide] Create a backward compatible Turbomodule #3023

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

Conversation

cipolleschi
Copy link
Contributor

This PR contains a first draft of a Guide to create a TurboModule which is backward compatible with the new architecture.

This guide is intended to be used as a reference to understand better how the backward compatibility can be achieved and what are the differences between a Native Module and a Turbomodule, from a developer perspective.

@netlify
Copy link

netlify bot commented Mar 21, 2022

✅ Deploy Preview for react-native ready!

🔨 Explore the source changes: 95db79d

🔍 Inspect the deploy log: https://app.netlify.com/sites/react-native/deploys/6239a2c0899af50008deb46e

😎 Browse the preview: https://deploy-preview-3023--react-native.netlify.app

@cipolleschi cipolleschi force-pushed the docs/create_backward_compatible_turbomodule branch 3 times, most recently from 78e1d3a to 0698e45 Compare March 21, 2022 11:16
Copy link
Collaborator

@Simek Simek left a comment

Choose a reason for hiding this comment

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

Hello @cipolleschi, thank you for the great work on fixing and extending the documentation lately! 👍

It looks like the page is not linked in any sidebar, which makes the page only accessible via URL. You probably want to add this page somewhere in there:

Other that that, I have left two, small suggestions according to the new page content.

@cipolleschi
Copy link
Contributor Author

Hi @Simek! Thanks for the suggestions. I'll go through applying them now.

About the sidebar thing, I left the article out on purpose for two reasons:

  1. It is not complete (missing the android parts) so I didn't want it to be found by final users.
  2. I'd like to discuss the structure of the New Architecture section because I think it could be organidsed in a more linear way.

What do you think?

@cipolleschi cipolleschi force-pushed the docs/create_backward_compatible_turbomodule branch from 0698e45 to 3b07322 Compare March 21, 2022 12:05
@cipolleschi
Copy link
Contributor Author

I should have fixed all the comments! :D


To create a turbomodule with the React Native CLI, run the following command:

```sh title=""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
```sh title=""
```sh

Just a small fix suggestion.

Copy link
Collaborator

@Simek Simek left a comment

Choose a reason for hiding this comment

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

Thank you for the quick updates! For the formatting and website perspective this LGTM.

Let's have a @cortinico look at the technical side of this. 🙂

There are few more small formatting (capitalization of Metro, JavaScript, TypeScript etc.) and punctuation issues (mostly missing dots at the end of sentences), but since this still a draft we can correct this in the future.

@Simek Simek requested a review from cortinico March 21, 2022 12:35
@cipolleschi cipolleschi force-pushed the docs/create_backward_compatible_turbomodule branch from 3b07322 to e9c53d6 Compare March 21, 2022 14:07
@cipolleschi
Copy link
Contributor Author

Great, thanks!
I should have fixed also the capitalizations and the punctuation issues that I could find.

],
"keywords": ["react-native", "ios", "android"],
"repository": "https://github.com/<your_github_handle>/example-library",
"author": "<Your Name> <your_email@your_provide.com> (https://github.com/<your_github_handle>)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"author": "<Your Name> <your_email@your_provide.com> (https://github.com/<your_github_handle>)",
"author": "<Your Name> <your_email@your_provider.com> (https://github.com/<your_github_handle>)",


This section and the following are a practical guides to create a module that is backward compatible. We are not diving deep into what can be done with Native Modules. For more informations on that topic, have a look [here](native-modules-intro).

If you are interested in creating a Turbomodule, you can skip this part and directly go [here](#create-the-turbomodule). Consider that most of the code of a Native Module is needed for a Turbomodule.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that the "Consider that most of the code of a Native Module is needed for a Turbomodule" is confusing for the reader.

If a reader is looking into creating a TurboModule without dealing with backward compat, probably is not even reading this page right?

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 agree. I moved the sentence to the previous paragraph, adding some more context.

@cortinico
Copy link
Contributor

Great stuff 👍

A couple of things that are worth mentioning:

  1. We should potentially mention that the New Architecture approach would work for apps that have the TM system enabled.
  2. For that reason, we could link users to this page: https://reactnative.dev/docs/next/new-architecture-app-modules-ios
  3. We should clarify what happens if you import the New Arch file but you have the TM system disabled (i.e. you're on the old arch).

@cipolleschi cipolleschi force-pushed the docs/create_backward_compatible_turbomodule branch from e9c53d6 to df09aba Compare March 22, 2022 10:12
@cipolleschi
Copy link
Contributor Author

Thanks!

For your points 1 and 2, I added a sentence at line 426.

It's not clear to me what do you mean for your point 3, though. The whole point of the article is that we can install the module in both the architecture. Some problem arises if:

  1. A user in the old architecture runs RCT_NEW_ARCH_ENABLED=1 pod install
  2. A user in the new architecture runs pod install

But I think that these are clearly explained throughout the guide and also with the summary. I think that the user can expect some error if it forget about these steps. What do you think?

@cipolleschi cipolleschi force-pushed the docs/create_backward_compatible_turbomodule branch from df09aba to 95db79d Compare March 22, 2022 10:19
@cortinico
Copy link
Contributor

It's not clear to me what do you mean for your point 3, though. The whole point of the article is that we can install the module in both the architecture. Some problem arises if:

Discussed offline but following up here for the sake of transparency.

I think we will adjust the guide a bit to adopt the approach followed by some of the Software Mansion library:

https://github.com/software-mansion/react-native-gesture-handler/blob/a144c0ebaba3b544d3455c7eced084d66dff5d7e/src/components/GestureHandlerButton.tsx#L6-L10

Ideally we would like to don't ask the user to update the import but just have an abstraction that will expose the correct object given the underlying infrastructure.

@cortinico
Copy link
Contributor

Closing as this is stale and merged in #3037

@cortinico cortinico closed this Jul 20, 2022
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.

4 participants