@@ -455,6 +455,9 @@ - (RCTViewManagerUIBlock)uiBlockWithLayoutUpdateForRootView:(RCTShadowView *)roo
455455 [frames addObject: [NSValue valueWithCGRect: shadowView.frame]];
456456 [areNew addObject: @(shadowView.isNewView)];
457457 [parentsAreNew addObject: @(shadowView.superview.isNewView)];
458+
459+ // TODO (#8214142): this can be greatly simplified by sending the layout
460+ // event directly from the shadow thread, which may be better anyway.
458461 id event = (id )kCFNull ;
459462 if (shadowView.onLayout ) {
460463 event = @{
@@ -1128,67 +1131,68 @@ static void RCTMeasureLayout(RCTShadowView *view,
11281131 }];
11291132}
11301133
1131- - (NSDictionary *)bubblingEventsConfig
1134+ - (NSDictionary *)constantsToExport
11321135{
1133- NSMutableDictionary *customBubblingEventTypesConfigs = [NSMutableDictionary new ];
1134- for (RCTComponentData *componentData in _componentDataByName.allValues ) {
1135- RCTViewManager *manager = componentData.manager ;
1136- if (RCTClassOverridesInstanceMethod ([manager class ], @selector (customBubblingEventTypes ))) {
1137- NSArray *events = [manager customBubblingEventTypes ];
1138- if (RCT_DEBUG) {
1139- RCTAssert (!events || [events isKindOfClass: [NSArray class ]],
1140- @" customBubblingEventTypes must return an array, but %@ returned %@ " ,
1141- [manager class ], [events class ]);
1142- }
1143- for (NSString *eventName in events) {
1144- NSString *topName = RCTNormalizeInputEventName (eventName);
1145- if (!customBubblingEventTypesConfigs[topName]) {
1146- NSString *bubbleName = [topName stringByReplacingCharactersInRange: (NSRange ){0 , 3 } withString: @" on" ];
1147- customBubblingEventTypesConfigs[topName] = @{
1148- @" phasedRegistrationNames" : @{
1149- @" bubbled" : bubbleName,
1150- @" captured" : [bubbleName stringByAppendingString: @" Capture" ],
1151- }
1152- };
1153- }
1154- }
1155- }
1156- };
1136+ NSMutableDictionary *allJSConstants = [NSMutableDictionary new ];
1137+ NSMutableDictionary *directEvents = [NSMutableDictionary new ];
1138+ NSMutableDictionary *bubblingEvents = [NSMutableDictionary new ];
11571139
1158- return customBubblingEventTypesConfigs;
1159- }
1140+ [_componentDataByName enumerateKeysAndObjectsUsingBlock:
1141+ ^( NSString *name, RCTComponentData *componentData, __unused BOOL *stop) {
11601142
1161- - (NSDictionary *)directEventsConfig
1162- {
1163- NSMutableDictionary *customDirectEventTypes = [NSMutableDictionary new ];
1164- for (RCTComponentData *componentData in _componentDataByName.allValues ) {
1165- RCTViewManager *manager = componentData.manager ;
1166- if (RCTClassOverridesInstanceMethod ([manager class ], @selector (customDirectEventTypes ))) {
1167- NSArray *events = [manager customDirectEventTypes ];
1168- if (RCT_DEBUG) {
1169- RCTAssert (!events || [events isKindOfClass: [NSArray class ]],
1170- @" customDirectEventTypes must return an array, but %@ returned %@ " ,
1171- [manager class ], [events class ]);
1172- }
1173- for (NSString *eventName in events) {
1174- NSString *topName = RCTNormalizeInputEventName (eventName);
1175- if (!customDirectEventTypes[topName]) {
1176- customDirectEventTypes[topName] = @{
1177- @" registrationName" : [topName stringByReplacingCharactersInRange: (NSRange ){0 , 3 } withString: @" on" ],
1178- };
1179- }
1180- }
1181- }
1182- };
1143+ RCTViewManager *manager = componentData.manager ;
1144+ NSMutableDictionary *constantsNamespace =
1145+ [NSMutableDictionary dictionaryWithDictionary: allJSConstants[name]];
11831146
1184- return customDirectEventTypes;
1185- }
1147+ // Add custom constants
1148+ // TODO: should these be inherited?
1149+ NSDictionary *constants = RCTClassOverridesInstanceMethod ([manager class ], @selector (constantsToExport )) ? [manager constantsToExport ] : nil ;
1150+ if (constants.count ) {
1151+ RCTAssert (constantsNamespace[@" Constants" ] == nil , @" Cannot redefine Constants in namespace: %@ " , name);
1152+ // add an additional 'Constants' namespace for each class
1153+ constantsNamespace[@" Constants" ] = constants;
1154+ }
1155+
1156+ // Add native props
1157+ NSDictionary *viewConfig = [componentData viewConfig ];
1158+ constantsNamespace[@" NativeProps" ] = viewConfig[@" propTypes" ];
1159+
1160+ // Add direct events
1161+ for (NSString *eventName in viewConfig[@" directEvents" ]) {
1162+ if (!directEvents[eventName]) {
1163+ directEvents[eventName] = @{
1164+ @" registrationName" : [eventName stringByReplacingCharactersInRange: (NSRange ){0 , 3 } withString: @" on" ],
1165+ };
1166+ }
1167+ if (RCT_DEBUG && bubblingEvents[eventName]) {
1168+ RCTLogError (@" Component '%@ ' re-registered bubbling event '%@ ' as a "
1169+ " direct event" , componentData.name , eventName);
1170+ }
1171+ }
1172+
1173+ // Add bubbling events
1174+ for (NSString *eventName in viewConfig[@" bubblingEvents" ]) {
1175+ if (!bubblingEvents[eventName]) {
1176+ NSString *bubbleName = [eventName stringByReplacingCharactersInRange: (NSRange ){0 , 3 } withString: @" on" ];
1177+ bubblingEvents[eventName] = @{
1178+ @" phasedRegistrationNames" : @{
1179+ @" bubbled" : bubbleName,
1180+ @" captured" : [bubbleName stringByAppendingString: @" Capture" ],
1181+ }
1182+ };
1183+ }
1184+ if (RCT_DEBUG && directEvents[eventName]) {
1185+ RCTLogError (@" Component '%@ ' re-registered direct event '%@ ' as a "
1186+ " bubbling event" , componentData.name , eventName);
1187+ }
1188+ }
1189+
1190+ allJSConstants[name] = [constantsNamespace copy ];
1191+ }];
11861192
1187- - (NSDictionary *)constantsToExport
1188- {
1189- NSMutableDictionary *allJSConstants = [@{
1190- @" customBubblingEventTypes" : [self bubblingEventsConfig ],
1191- @" customDirectEventTypes" : [self directEventsConfig ],
1193+ [allJSConstants addEntriesFromDictionary: @{
1194+ @" customBubblingEventTypes" : bubblingEvents,
1195+ @" customDirectEventTypes" : directEvents,
11921196 @" Dimensions" : @{
11931197 @" window" : @{
11941198 @" width" : @(RCTScreenSize ().width ),
@@ -1200,28 +1204,8 @@ - (NSDictionary *)constantsToExport
12001204 @" height" : @(RCTScreenSize ().height ),
12011205 },
12021206 },
1203- } mutableCopy];
1204-
1205- [_componentDataByName enumerateKeysAndObjectsUsingBlock:
1206- ^(NSString *name, RCTComponentData *componentData, __unused BOOL *stop) {
1207- RCTViewManager *manager = componentData.manager ;
1208- NSMutableDictionary *constantsNamespace =
1209- [NSMutableDictionary dictionaryWithDictionary: allJSConstants[name]];
1210-
1211- // Add custom constants
1212- // TODO: should these be inherited?
1213- NSDictionary *constants = RCTClassOverridesInstanceMethod ([manager class ], @selector (constantsToExport )) ? [manager constantsToExport ] : nil ;
1214- if (constants.count ) {
1215- RCTAssert (constantsNamespace[@" Constants" ] == nil , @" Cannot redefine Constants in namespace: %@ " , name);
1216- // add an additional 'Constants' namespace for each class
1217- constantsNamespace[@" Constants" ] = constants;
1218- }
1219-
1220- // Add native props
1221- constantsNamespace[@" NativeProps" ] = [componentData viewConfig ];
1222-
1223- allJSConstants[name] = [constantsNamespace copy ];
12241207 }];
1208+
12251209 return allJSConstants;
12261210}
12271211
0 commit comments