Skip to content

Commit a702d05

Browse files
cipolleschifacebook-github-bot
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. ## Changelog: [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 a28881a commit a702d05

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

packages/react-native/Libraries/AppDelegate/RCTLegacyInteropComponents.mm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/*
32
* Copyright (c) Meta Platforms, Inc. and affiliates.
43
*
@@ -12,7 +11,7 @@ @implementation RCTLegacyInteropComponents
1211

1312
+ (NSArray<NSString *> *)legacyInteropComponents
1413
{
15-
return @[ @"RNTMyLegacyNativeView" ];
14+
return @[ @"RNTMyLegacyNativeView", @"RNTMyNativeView" ];
1615
}
1716

1817
@end

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

Lines changed: 23 additions & 4 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,10 +106,16 @@ - (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

@@ -119,14 +126,13 @@ - (BOOL)registerComponentIfPossible:(std::string const &)name
119126
NSString *objcName = [NSString stringWithCString:name.c_str() encoding:NSUTF8StringEncoding];
120127
klass = self.thirdPartyFabricComponentsProvider.thirdPartyFabricComponents[objcName];
121128
if (klass) {
122-
[self registerComponentViewClass:klass];
129+
[self registerComponentViewClass:klass andWarnIfNeeded:isRegisteredInInteropLayer];
123130
return YES;
124131
}
125132
}
126133

127134
// Fallback 3: Try to use Paper Interop.
128-
NSString *componentNameString = RCTNSStringFromString(name);
129-
if ([RCTLegacyViewManagerInteropComponentView isSupported:componentNameString]) {
135+
if (isRegisteredInInteropLayer) {
130136
RCTLogNewArchitectureValidation(
131137
RCTNotAllowedInBridgeless,
132138
self,
@@ -215,4 +221,17 @@ - (RCTComponentViewDescriptor)createComponentViewWithComponentHandle:(facebook::
215221
return _providerRegistry.createComponentDescriptorRegistry(parameters);
216222
}
217223

224+
#pragma mark - Private
225+
226+
- (void)registerComponentViewClass:(Class<RCTComponentViewProtocol>)componentViewClass
227+
andWarnIfNeeded:(BOOL)isRegisteredInInteropLayer
228+
{
229+
[self registerComponentViewClass:componentViewClass];
230+
if (isRegisteredInInteropLayer) {
231+
RCTLogWarn(
232+
@"Component with class %@ has been registered in both the New Architecture Renderer and in the Interop Layer.\nPlease remove it from the Interop Layer",
233+
componentViewClass);
234+
}
235+
}
236+
218237
@end

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ module.exports = {
2828
project: {
2929
ios: {
3030
sourceDir: '.',
31-
unstable_reactLegacyComponentNames: ['RNTMyLegacyNativeView'],
31+
unstable_reactLegacyComponentNames: [
32+
'RNTMyLegacyNativeView',
33+
'RNTMyNativeView',
34+
],
3235
},
3336
android: {
3437
sourceDir: '../../',

0 commit comments

Comments
 (0)