diff --git a/Libraries/Utilities/MessageQueue.js b/Libraries/Utilities/MessageQueue.js index 415df27c7..8b336bd7e 100644 --- a/Libraries/Utilities/MessageQueue.js +++ b/Libraries/Utilities/MessageQueue.js @@ -67,6 +67,8 @@ class MessageQueue { this._genModulesConfig(localModules),this._moduleTable, this._methodTable ); + this._copyNativeComponentConstants(this.RemoteModules); + this._debugInfo = {}; this._remoteModuleTable = {}; this._remoteMethodTable = {}; @@ -185,6 +187,30 @@ class MessageQueue { * Private helper methods */ + /** + * Copies the ViewManager constants into UIManager. This is only + * needed for iOS, which puts the constants in the ViewManager + * namespace instead of UIManager, unlike Android. + */ + _copyNativeComponentConstants(remoteModules) { + let UIManager = remoteModules.RCTUIManager; + UIManager && Object.keys(UIManager).forEach(viewName => { + let viewConfig = UIManager[viewName]; + if (viewConfig.Manager) { + const viewManager = remoteModules[viewConfig.Manager]; + viewManager && Object.keys(viewManager).forEach(key => { + const value = viewManager[key]; + if (typeof value !== 'function') { + if (!viewConfig.Constants) { + viewConfig.Constants = {}; + } + viewConfig.Constants[key] = value; + } + }); + } + }); + } + /** * Converts the old, object-based module structure to the new * array-based structure. TODO (t8823865) Removed this diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 83ced744d..679e84767 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -1197,14 +1197,8 @@ RCT_EXPORT_METHOD(clearJSResponder) NSMutableDictionary *constantsNamespace = [NSMutableDictionary dictionaryWithDictionary:allJSConstants[name]]; - // Add custom constants - // TODO: should these be inherited? - NSDictionary *constants = RCTClassOverridesInstanceMethod([manager class], @selector(constantsToExport)) ? [manager constantsToExport] : nil; - if (constants.count) { - RCTAssert(constantsNamespace[@"Constants"] == nil , @"Cannot redefine Constants in namespace: %@", name); - // add an additional 'Constants' namespace for each class - constantsNamespace[@"Constants"] = constants; - } + // Add manager class + constantsNamespace[@"Manager"] = RCTBridgeModuleNameForClass([manager class]); // Add native props NSDictionary *viewConfig = [componentData viewConfig];