Skip to content

Commit 4579aa5

Browse files
Dmitry Rykunfacebook-github-bot
authored andcommitted
Export Commands and Constants only if native view config interop is enabled (#39696)
Summary: `Commands` and `Constants` should be set in native only if component data is instantiated via native view config interop layer. Changelog: [Internal] Reviewed By: RSNara Differential Revision: D49684166
1 parent 5203354 commit 4579aa5

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

packages/react-native/React/Modules/RCTUIManager.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,9 +1489,10 @@ static void RCTMeasureLayout(RCTShadowView *view, RCTShadowView *ancestor, RCTRe
14891489
// lazifyViewManagerConfig function in JS. This fuction uses NativeModules global object that is not available in the
14901490
// New Architecture. To make native view configs work in the New Architecture we will populate these properties in
14911491
// native.
1492-
moduleConstants[@"Commands"] = viewConfig[@"Commands"];
1493-
moduleConstants[@"Constants"] = viewConfig[@"Constants"];
1494-
1492+
if (RCTGetUseNativeViewConfigsInBridgelessMode()) {
1493+
moduleConstants[@"Commands"] = viewConfig[@"Commands"];
1494+
moduleConstants[@"Constants"] = viewConfig[@"Constants"];
1495+
}
14951496
// Add direct events
14961497
for (NSString *eventName in viewConfig[@"directEvents"]) {
14971498
if (!directEvents[eventName]) {

packages/react-native/React/Views/RCTComponentData.m

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,6 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowV
480480
}
481481
}
482482

483-
NSDictionary<NSString *, NSNumber *> *commands = [self commandsForViewMangerClass:managerClass
484-
methods:methods
485-
methodCount:count];
486-
free(methods);
487-
488483
#if RCT_DEBUG
489484
for (NSString *event in bubblingEvents) {
490485
if ([directEvents containsObject:event]) {
@@ -499,15 +494,22 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowV
499494

500495
Class superClass = [managerClass superclass];
501496

502-
return @{
497+
NSMutableDictionary *result = [[NSMutableDictionary alloc] initWithDictionary:@{
503498
@"propTypes" : propTypes,
504499
@"directEvents" : directEvents,
505500
@"bubblingEvents" : bubblingEvents,
506501
@"capturingEvents" : capturingEvents,
507502
@"baseModuleName" : superClass == [NSObject class] ? (id)kCFNull : RCTViewManagerModuleNameForClass(superClass),
508-
@"Commands" : commands,
509-
@"Constants" : [self constantsForViewMangerClass:managerClass],
510-
};
503+
}];
504+
505+
if (RCTGetUseNativeViewConfigsInBridgelessMode()) {
506+
result[@"Commands"] = [self commandsForViewMangerClass:managerClass methods:methods methodCount:count];
507+
result[@"Constants"] = [self constantsForViewMangerClass:managerClass];
508+
}
509+
510+
free(methods);
511+
512+
return result;
511513
}
512514

513515
- (NSDictionary<NSString *, id> *)viewConfig

0 commit comments

Comments
 (0)