Skip to content

Commit 15a5638

Browse files
gabrieldonadelfacebook-github-bot
authored andcommitted
Implement multiple view manager lookup for the interop layer on Android (#43595)
Summary: When running with the new architurece and using the renderer interop layer on Android, view managers don't work if their names start with `RCT`. This happens because the `RCT` prefix is automatically removed from the component name, and inside the internal `mViewManagers` we store view managers with the `RCT` prefix. Using the `RCT` pattern as a prefix works fine with the old architecture and is actually used on the [Android Native UI Components](https://reactnative.dev/docs/next/native-components-android) tutorial in the docs, making me believe that this same patterns is used across many community libraries. This diff adds a secondary lookup logic for view managers: 1. We look for the XXXViewManager. 2. If not found, we look for RCTXXXViewManager. Quite similar to the iOS implementation introduced in #38093 --- With this change we can also remove most of the entries from FabricNameComponentMapping (I can address this in a follow up PR) https://github.com/facebook/react-native/blob/4e6eba7a2dedaa855af0bff5df3bec73a95f0fc4/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/mountitems/FabricNameComponentMapping.java#L22-L45 ## Changelog: [ANDROID] [ADDED] - Implement multiple view manager lookup for the interop layer Pull Request resolved: #43595 Test Plan: Tested installing a library such as [react-native-fbsdk-next](https://github.com/thebergamo/react-native-fbsdk-next) that names its view managers starting with `RCT` <table> <tr> <th>Before</th> <th>After</th> </tr> <tr> <td> <img width="519" alt="image" src="https://github.com/facebook/react-native/assets/11707729/123de1d6-f018-424b-b6ce-38221af9d83e"> </td> <td><img width="519" alt="image" src="https://github.com/facebook/react-native/assets/11707729/0f35b369-e2e4-4bbf-b880-6471fbc05d38"> </td> </tr> </table> Reviewed By: cortinico Differential Revision: D55208396 Pulled By: arushikesarwani94 fbshipit-source-id: a1fb1f4cee8483cf91ebededd1d7c4ba7021f9d9
1 parent 24a3dad commit 15a5638

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ViewManagerRegistry.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,32 @@ public ViewManagerRegistry(Map<String, ViewManager> viewManagerMap) {
5353
* @return the {@link ViewManager} registered to the className received as a parameter
5454
*/
5555
public synchronized ViewManager get(String className) {
56+
// 1. Try to get the manager without the prefix.
5657
ViewManager viewManager = mViewManagers.get(className);
5758
if (viewManager != null) {
5859
return viewManager;
5960
}
61+
62+
// 2. Try to get the manager with the RCT prefix.
63+
String rctViewManagerName = "RCT" + className;
64+
viewManager = mViewManagers.get(rctViewManagerName);
65+
if (viewManager != null) {
66+
return viewManager;
67+
}
6068
if (mViewManagerResolver != null) {
69+
// 1. Try to get the manager without the prefix.
6170
viewManager = getViewManagerFromResolver(className);
6271
if (viewManager != null) return viewManager;
72+
73+
// 2. Try to get the manager with the RCT prefix.
74+
viewManager = getViewManagerFromResolver(rctViewManagerName);
75+
if (viewManager != null) return viewManager;
76+
6377
throw new IllegalViewOperationException(
64-
"ViewManagerResolver returned null for "
78+
"ViewManagerResolver returned null for either "
6579
+ className
80+
+ " or "
81+
+ rctViewManagerName
6682
+ ", existing names are: "
6783
+ mViewManagerResolver.getViewManagerNames());
6884
}

0 commit comments

Comments
 (0)