Skip to content

Commit

Permalink
Export Commands and Constants only if native view config interop is e…
Browse files Browse the repository at this point in the history
…nabled (#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
  • Loading branch information
Dmitry Rykun authored and facebook-github-bot committed Sep 27, 2023
1 parent 5203354 commit 4579aa5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
7 changes: 4 additions & 3 deletions packages/react-native/React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -1489,9 +1489,10 @@ static void RCTMeasureLayout(RCTShadowView *view, RCTShadowView *ancestor, RCTRe
// lazifyViewManagerConfig function in JS. This fuction uses NativeModules global object that is not available in the
// New Architecture. To make native view configs work in the New Architecture we will populate these properties in
// native.
moduleConstants[@"Commands"] = viewConfig[@"Commands"];
moduleConstants[@"Constants"] = viewConfig[@"Constants"];

if (RCTGetUseNativeViewConfigsInBridgelessMode()) {
moduleConstants[@"Commands"] = viewConfig[@"Commands"];
moduleConstants[@"Constants"] = viewConfig[@"Constants"];
}
// Add direct events
for (NSString *eventName in viewConfig[@"directEvents"]) {
if (!directEvents[eventName]) {
Expand Down
20 changes: 11 additions & 9 deletions packages/react-native/React/Views/RCTComponentData.m
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,6 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowV
}
}

NSDictionary<NSString *, NSNumber *> *commands = [self commandsForViewMangerClass:managerClass
methods:methods
methodCount:count];
free(methods);

#if RCT_DEBUG
for (NSString *event in bubblingEvents) {
if ([directEvents containsObject:event]) {
Expand All @@ -499,15 +494,22 @@ - (void)setProps:(NSDictionary<NSString *, id> *)props forShadowView:(RCTShadowV

Class superClass = [managerClass superclass];

return @{
NSMutableDictionary *result = [[NSMutableDictionary alloc] initWithDictionary:@{
@"propTypes" : propTypes,
@"directEvents" : directEvents,
@"bubblingEvents" : bubblingEvents,
@"capturingEvents" : capturingEvents,
@"baseModuleName" : superClass == [NSObject class] ? (id)kCFNull : RCTViewManagerModuleNameForClass(superClass),
@"Commands" : commands,
@"Constants" : [self constantsForViewMangerClass:managerClass],
};
}];

if (RCTGetUseNativeViewConfigsInBridgelessMode()) {
result[@"Commands"] = [self commandsForViewMangerClass:managerClass methods:methods methodCount:count];
result[@"Constants"] = [self constantsForViewMangerClass:managerClass];
}

free(methods);

return result;
}

- (NSDictionary<NSString *, id> *)viewConfig
Expand Down

0 comments on commit 4579aa5

Please sign in to comment.