Skip to content

Commit

Permalink
Move RCTConvertSelectorForType to their respective using modules
Browse files Browse the repository at this point in the history
Reviewed By: javache

Differential Revision: D6137419

fbshipit-source-id: a30193469e7a061331d3d6798324475890c75625
  • Loading branch information
aditya7fb authored and facebook-github-bot committed Oct 27, 2017
1 parent c0fea38 commit bbc90b4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
5 changes: 0 additions & 5 deletions React/Base/RCTConvert.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ RCT_EXTERN NSNumber *RCTConvertEnumValue(const char *, NSDictionary *, NSNumber
RCT_EXTERN NSNumber *RCTConvertMultiEnumValue(const char *, NSDictionary *, NSNumber *, id);
RCT_EXTERN NSArray *RCTConvertArrayValue(SEL, id);

/**
* Get the converter function for the specified type
*/
RCT_EXTERN SEL RCTConvertSelectorForType(NSString *type);

/**
* This macro is used for logging conversion errors. This is just used to
* avoid repeating the same boilerplate for every error message.
Expand Down
6 changes: 0 additions & 6 deletions React/Base/RCTConvert.m
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,6 @@ + (YGValue)YGValue:(id)json
return values;
}

SEL RCTConvertSelectorForType(NSString *type)
{
const char *input = type.UTF8String;
return NSSelectorFromString([RCTParseType(&input) stringByAppendingString:@":"]);
}

RCT_ARRAY_CONVERTER(NSURL)
RCT_ARRAY_CONVERTER(RCTFileURL)
RCT_ARRAY_CONVERTER(UIColor)
Expand Down
11 changes: 10 additions & 1 deletion React/Base/RCTModuleMethod.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@

typedef BOOL (^RCTArgumentBlock)(RCTBridge *, NSUInteger, id);

/**
* Get the converter function for the specified type
*/
static SEL selectorForType(NSString *type)
{
const char *input = type.UTF8String;
return NSSelectorFromString([RCTParseType(&input) stringByAppendingString:@":"]);
}

@implementation RCTMethodArgument

- (instancetype)initWithType:(NSString *)type
Expand Down Expand Up @@ -257,7 +266,7 @@ - (void)processMethodSignature
BOOL isNullableType = NO;
RCTMethodArgument *argument = arguments[i - 2];
NSString *typeName = argument.type;
SEL selector = RCTConvertSelectorForType(typeName);
SEL selector = selectorForType(typeName);
if ([RCTConvert respondsToSelector:selector]) {
switch (objcType[0]) {
// Primitives
Expand Down
13 changes: 12 additions & 1 deletion React/Views/RCTComponentData.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@
#import "RCTBridge.h"
#import "RCTBridgeModule.h"
#import "RCTConvert.h"
#import "RCTParserUtils.h"
#import "RCTShadowView.h"
#import "RCTUtils.h"
#import "UIView+React.h"

typedef void (^RCTPropBlock)(id<RCTComponent> view, id json);
typedef NSMutableDictionary<NSString *, RCTPropBlock> RCTPropBlockDictionary;

/**
* Get the converter function for the specified type
*/
static SEL selectorForType(NSString *type)
{
const char *input = type.UTF8String;
return NSSelectorFromString([RCTParseType(&input) stringByAppendingString:@":"]);
}


@implementation RCTComponentData
{
id<RCTComponent> _defaultView; // Only needed for RCT_CUSTOM_VIEW_PROPERTY
Expand Down Expand Up @@ -196,7 +207,7 @@ - (RCTPropBlock)createPropBlock:(NSString *)name isShadowView:(BOOL)isShadowView
SEL selector = NSSelectorFromString([NSString stringWithFormat:@"propConfig%@_%@", isShadowView ? @"Shadow" : @"", name]);
if ([_managerClass respondsToSelector:selector]) {
NSArray<NSString *> *typeAndKeyPath = ((NSArray<NSString *> *(*)(id, SEL))objc_msgSend)(_managerClass, selector);
type = RCTConvertSelectorForType(typeAndKeyPath[0]);
type = selectorForType(typeAndKeyPath[0]);
keyPath = typeAndKeyPath.count > 1 ? typeAndKeyPath[1] : nil;
} else {
return ^(__unused id view, __unused id json) {};
Expand Down

0 comments on commit bbc90b4

Please sign in to comment.