-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support native ViewManager inheritance on iOS #14775
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<NSString *, id> *)props forShadowView:(RCTShadowV | |
} | ||
} | ||
#endif | ||
|
||
|
||
Class superClass = [_managerClass superclass]; | ||
|
||
return @{ | ||
@"propTypes": propTypes, | ||
@"directEvents": directEvents, | ||
@"bubblingEvents": bubblingEvents, | ||
@"baseModuleName": superClass != [NSObject class] ? [self moduleNameForClass:superClass] : [NSNull null] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Please avoid "negative logic": Changing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
}; | ||
} | ||
|
||
|
@@ -455,4 +442,26 @@ - (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(NSDictionary<NSNu | |
return nil; | ||
} | ||
|
||
- (NSString *)moduleNameForClass:(Class)managerClass | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method doesn't depend on any state, make it a static C-function. |
||
{ | ||
// 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); | ||
|
||
return name; | ||
} | ||
|
||
@end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does using
do { } while ();
loop make this code a bit cleaner/easier-to-read?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do { } while ();
would make it execute the statement at least once, which we don't want to do if there is nobaseModuleName
exported. So not sure if that is a good idea.