New Renderer Interop Layer #135
Replies: 12 comments 42 replies
-
This is pretty awesome! As for the roadmap, do you have any plans for when to remove the compatibility layer again? |
Beta Was this translation helpful? Give feedback.
-
This will help greatly when only a few native dependencies don't support the new arch yet! |
Beta Was this translation helpful? Give feedback.
-
I think we can use strong |
Beta Was this translation helpful? Give feedback.
-
The interop layer is really great. I did have a question about events interop, as implemented here: facebook/react-native#37059 As described in that PR, in Fabric, all event names need to be prefixed with the word "top". In that PR, it looks like the normalization logic to prepend "top" only applies to bubbling events, and not direct events. Is this intentional? Pre-Fabric, I don't believe the "top" prefix was required for direct events. To provide a specific example, the interop feature wasn't working for the stable version of
I'm wondering why the "top" normalization was performed only for bubbling events? Given that this naming convention was not required for direct events prior to Fabric, doesn't that mean the interop layer won't work out of the box for libraries using direct events? Thanks! (in case it helps illustrate my experience, here are my changes in a fork of |
Beta Was this translation helpful? Give feedback.
-
@cipolleschi, I think the interop approach is a great idea. One challenge I've run into with the RN Interop layer is determining the suitable component name for 'unstable_reactLegacyComponentNames' as the 'package.json' name is not currently accepted. While visual elements like the React Native Picker offer clear identification (pink bounding box), how can we identify keys for non-visual libraries since it doesn't seem to be standardized across iOS and Android? For instance, how could developers find the necessary key for 'unstable_reactLegacyComponentNames' when dealing with libraries like React Native Cookies or React Native Netinfo since neither has a visual element that could help identify its key? |
Beta Was this translation helpful? Give feedback.
-
The interop layer is a great ideal. But i think if we can add |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Really big thank you. This Interop Layer works for me. After adding the components' names in
|
Beta Was this translation helpful? Give feedback.
-
Hello, I've been trying out a lib on new arch before doing anything (private repo, sadly can't share), expecting to see the pinkish box, but everything renders as it should. I see fabric is enabled in console log. In what cases the pink box appears? Just trying to understand that. The lib was created using react-native-builder-bob (0.30.0), using the old arch options during init, I did not follow any new arch instructions during development. Secondly, can I get a clarification on this:
Link that got me here was about migrating a library, not application. Is |
Beta Was this translation helpful? Give feedback.
-
I added the configuration file and now it works only the first time, that is, when I open the map (react-native-maps) for the first time after closing the app it works. If I continue the navigation and return, they no longer appear. I have to completely close the app and reopen it. The same happens if there is an hot reload. :( |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Important
Exciting changes for the Interop Layers from 0.74. Read more here
TL;DR: With React Native 0.72, we are releasing an interop layer for both Android and iOS to use non-migrated libraries on New Architecture apps. This post describes what it is, how to use it, and it serves as a way to collect feedback.
Hi all,
We’re excited to share that React Native 0.72 will ship with an interop layer to use legacy components in the New Architecture.
What it is
The interop layer is a feature that lets you reuse legacy Native Components in New Architecture apps, without the need for them to be migrated. It’s a platform layer that allows you to register legacy components into the New Renderer (aka Fabric) and it maps legacy function invocation (for example, the setters for specific properties) to the equivalent in the New Renderer (the updateProps function).
You need to explicitly opt-in on a component basis to use this layer. Which means that you’ll have to list your components in a specific file in order to load them in the New Architecture.
Please note that this layer is experimental. There could be several edge cases not yet covered.
Please, report them as a comment in this discussion.
How to use the interop layer
The interop layer is shipped with React Native 0.72. If no components are registered, it does nothing.
The only step required to use it is to register a component in the layer.
To register a component, you have to edit the
react-native.config.js
file in your application project to list the legacy components required by the app, in the Android and iOS sections:Technical Background
To embrace the New Architecture completely, an app has the strong requirement to have all the Native Components migrated to the new Native Components system and to the New Render (Fabric). The migration of Native Components to the New Renderer is complex, requires a lot of time and usually can not be automated as the paradigm is completely different. The result is that it’s very hard for apps to start using the New Architecture.
Under these hypothesis, we decided to share an interop layer between the legacy and the New Architecture that we’ve been using internally for some of our products to facilitate the migration.
The interop layer is effectively a wrapper that allows your legacy component to work with the New Renderer.
Under the hoods, whenever a prop is updated or a command sent, it is forwarded to the
UIManager
of the New Renderer. TheUIManager
sends the message to the wrapper which takes care to convert it to a format that the legacy architecture can understand and it lets the legacy component handle it. It then back-propagates the message to JS, updating the UI.Supported Features
Currently, the supported features of the interop layer are:
UIManager.dispatchViewManager
)setNativeProps
andmeasure*
functions)Limitations
We know that there are some use cases that we are not covering yet. We will analyze them case by case and we will decide whether to implement them in the interop layer or not, based on how common the use case is and how hard will be to implement it w.r.t. properly migrate the component to the New Architecture.
Please, report them as a comment in this discussion.
So far, we know that the following features are not implemented or for which we may not guarantee a perfect execution:
These features require a proper migration to the New Renderer to work correctly, and we cannot fully support them in the interop layer due to architectural limitations.
The Interop Layer in Action
Before
Before the interop layer, when you were trying to use a Legacy Component on the new Architecture, you would have seen something like this:
Those pinkish views are indicating that the component is not compatible with the New Renderer and the library maintainer need to migrate it to be used in the New Architecture.
Adopting the interop layer
To adopt the nRIL, you just need to:
react-native.config.js
of your app.RNCAndroiddialogPicker
for Android andRNCPicker
for iOS):yarn android
(ornpm run android
) oryarn ios
(ornpm run ios
).After
After relaunching the app, you should see the actual component in place of the pinkish view of before:
What’s Next
As highlighted in the Limitations section, we are aware that the interop layer is not complete. We are not aiming to make it 100% complete as, to leverage all the new features we are going to develop, we need that all the native components in the ecosystem are properly migrated to the New Architecture, avoiding invocation to functions that do not work well with the New Architecture.
However, we want to learn about the use cases when the interop layer fails short: we will evaluate them on a case-by-case basis and we can decided to support some of those if the use case is widely spread or very easy to implement.
So, we need you!
If you can, take some time to test this layer and report here use cases when it doesn’t work. For each of them, please add a short description and a way to reproduce it, so we can double-check the example and understand how to move forward.
Thank you so much!
Beta Was this translation helpful? Give feedback.
All reactions