Skip to content

Commit

Permalink
Warn users when a component is registered in Rendere and in the inter…
Browse files Browse the repository at this point in the history
…op (#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
  • Loading branch information
cipolleschi authored and Riccardo Cipolleschi committed Jun 28, 2023
1 parent f537257 commit 4ddfeb6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#import <React/RCTAssert.h>
#import <React/RCTConversions.h>
#import <React/RCTLog.h>

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

// Paper name: we prepare this variables to warn the user
// when the component is registered in both Fabric and in the
// interop layer, so they can remove that
NSString *componentNameString = RCTNSStringFromString(name);
BOOL isRegisteredInInteropLayer = [RCTLegacyViewManagerInteropComponentView isSupported:componentNameString];

// Fallback 1: Call provider function for component view class.
Class<RCTComponentViewProtocol> klass = RCTComponentViewClassWithName(name.c_str());
if (klass) {
[self registerComponentViewClass:klass];
[self registerComponentViewClass:klass andWarnIfNeeded:isRegisteredInInteropLayer];
return YES;
}

// Fallback 2: Try to use Paper Interop.
NSString *componentNameString = RCTNSStringFromString(name);
if ([RCTLegacyViewManagerInteropComponentView isSupported:componentNameString]) {
if (isRegisteredInInteropLayer) {
RCTLogNewArchitectureValidation(
RCTNotAllowedInBridgeless,
self,
Expand Down Expand Up @@ -203,4 +209,17 @@ - (RCTComponentViewDescriptor)createComponentViewWithComponentHandle:(facebook::
return _providerRegistry.createComponentDescriptorRegistry(parameters);
}

#pragma mark - Private

- (void)registerComponentViewClass:(Class<RCTComponentViewProtocol>)componentViewClass
andWarnIfNeeded:(BOOL)isRegisteredInInteropLayer
{
[self registerComponentViewClass:componentViewClass];
if (isRegisteredInInteropLayer) {
RCTLogWarn(
@"Component with class %@ has been registered in both the New Architecture Renderer and in the Interop Layer.\nPlease remove it from the Interop Layer",
componentViewClass);
}
}

@end
7 changes: 7 additions & 0 deletions packages/rn-tester/react-native.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ module.exports = {
project: {
ios: {
sourceDir: '.',
unstable_reactLegacyComponentNames: [
'RNTMyLegacyNativeView',
'RNTMyNativeView',
],
},
android: {
sourceDir: '../../',
},
},
};

0 comments on commit 4ddfeb6

Please sign in to comment.