Improve types in RCTFont API

Reviewed By: majak

Differential Revision: D3662880

fbshipit-source-id: f54e1ac164373337460047eb3708a588f578b5fc
This commit is contained in:
Pieter De Baets 2016-08-05 12:29:21 -07:00 committed by Facebook Github Bot 2
parent 3d6240f9a6
commit f571f016d9
5 changed files with 27 additions and 27 deletions

View File

@ -96,7 +96,7 @@ RCT_REMAP_VIEW_PROPERTY(color, textColor, UIColor)
RCT_REMAP_VIEW_PROPERTY(autoCapitalize, autocapitalizationType, UITextAutocapitalizationType)
RCT_REMAP_VIEW_PROPERTY(textAlign, textAlignment, NSTextAlignment)
RCT_REMAP_VIEW_PROPERTY(selectionColor, tintColor, UIColor)
RCT_CUSTOM_VIEW_PROPERTY(fontSize, CGFloat, RCTTextField)
RCT_CUSTOM_VIEW_PROPERTY(fontSize, NSNumber, RCTTextField)
{
view.font = [RCTFont updateFont:view.font withSize:json ?: @(defaultView.font.pointSize)];
}

View File

@ -46,7 +46,7 @@ RCT_REMAP_VIEW_PROPERTY(secureTextEntry, textView.secureTextEntry, BOOL)
RCT_REMAP_VIEW_PROPERTY(selectionColor, tintColor, UIColor)
RCT_EXPORT_VIEW_PROPERTY(selectTextOnFocus, BOOL)
RCT_EXPORT_VIEW_PROPERTY(text, NSString)
RCT_CUSTOM_VIEW_PROPERTY(fontSize, CGFloat, RCTTextView)
RCT_CUSTOM_VIEW_PROPERTY(fontSize, NSNumber, RCTTextView)
{
view.font = [RCTFont updateFont:view.font withSize:json ?: @(defaultView.font.pointSize)];
}

View File

@ -19,16 +19,16 @@
* If font is nil, the default system font of size 14 will be used.
*/
+ (UIFont *)updateFont:(UIFont *)font
withFamily:(id)family
size:(id)size
weight:(id)weight
style:(id)style
withFamily:(NSString *)family
size:(NSNumber *)size
weight:(NSString *)weight
style:(NSString *)style
scaleMultiplier:(CGFloat)scaleMultiplier;
+ (UIFont *)updateFont:(UIFont *)font withFamily:(id)json;
+ (UIFont *)updateFont:(UIFont *)font withSize:(id)json;
+ (UIFont *)updateFont:(UIFont *)font withWeight:(id)json;
+ (UIFont *)updateFont:(UIFont *)font withStyle:(id)json;
+ (UIFont *)updateFont:(UIFont *)font withFamily:(NSString *)family;
+ (UIFont *)updateFont:(UIFont *)font withSize:(NSNumber *)size;
+ (UIFont *)updateFont:(UIFont *)font withWeight:(NSString *)weight;
+ (UIFont *)updateFont:(UIFont *)font withStyle:(NSString *)style;
@end

View File

@ -104,10 +104,10 @@ static UIFont *cachedSystemFont(CGFloat size, RCTFontWeight weight)
{
json = [self NSDictionary:json];
return [RCTFont updateFont:nil
withFamily:json[@"fontFamily"]
size:json[@"fontSize"]
weight:json[@"fontWeight"]
style:json[@"fontStyle"]
withFamily:[RCTConvert NSString:json[@"fontFamily"]]
size:[RCTConvert NSNumber:json[@"fontSize"]]
weight:[RCTConvert NSString:json[@"fontWeight"]]
style:[RCTConvert NSString:json[@"fontStyle"]]
scaleMultiplier:1];
}
@ -137,10 +137,10 @@ RCT_ENUM_CONVERTER(RCTFontStyle, (@{
@implementation RCTFont
+ (UIFont *)updateFont:(UIFont *)font
withFamily:(id)family
size:(id)size
weight:(id)weight
style:(id)style
withFamily:(NSString *)family
size:(NSNumber *)size
weight:(NSString *)weight
style:(NSString *)style
scaleMultiplier:(CGFloat)scaleMultiplier
{
// Defaults
@ -239,24 +239,24 @@ RCT_ENUM_CONVERTER(RCTFontStyle, (@{
return bestMatch;
}
+ (UIFont *)updateFont:(UIFont *)font withFamily:(id)json
+ (UIFont *)updateFont:(UIFont *)font withFamily:(NSString *)family
{
return [self updateFont:font withFamily:json size:nil weight:nil style:nil scaleMultiplier:1];
return [self updateFont:font withFamily:family size:nil weight:nil style:nil scaleMultiplier:1];
}
+ (UIFont *)updateFont:(UIFont *)font withSize:(id)json
+ (UIFont *)updateFont:(UIFont *)font withSize:(NSNumber *)size
{
return [self updateFont:font withFamily:nil size:json weight:nil style:nil scaleMultiplier:1];
return [self updateFont:font withFamily:nil size:size weight:nil style:nil scaleMultiplier:1];
}
+ (UIFont *)updateFont:(UIFont *)font withWeight:(id)json
+ (UIFont *)updateFont:(UIFont *)font withWeight:(NSString *)weight
{
return [self updateFont:font withFamily:nil size:nil weight:json style:nil scaleMultiplier:1];
return [self updateFont:font withFamily:nil size:nil weight:weight style:nil scaleMultiplier:1];
}
+ (UIFont *)updateFont:(UIFont *)font withStyle:(id)json
+ (UIFont *)updateFont:(UIFont *)font withStyle:(NSString *)style
{
return [self updateFont:font withFamily:nil size:nil weight:nil style:json scaleMultiplier:1];
return [self updateFont:font withFamily:nil size:nil weight:nil style:style scaleMultiplier:1];
}
@end

View File

@ -27,7 +27,7 @@ RCT_EXPORT_VIEW_PROPERTY(selectedIndex, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(color, UIColor)
RCT_EXPORT_VIEW_PROPERTY(textAlign, NSTextAlignment)
RCT_CUSTOM_VIEW_PROPERTY(fontSize, CGFloat, RCTPicker)
RCT_CUSTOM_VIEW_PROPERTY(fontSize, NSNumber, RCTPicker)
{
view.font = [RCTFont updateFont:view.font withSize:json ?: @(defaultView.font.pointSize)];
}