From 3d9b553b150d21e2f47a9a5e1982e58308efac18 Mon Sep 17 00:00:00 2001 From: Christian Brevik Date: Tue, 27 Jun 2017 08:47:07 +0200 Subject: [PATCH 1/3] Add baseModuleName module constant for inheritance And re-establish inheritance relationship in requireNativeComponent --- .../ReactNative/requireNativeComponent.js | 20 ++++++--- React/Modules/RCTUIManager.m | 1 + React/Views/RCTComponentData.m | 45 +++++++++++-------- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/Libraries/ReactNative/requireNativeComponent.js b/Libraries/ReactNative/requireNativeComponent.js index 00327a97c73e9f..7c6aedf14c5085 100644 --- a/Libraries/ReactNative/requireNativeComponent.js +++ b/Libraries/ReactNative/requireNativeComponent.js @@ -70,13 +70,19 @@ function requireNativeComponent( viewConfig.propTypes = null; } - // The ViewConfig doesn't contain any props inherited from the view manager's - // superclass, so we manually merge in the RCTView ones. Other inheritance - // patterns are currenty not supported. - const nativeProps = { - ...UIManager.RCTView.NativeProps, - ...viewConfig.NativeProps, - }; + let baseModuleName = viewConfig.baseModuleName; + let nativeProps = { ...viewConfig.NativeProps }; + while (baseModuleName) { + const baseModule = UIManager[baseModuleName]; + if (!baseModule) { + warning(false, 'Base module "%s" does not exist', baseModuleName); + baseModuleName = null; + } else { + nativeProps = { ...nativeProps, ...baseModule.NativeProps }; + baseModuleName = baseModule.baseModuleName; + } + } + for (const key in nativeProps) { let useAttribute = false; const attribute = {}; diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 5d5c36a403859e..596bcb49871fb5 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -1542,6 +1542,7 @@ static void RCTMeasureLayout(RCTShadowView *view, // Add native props NSDictionary *viewConfig = [componentData viewConfig]; moduleConstants[@"NativeProps"] = viewConfig[@"propTypes"]; + moduleConstants[@"baseModuleName"] = viewConfig[@"baseModuleName"]; // Add direct events for (NSString *eventName in viewConfig[@"directEvents"]) { diff --git a/React/Views/RCTComponentData.m b/React/Views/RCTComponentData.m index 91c92f94a60ffd..4045652e8394e7 100644 --- a/React/Views/RCTComponentData.m +++ b/React/Views/RCTComponentData.m @@ -41,23 +41,7 @@ - (instancetype)initWithManagerClass:(Class)managerClass _viewPropBlocks = [NSMutableDictionary new]; _shadowPropBlocks = [NSMutableDictionary new]; - // Hackety hack, this partially re-implements RCTBridgeModuleNameForClass - // We want to get rid of RCT and RK prefixes, but a lot of JS code still references - // view names by prefix. So, while RCTBridgeModuleNameForClass now drops these - // prefixes by default, we'll still keep them around here. - NSString *name = [managerClass moduleName]; - if (name.length == 0) { - name = NSStringFromClass(managerClass); - } - if ([name hasPrefix:@"RK"]) { - name = [name stringByReplacingCharactersInRange:(NSRange){0, @"RK".length} withString:@"RCT"]; - } - if ([name hasSuffix:@"Manager"]) { - name = [name substringToIndex:name.length - @"Manager".length]; - } - - RCTAssert(name.length, @"Invalid moduleName '%@'", name); - _name = name; + _name = [self moduleNameForClass:managerClass]; _implementsUIBlockToAmendWithShadowViewRegistry = NO; Class cls = _managerClass; @@ -439,11 +423,14 @@ - (void)setProps:(NSDictionary *)props forShadowView:(RCTShadowV } } #endif - + + Class superClass = [_managerClass superclass]; + return @{ @"propTypes": propTypes, @"directEvents": directEvents, @"bubblingEvents": bubblingEvents, + @"baseModuleName": superClass != [NSObject class] ? [self moduleNameForClass:superClass] : [NSNull null] }; } @@ -455,4 +442,26 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary Date: Thu, 6 Jul 2017 18:28:48 +0200 Subject: [PATCH 2/3] Use kCFNull & static c function --- React/Views/RCTComponentData.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/React/Views/RCTComponentData.m b/React/Views/RCTComponentData.m index 4045652e8394e7..519446a3394b87 100644 --- a/React/Views/RCTComponentData.m +++ b/React/Views/RCTComponentData.m @@ -41,7 +41,7 @@ - (instancetype)initWithManagerClass:(Class)managerClass _viewPropBlocks = [NSMutableDictionary new]; _shadowPropBlocks = [NSMutableDictionary new]; - _name = [self moduleNameForClass:managerClass]; + _name = moduleNameForClass(managerClass); _implementsUIBlockToAmendWithShadowViewRegistry = NO; Class cls = _managerClass; @@ -430,7 +430,7 @@ - (void)setProps:(NSDictionary *)props forShadowView:(RCTShadowV @"propTypes": propTypes, @"directEvents": directEvents, @"bubblingEvents": bubblingEvents, - @"baseModuleName": superClass != [NSObject class] ? [self moduleNameForClass:superClass] : [NSNull null] + @"baseModuleName": superClass == [NSObject class] ? (id)kCFNull : moduleNameForClass(superClass) }; } @@ -442,7 +442,7 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary Date: Mon, 10 Jul 2017 14:30:38 -0700 Subject: [PATCH 3/3] Update RCTComponentData.m --- React/Views/RCTComponentData.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/React/Views/RCTComponentData.m b/React/Views/RCTComponentData.m index 519446a3394b87..7ebe7673e75fd7 100644 --- a/React/Views/RCTComponentData.m +++ b/React/Views/RCTComponentData.m @@ -430,7 +430,7 @@ - (void)setProps:(NSDictionary *)props forShadowView:(RCTShadowV @"propTypes": propTypes, @"directEvents": directEvents, @"bubblingEvents": bubblingEvents, - @"baseModuleName": superClass == [NSObject class] ? (id)kCFNull : moduleNameForClass(superClass) + @"baseModuleName": superClass == [NSObject class] ? [NSNull null] : moduleNameForClass(superClass) }; }