Skip to content

Commit 4ddfeb6

Browse files
cipolleschiRiccardo Cipolleschi
authored andcommitted
Warn users when a component is registered in Rendere and in the interop (#38089)
Summary: Pull Request resolved: #38089 This change add a warning if a component is registered in both the New Renderer and in the Interop layer. This can help users migrating their components once the library has been migrated. [iOS][Added] - Add warning to help users migrate away from the interop layer. Reviewed By: cortinico Differential Revision: D47053556 fbshipit-source-id: cc2ba09db16aaa370947a77173b6ea6a0acfa519
1 parent f537257 commit 4ddfeb6

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

packages/react-native/React/Fabric/Mounting/RCTComponentViewFactory.mm

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#import <React/RCTAssert.h>
1111
#import <React/RCTConversions.h>
12+
#import <React/RCTLog.h>
1213

1314
#import <butter/map.h>
1415
#import <butter/set.h>
@@ -105,16 +106,21 @@ - (BOOL)registerComponentIfPossible:(std::string const &)name
105106
return YES;
106107
}
107108

109+
// Paper name: we prepare this variables to warn the user
110+
// when the component is registered in both Fabric and in the
111+
// interop layer, so they can remove that
112+
NSString *componentNameString = RCTNSStringFromString(name);
113+
BOOL isRegisteredInInteropLayer = [RCTLegacyViewManagerInteropComponentView isSupported:componentNameString];
114+
108115
// Fallback 1: Call provider function for component view class.
109116
Class<RCTComponentViewProtocol> klass = RCTComponentViewClassWithName(name.c_str());
110117
if (klass) {
111-
[self registerComponentViewClass:klass];
118+
[self registerComponentViewClass:klass andWarnIfNeeded:isRegisteredInInteropLayer];
112119
return YES;
113120
}
114121

115122
// Fallback 2: Try to use Paper Interop.
116-
NSString *componentNameString = RCTNSStringFromString(name);
117-
if ([RCTLegacyViewManagerInteropComponentView isSupported:componentNameString]) {
123+
if (isRegisteredInInteropLayer) {
118124
RCTLogNewArchitectureValidation(
119125
RCTNotAllowedInBridgeless,
120126
self,
@@ -203,4 +209,17 @@ - (RCTComponentViewDescriptor)createComponentViewWithComponentHandle:(facebook::
203209
return _providerRegistry.createComponentDescriptorRegistry(parameters);
204210
}
205211

212+
#pragma mark - Private
213+
214+
- (void)registerComponentViewClass:(Class<RCTComponentViewProtocol>)componentViewClass
215+
andWarnIfNeeded:(BOOL)isRegisteredInInteropLayer
216+
{
217+
[self registerComponentViewClass:componentViewClass];
218+
if (isRegisteredInInteropLayer) {
219+
RCTLogWarn(
220+
@"Component with class %@ has been registered in both the New Architecture Renderer and in the Interop Layer.\nPlease remove it from the Interop Layer",
221+
componentViewClass);
222+
}
223+
}
224+
206225
@end

packages/rn-tester/react-native.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ module.exports = {
2828
project: {
2929
ios: {
3030
sourceDir: '.',
31+
unstable_reactLegacyComponentNames: [
32+
'RNTMyLegacyNativeView',
33+
'RNTMyNativeView',
34+
],
35+
},
36+
android: {
37+
sourceDir: '../../',
3138
},
3239
},
3340
};

0 commit comments

Comments
 (0)