Dynamic Text Sizes for Text component

Summary:
Dynamic Text Sizes for Text component.
Text gains new prop - allowFontScaling (false by default).
There is also AccessibilityManager module that allows you to tune multipliers per each content size category.
This commit is contained in:
Vladislav Alexeev
2015-07-31 07:37:12 -07:00
parent 407eb4ce85
commit 53fb5b6cee
14 changed files with 331 additions and 13 deletions

View File

@@ -91,7 +91,8 @@ typedef NSURL RCTFileURL;
+ (UIFont *)UIFont:(UIFont *)font withStyle:(id)json;
+ (UIFont *)UIFont:(UIFont *)font withFamily:(id)json;
+ (UIFont *)UIFont:(UIFont *)font withFamily:(id)family
size:(id)size weight:(id)weight style:(id)style;
size:(id)size weight:(id)weight style:(id)style
scaleMultiplier:(CGFloat)scaleMultiplier;
typedef NSArray NSStringArray;
+ (NSStringArray *)NSStringArray:(id)json;

View File

@@ -779,31 +779,33 @@ static BOOL RCTFontIsCondensed(UIFont *font)
withFamily:json[@"fontFamily"]
size:json[@"fontSize"]
weight:json[@"fontWeight"]
style:json[@"fontStyle"]];
style:json[@"fontStyle"]
scaleMultiplier:1.0f];
}
+ (UIFont *)UIFont:(UIFont *)font withSize:(id)json
{
return [self UIFont:font withFamily:nil size:json weight:nil style:nil];
return [self UIFont:font withFamily:nil size:json weight:nil style:nil scaleMultiplier:1.0];
}
+ (UIFont *)UIFont:(UIFont *)font withWeight:(id)json
{
return [self UIFont:font withFamily:nil size:nil weight:json style:nil];
return [self UIFont:font withFamily:nil size:nil weight:json style:nil scaleMultiplier:1.0];
}
+ (UIFont *)UIFont:(UIFont *)font withStyle:(id)json
{
return [self UIFont:font withFamily:nil size:nil weight:nil style:json];
return [self UIFont:font withFamily:nil size:nil weight:nil style:json scaleMultiplier:1.0];
}
+ (UIFont *)UIFont:(UIFont *)font withFamily:(id)json
{
return [self UIFont:font withFamily:json size:nil weight:nil style:nil];
return [self UIFont:font withFamily:json size:nil weight:nil style:nil scaleMultiplier:1.0];
}
+ (UIFont *)UIFont:(UIFont *)font withFamily:(id)family
size:(id)size weight:(id)weight style:(id)style
scaleMultiplier:(CGFloat)scaleMultiplier
{
// Defaults
NSString *const RCTDefaultFontFamily = @"System";
@@ -828,6 +830,9 @@ static BOOL RCTFontIsCondensed(UIFont *font)
// Get font attributes
fontSize = [self CGFloat:size] ?: fontSize;
if (scaleMultiplier > 0.0 && scaleMultiplier != 1.0) {
fontSize = round(fontSize * scaleMultiplier);
}
familyName = [self NSString:family] ?: familyName;
isItalic = style ? [self RCTFontStyle:style] : isItalic;
fontWeight = weight ? [self RCTFontWeight:weight] : fontWeight;