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

Add unstable_reactLegacyComponent to cli-platform-android #1849

Conversation

cortinico
Copy link
Member

@cortinico cortinico commented Feb 27, 2023

Summary:

This adds the unstable_reactLegacyComponent config key inside the android.project. object, so that users can use the react-native.config.js file to register a list of component they want to use on the New Architecture that are not yet migrated to support Fabric.

I've added the unstable_ prefix as this is most likely going to change, but we'd like to have it out so soon-ish we can ask users to try it and report back if there are blockers.

I've added docs for this field:

An array with a list of Legacy Component Name that you want to be registered with the Fabric Interop Layer. This will allow you to use on the New Architecture, libreries that are legacy and haven't been migrated yet.
The list should contain the name of the components, as they're registered in the ViewManagers (i.e. just "Button").

Test Plan:

I've tested this on the latest nightly and I was able to build correctly.

cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Mar 1, 2023
…in the interop layer

Summary:
This change depends on [this PR](react-native-community/cli#1849) of the CLI that introduces the `unstable_reactLegacyComponent` field in the `react-native.config.js` file.

This change introduce a JS script that reads that fields and generated a method in an object to return a list of components to be registered. The RCTAppDelegate has been updated to read those components and to automatically register them into the interop layer.

Notice that a user can just update the `react-native.config.js` and rebuild the app to integrate these changes, there is no need to reinstall the pods.

The idea behind this logic is to let the user know which components they are using with the interop layer, rather than rely on some black magic that could leave them blind to the need of actually migrate their apps.

## Changelog:
[iOS][Changed] - Implement mechanism to register components in the iOS Fabric interop layer

Differential Revision: D43665973

fbshipit-source-id: 0de4664ea6513b7664c30e8fbf6923f92df46766
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Mar 1, 2023
…in the interop layer (facebook#36335)

Summary:
Pull Request resolved: facebook#36335

This change depends on [this PR](react-native-community/cli#1849) of the CLI that introduces the `unstable_reactLegacyComponent` field in the `react-native.config.js` file.

This change introduce a JS script that reads that fields and generated a method in an object to return a list of components to be registered. The RCTAppDelegate has been updated to read those components and to automatically register them into the interop layer.

Notice that a user can just update the `react-native.config.js` and rebuild the app to integrate these changes, there is no need to reinstall the pods.

The idea behind this logic is to let the user know which components they are using with the interop layer, rather than rely on some black magic that could leave them blind to the need of actually migrate their apps.

## Changelog:
[iOS][Changed] - Implement mechanism to register components in the iOS Fabric interop layer

Reviewed By: dmytrorykun

Differential Revision: D43665973

fbshipit-source-id: 9f5687a383c1430c2793d1af8523d811e44b8a66
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Mar 3, 2023
… in the interop layer (facebook#36335)

Summary:
Pull Request resolved: facebook#36335

This change depends on [this PR](react-native-community/cli#1849) of the CLI that introduces the `unstable_reactLegacyComponent` field in the `react-native.config.js` file.

This change introduce a JS script that reads that fields and generated a method in an object to return a list of components to be registered. The `RCTAppDelegate` has been updated to read those components and to automatically register them into the interop layer.

Notice that a user can just update the `react-native.config.js` and rebuild the app to integrate these changes, there is no need to reinstall the pods.

The idea behind this logic is to let the user know which components they are using with the interop layer, rather than rely on some black magic that could leave them blind to the need of actually migrate their apps.

## Changelog:
[iOS][Changed] - Implement mechanism to register legacy components in the iOS Fabric interop layer

Reviewed By: cortinico, dmytrorykun

Differential Revision: D43665973

fbshipit-source-id: d42c6f58bd1bb69eb938f0473c3004a91392eacc
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Mar 3, 2023
… in the interop layer (facebook#36335)

Summary:
Pull Request resolved: facebook#36335

This change depends on [this PR](react-native-community/cli#1849) of the CLI that introduces the `unstable_reactLegacyComponent` field in the `react-native.config.js` file.

This change introduce a JS script that reads that fields and generated a method in an object to return a list of components to be registered. The `RCTAppDelegate` has been updated to read those components and to automatically register them into the interop layer.

Notice that a user can just update the `react-native.config.js` and rebuild the app to integrate these changes, there is no need to reinstall the pods.

The idea behind this logic is to let the user know which components they are using with the interop layer, rather than rely on some black magic that could leave them blind to the need of actually migrate their apps.

## Changelog:
[iOS][Changed] - Implement mechanism to register legacy components in the iOS Fabric interop layer

Reviewed By: cortinico, dmytrorykun

Differential Revision: D43665973

fbshipit-source-id: 760a016bd717fd098273d755fab1bbdb984bd66e
cipolleschi added a commit to cipolleschi/react-native that referenced this pull request Mar 3, 2023
… in the interop layer (facebook#36335)

Summary:
Pull Request resolved: facebook#36335

This change depends on [this PR](react-native-community/cli#1849) of the CLI that introduces the `unstable_reactLegacyComponent` field in the `react-native.config.js` file.

This change introduce a JS script that reads that fields and generated a method in an object to return a list of components to be registered. The `RCTAppDelegate` has been updated to read those components and to automatically register them into the interop layer.

Notice that a user can just update the `react-native.config.js` and rebuild the app to integrate these changes, there is no need to reinstall the pods.

The idea behind this logic is to let the user know which components they are using with the interop layer, rather than rely on some black magic that could leave them blind to the need of actually migrate their apps.

## Changelog:
[iOS][Changed] - Implement mechanism to register legacy components in the iOS Fabric interop layer

Differential Revision: https://internalfb.com/D43665973

fbshipit-source-id: 22ef2ec769afad76624797e07c8e5bed28011449
@cortinico cortinico force-pushed the nc/unstable-reactLegacyComponent branch 2 times, most recently from 52ac6ec to 423d643 Compare March 3, 2023 17:28
@github-actions github-actions bot added the docs Documentation change label Mar 3, 2023
@cortinico cortinico changed the title Draft: Add unstable_reactLegacyComponent to the cli/android Draft: Add unstable_reactLegacyComponent to cli-platform-android Mar 3, 2023
@cortinico cortinico force-pushed the nc/unstable-reactLegacyComponent branch from 423d643 to a7c67df Compare March 3, 2023 17:34
@cortinico cortinico marked this pull request as ready for review March 3, 2023 17:35
@cortinico cortinico changed the title Draft: Add unstable_reactLegacyComponent to cli-platform-android Add unstable_reactLegacyComponent to cli-platform-android Mar 3, 2023
docs/projects.md Outdated Show resolved Hide resolved
@thymikee
Copy link
Member

thymikee commented Mar 3, 2023

Does this work with 3rd party components from node_modules as well?

@cortinico
Copy link
Member Author

Does this work with 3rd party components from node_modules as well?

Yes it will work with 3rd party components as well, as long as the user knows the name of the components.

We could make it more smart so that libraries can expose a list of components names, but we think this is going to be a more "advanced" feature at least for now, so we assume the users know which components they want to register.

On top of this, unregistered component which are not fabric compatible show a Redbox that says "The component 'XYZ' is not Fabric Compatible yet". That's the name that needs to be registered here.

@thymikee
Copy link
Member

thymikee commented Mar 3, 2023

Ok. Once that's in, we could improve the error message to include adjusting the react-native.config.js, at least for non-expo projects

@cortinico
Copy link
Member Author

Ok. Once that's in, we could improve the error message to include adjusting the react-native.config.js, at least for non-expo projects

You mean for the "Unregistered components"? We can totally do so

hence the `unstable_` prefix.

An array with a list of Legacy Component Name that you want to be registered with the Fabric Interop Layer.
This will allow you to use on the New Architecture, libreries that are legacy and haven't been migrated yet.
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
This will allow you to use on the New Architecture, libreries that are legacy and haven't been migrated yet.
This will allow you to use on the New Architecture, libraries that are legacy and haven't been migrated yet.

;)

@adamTrz
Copy link
Collaborator

adamTrz commented Mar 3, 2023

Code looks good 💪
Is there a way to test it locally?

facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Mar 3, 2023
… in the interop layer (#36335)

Summary:
Pull Request resolved: #36335

This change depends on [this PR](react-native-community/cli#1849) of the CLI that introduces the `unstable_reactLegacyComponent` field in the `react-native.config.js` file.

This change introduce a JS script that reads that fields and generated a method in an object to return a list of components to be registered. The `RCTAppDelegate` has been updated to read those components and to automatically register them into the interop layer.

Notice that a user can just update the `react-native.config.js` and rebuild the app to integrate these changes, there is no need to reinstall the pods.

The idea behind this logic is to let the user know which components they are using with the interop layer, rather than rely on some black magic that could leave them blind to the need of actually migrate their apps.

## Changelog:
[iOS][Changed] - Implement mechanism to register legacy components in the iOS Fabric interop layer

Reviewed By: cortinico, dmytrorykun

Differential Revision: D43665973

fbshipit-source-id: b4e8d71fa1bbed7a6130ee4f83a6221394d5306e
@cortinico
Copy link
Member Author

cortinico commented Mar 6, 2023

Code looks good 💪 Is there a way to test it locally?

To test locally:

  1. Create a new RN project locally using the latest nightly (npx react-native@latest init RNNightly --version nightly)
  2. Make sure the project is using the CLI version from this PR
  3. Add a Native Component as described here called RCTImageView https://reactnative.dev/docs/native-components-android
  4. Create a screen using <RCTImageView>
  5. Turn on New Architecture
  6. Verifies that the app builds but the component renders as red on screen
  7. Add the following to the react-native.config.js
module.exports = {
  project: {
    android: {
      unstable_reactLegacyComponent: [
        'RCTImageView'
      ]
    },
  },
};
  1. Verify that you can see the component rendered correctly.

Comment on lines +163 to +166
unstable_reactLegacyComponentNames: t
.array()
.items(t.string())
.default([]),
Copy link
Contributor

@cipolleschi cipolleschi Mar 6, 2023

Choose a reason for hiding this comment

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

note: for iOS, we just need these same lines in the iOS project above (Line 149).

The CLI doesn't have to do anything else for iOS, we just need the same key structure.

I can do it in a separate PR, if you prefer.

@adamTrz
Copy link
Collaborator

adamTrz commented Mar 6, 2023

To test locally:
...
7. Add the following to the react-native.config.js

module.exports = {
  platforms: {
    android: {
      unstable_reactLegacyComponent: [
        'RCTImageView'
      ]
    },
  },
};
  1. Verify that you can see the component rendered correctly.

Thanks @cortinico :)

Got an error when using platforms:

error Failed to load configuration of your project.
Config Validation Error: "platforms.android.unstable_reactLegacyComponentNames" is not allowed
    at readConfigFromDisk [...]

But when I've switched to project from platform it works and Image is rendered 🎉

@adamTrz adamTrz merged commit 90edee9 into react-native-community:main Mar 6, 2023
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
… in the interop layer (facebook#36335)

Summary:
Pull Request resolved: facebook#36335

This change depends on [this PR](react-native-community/cli#1849) of the CLI that introduces the `unstable_reactLegacyComponent` field in the `react-native.config.js` file.

This change introduce a JS script that reads that fields and generated a method in an object to return a list of components to be registered. The `RCTAppDelegate` has been updated to read those components and to automatically register them into the interop layer.

Notice that a user can just update the `react-native.config.js` and rebuild the app to integrate these changes, there is no need to reinstall the pods.

The idea behind this logic is to let the user know which components they are using with the interop layer, rather than rely on some black magic that could leave them blind to the need of actually migrate their apps.

## Changelog:
[iOS][Changed] - Implement mechanism to register legacy components in the iOS Fabric interop layer

Reviewed By: cortinico, dmytrorykun

Differential Revision: D43665973

fbshipit-source-id: b4e8d71fa1bbed7a6130ee4f83a6221394d5306e
@affansk
Copy link

affansk commented Jun 13, 2023

@cortinico i am getting this error, i tried both platform and project.

Config Validation Error: "platform.ios.unstable_reactLegacyComponent" is not allowed
Config Validation Error: "project.ios.unstable_reactLegacyComponent" is not allowed

platforms: {
ios: {
unstable_reactLegacyComponentNames: ['BVLinearGradient'],
},
android: {},
},
i am testing on version : "0.72.0-rc.5",

@cortinico
Copy link
Member Author

platforms: {

As suggested in this thread, you should use project and not platform. I've updated my snippet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants