Native view manager event types exposed to JS via view config

Differential Revision: D5814210

fbshipit-source-id: 41291f0d6b39af77f66173f6a699d88f9f4ccc74
This commit is contained in:
Brian Vaughn
2017-09-14 18:01:27 -07:00
committed by Facebook Github Bot
parent e9780bdc0f
commit 75c94a8907
9 changed files with 121 additions and 624 deletions

View File

@@ -1446,6 +1446,11 @@ RCT_EXPORT_METHOD(clearJSResponder)
[_componentDataByName enumerateKeysAndObjectsUsingBlock:^(NSString *name, RCTComponentData *componentData, __unused BOOL *stop) {
NSMutableDictionary<NSString *, id> *moduleConstants = [NSMutableDictionary new];
// Register which event-types this view dispatches.
// React needs this for the event plugin.
NSMutableDictionary<NSString *, NSDictionary *> *bubblingEventTypes = [NSMutableDictionary new];
NSMutableDictionary<NSString *, NSDictionary *> *directEventTypes = [NSMutableDictionary new];
// Add manager class
moduleConstants[@"Manager"] = RCTBridgeModuleNameForClass(componentData.managerClass);
@@ -1453,6 +1458,8 @@ RCT_EXPORT_METHOD(clearJSResponder)
NSDictionary<NSString *, id> *viewConfig = [componentData viewConfig];
moduleConstants[@"NativeProps"] = viewConfig[@"propTypes"];
moduleConstants[@"baseModuleName"] = viewConfig[@"baseModuleName"];
moduleConstants[@"bubblingEventTypes"] = bubblingEventTypes;
moduleConstants[@"directEventTypes"] = directEventTypes;
// Add direct events
for (NSString *eventName in viewConfig[@"directEvents"]) {
@@ -1461,6 +1468,7 @@ RCT_EXPORT_METHOD(clearJSResponder)
@"registrationName": [eventName stringByReplacingCharactersInRange:(NSRange){0, 3} withString:@"on"],
};
}
directEventTypes[eventName] = directEvents[eventName];
if (RCT_DEBUG && bubblingEvents[eventName]) {
RCTLogError(@"Component '%@' re-registered bubbling event '%@' as a "
"direct event", componentData.name, eventName);
@@ -1478,6 +1486,7 @@ RCT_EXPORT_METHOD(clearJSResponder)
}
};
}
bubblingEventTypes[eventName] = bubblingEvents[eventName];
if (RCT_DEBUG && directEvents[eventName]) {
RCTLogError(@"Component '%@' re-registered direct event '%@' as a "
"bubbling event", componentData.name, eventName);
@@ -1488,9 +1497,6 @@ RCT_EXPORT_METHOD(clearJSResponder)
constants[name] = moduleConstants;
}];
constants[@"customBubblingEventTypes"] = bubblingEvents;
constants[@"customDirectEventTypes"] = directEvents;
return constants;
}