Export Commands and Constants only if native view config interop is enabled (#39696)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/39696

`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

fbshipit-source-id: ceaa29c2ed3336aa6e21a116a3f5f94e03c225c1
This commit is contained in:
Dmitry Rykun
2023-09-27 13:41:12 -04:00
committed by Luna Wei
parent 562109fdd3
commit ea09bcd8cb
2 changed files with 15 additions and 12 deletions
@@ -1489,9 +1489,10 @@ NSMutableDictionary<NSString *, id> *RCTModuleConstantsForDestructuredComponent(
// 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]) {
@@ -480,11 +480,6 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S
}
}
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]) {
@@ -499,15 +494,22 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S
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