Skip to content

Commit 3d4d097

Browse files
Gate legacy view manager interop behind RCT_REMOVE_LEGACY_COMPONENT_INTEROP (#57071)
Summary: Wraps the iOS legacy `RCTViewManager` ↔ Fabric component interop layer in `#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP` so that apps which opt into compile it out entirely. This enables dead-code elimination of the Paper view manager interop surface for apps that have fully migrated their custom views to Fabric Component Views. Changes: iOS (Objective-C / C++): - `React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.{h,mm}`: Compile the entire translation unit only when the flag is undefined. - `React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropCoordinatorAdapter.{h,mm}`: Compile the entire translation unit only when the flag is undefined. - `ReactCommon/.../platform/ios/.../RCTLegacyViewManagerInteropCoordinator.{h,mm}`: Compile the entire translation unit only when the flag is undefined. - `ReactCommon/.../platform/ios/.../LegacyViewManagerInteropComponentDescriptor.mm`: Compile the entire translation unit only when the flag is undefined. - `React/Base/RCTBridge.{h,mm}`: Hide `RCTFabricInteropLayerEnabled` / `RCTEnableFabricInteropLayer` API and the backing `fabricInteropLayerEnabled` static when the flag is defined. - `React/Fabric/Mounting/RCTComponentViewFactory.mm`: Gate the `#import` of `RCTLegacyViewManagerInteropComponentView.h` and the legacy interop fallback branch in `_registerComponentIfPossible:`. Default behavior is unchanged because `RCT_REMOVE_LEGACY_COMPONENT_INTEROP` is not defined unless the new constraint is selected. Changelog: [General][Added] Gate legacy view manager interop behind `RCT_REMOVE_LEGACY_COMPONENT_INTEROP` Differential Revision: D107440358
1 parent eedfdef commit 3d4d097

10 files changed

Lines changed: 44 additions & 5 deletions

File tree

packages/react-native/React/Base/RCTBridge.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ BOOL RCTTurboModuleInteropEnabled(void);
5656
void RCTEnableTurboModuleInterop(BOOL enabled);
5757
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
5858

59+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
5960
// Turn on the fabric interop layer
6061
BOOL RCTFabricInteropLayerEnabled(void);
6162
void RCTEnableFabricInteropLayer(BOOL enabled);
63+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP
6264

6365
BOOL RCTUIManagerDispatchAccessibilityManagerInitOntoMain(void);
6466
void RCTUIManagerSetDispatchAccessibilityManagerInitOntoMain(BOOL enabled);

packages/react-native/React/Base/RCTBridge.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ void RCTEnableTurboModuleInterop(BOOL enabled)
211211
}
212212
#endif // RCT_REMOVE_LEGACY_MODULE_INTEROP
213213

214+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
214215
static BOOL fabricInteropLayerEnabled = YES;
215216
BOOL RCTFabricInteropLayerEnabled()
216217
{
@@ -221,6 +222,7 @@ void RCTEnableFabricInteropLayer(BOOL enabled)
221222
{
222223
fabricInteropLayerEnabled = enabled;
223224
}
225+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP
224226

225227
static RCTBridgeProxyLoggingLevel bridgeProxyLoggingLevel = kRCTBridgeProxyLoggingLevelNone;
226228
RCTBridgeProxyLoggingLevel RCTTurboModuleInteropBridgeProxyLogLevel(void)

packages/react-native/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
9+
810
#import <UIKit/UIKit.h>
911

1012
#import <React/RCTViewComponentView.h>
@@ -30,3 +32,5 @@ NS_ASSUME_NONNULL_BEGIN
3032
@end
3133

3234
NS_ASSUME_NONNULL_END
35+
36+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP

packages/react-native/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropComponentView.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#import "RCTLegacyViewManagerInteropComponentView.h"
99

10+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
11+
1012
#import <React/RCTAssert.h>
1113
#import <React/RCTBridge+Private.h>
1214
#import <React/RCTConstants.h>
@@ -299,3 +301,5 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
299301
}
300302

301303
@end
304+
305+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP

packages/react-native/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropCoordinatorAdapter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
9+
810
#import <Foundation/Foundation.h>
911
#import <react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.h>
1012

@@ -25,3 +27,5 @@ NS_ASSUME_NONNULL_BEGIN
2527
@end
2628

2729
NS_ASSUME_NONNULL_END
30+
31+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP

packages/react-native/React/Fabric/Mounting/ComponentViews/LegacyViewManagerInterop/RCTLegacyViewManagerInteropCoordinatorAdapter.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77

88
#import "RCTLegacyViewManagerInteropCoordinatorAdapter.h"
9+
10+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
11+
912
#import <React/UIView+React.h>
1013
#import <react/utils/FollyConvert.h>
1114

@@ -146,3 +149,5 @@ - (BOOL)_propIsSameObject:(id)first second:(id)second
146149
}
147150

148151
@end
152+
153+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
#import <React/RCTComponentViewClassDescriptor.h>
3333
#import <React/RCTFabricComponentsPlugins.h>
3434
#import <React/RCTImageComponentView.h>
35+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
3536
#import <React/RCTLegacyViewManagerInteropComponentView.h>
37+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP
3638
#import <React/RCTMountingTransactionObserving.h>
3739
#import <React/RCTParagraphComponentView.h>
3840
#import <React/RCTRootComponentView.h>
@@ -125,11 +127,6 @@ - (void)_registerComponentIfPossible:(const std::string &)name
125127
return;
126128
}
127129

128-
// Paper name: we prepare this variables to warn the user
129-
// when the component is registered in both Fabric and in the
130-
// interop layer, so they can remove that
131-
NSString *componentNameString = RCTNSStringFromString(name);
132-
133130
// Fallback 1: Call provider function for component view class.
134131
Class<RCTComponentViewProtocol> klass = RCTComponentViewClassWithName(name.c_str());
135132
if (klass != nullptr) {
@@ -149,6 +146,12 @@ - (void)_registerComponentIfPossible:(const std::string &)name
149146
}
150147
}
151148

149+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
150+
// Paper name: we prepare this variables to warn the user
151+
// when the component is registered in both Fabric and in the
152+
// interop layer, so they can remove that
153+
NSString *componentNameString = RCTNSStringFromString(name);
154+
152155
// Fallback 3: Try to use Paper Interop.
153156
// TODO(T174674274): Implement lazy loading of legacy view managers in the new architecture.
154157
if (RCTFabricInteropLayerEnabled() && [RCTLegacyViewManagerInteropComponentView isSupported:componentNameString]) {
@@ -166,6 +169,7 @@ - (void)_registerComponentIfPossible:(const std::string &)name
166169
_registrationStatusMap.insert({provider.name, true});
167170
return;
168171
}
172+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP
169173

170174
// Fallback 4: use <UnimplementedView> if component doesn't exist.
171175
auto flavor = std::make_shared<const std::string>(name);

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/platform/ios/react/renderer/components/legacyviewmanagerinterop/LegacyViewManagerInteropComponentDescriptor.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77

88
#include "LegacyViewManagerInteropComponentDescriptor.h"
9+
10+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
11+
912
#include <React/RCTBridge+Private.h>
1013
#include <React/RCTBridge.h>
1114
#include <React/RCTBridgeModuleDecorator.h>
@@ -175,3 +178,5 @@ static Class getViewManagerClass(const std::string &componentName, RCTBridge *br
175178
legacyViewManagerInteropShadowNode.setStateData(std::move(state));
176179
}
177180
} // namespace facebook::react
181+
182+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/platform/ios/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
9+
810
#import <Foundation/Foundation.h>
911
#import <React/RCTBridgeModuleDecorator.h>
1012
#import <UIKit/UIKit.h>
@@ -42,3 +44,5 @@ typedef void (^InterceptorBlock)(std::string eventName, folly::dynamic &&event);
4244
@end
4345

4446
NS_ASSUME_NONNULL_END
47+
48+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP

packages/react-native/ReactCommon/react/renderer/components/legacyviewmanagerinterop/platform/ios/react/renderer/components/legacyviewmanagerinterop/RCTLegacyViewManagerInteropCoordinator.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
*/
77

88
#include "RCTLegacyViewManagerInteropCoordinator.h"
9+
10+
#ifndef RCT_REMOVE_LEGACY_COMPONENT_INTEROP
11+
912
#include <React/RCTBridge+Private.h>
1013
#include <React/RCTBridgeMethod.h>
1114
#include <React/RCTBridgeProxy.h>
@@ -220,3 +223,5 @@ - (void)_lookupModuleMethodsIfNecessary
220223
}
221224

222225
@end
226+
227+
#endif // RCT_REMOVE_LEGACY_COMPONENT_INTEROP

0 commit comments

Comments
 (0)