|
@@ -1,6 +1,8 @@
|
1
|
1
|
#import "RNNFontAttributesCreator.h"
|
2
|
2
|
#import "RCTConvert+UIFontWeight.h"
|
3
|
3
|
|
|
4
|
+#define DEFAULT_FONT_SIZE 17.0f
|
|
5
|
+
|
4
|
6
|
@implementation RNNFontAttributesCreator
|
5
|
7
|
|
6
|
8
|
+ (NSDictionary *)createWithFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize defaultFontSize:(NSNumber *)defaultFontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color defaultColor:(UIColor *)defaultColor {
|
|
@@ -21,7 +23,7 @@
|
21
|
23
|
NSMutableDictionary* titleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:attributesDictionary];\
|
22
|
24
|
UIFont* currentFont = attributesDictionary[NSFontAttributeName];
|
23
|
25
|
|
24
|
|
- CGFloat resolvedFontSize = fontSize ? fontSize.floatValue : currentFont.fontDescriptor.pointSize;
|
|
26
|
+ CGFloat resolvedFontSize = [self resolveFontSize:currentFont fontSize:fontSize];
|
25
|
27
|
if (color) {
|
26
|
28
|
titleTextAttributes[NSForegroundColorAttributeName] = color;
|
27
|
29
|
}
|
|
@@ -29,11 +31,23 @@
|
29
|
31
|
titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize weight:[RCTConvert UIFontWeight:fontWeight]];
|
30
|
32
|
} else if (fontFamily){
|
31
|
33
|
titleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:fontFamily size:resolvedFontSize];
|
32
|
|
- } else if (fontSize) {
|
|
34
|
+ } else if (fontSize && currentFont) {
|
33
|
35
|
titleTextAttributes[NSFontAttributeName] = [UIFont fontWithDescriptor:currentFont.fontDescriptor size:resolvedFontSize];
|
|
36
|
+ } else if (fontSize) {
|
|
37
|
+ titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize];
|
34
|
38
|
}
|
35
|
39
|
|
36
|
40
|
return titleTextAttributes;
|
37
|
41
|
}
|
38
|
42
|
|
|
43
|
++ (CGFloat)resolveFontSize:(UIFont *)currentFont fontSize:(NSNumber *)fontSize {
|
|
44
|
+ if (fontSize) {
|
|
45
|
+ return fontSize.floatValue;
|
|
46
|
+ } else if (currentFont) {
|
|
47
|
+ return currentFont.fontDescriptor.pointSize;
|
|
48
|
+ } else {
|
|
49
|
+ return DEFAULT_FONT_SIZE;
|
|
50
|
+ }
|
|
51
|
+}
|
|
52
|
+
|
39
|
53
|
@end
|