瀏覽代碼

Fix default font size regression (#5772)

Yogev Ben David 5 年之前
父節點
當前提交
8f9e719747
No account linked to committer's email address
共有 1 個文件被更改,包括 16 次插入2 次删除
  1. 16
    2
      lib/ios/RNNFontAttributesCreator.m

+ 16
- 2
lib/ios/RNNFontAttributesCreator.m 查看文件

1
 #import "RNNFontAttributesCreator.h"
1
 #import "RNNFontAttributesCreator.h"
2
 #import "RCTConvert+UIFontWeight.h"
2
 #import "RCTConvert+UIFontWeight.h"
3
 
3
 
4
+#define DEFAULT_FONT_SIZE 17.0f
5
+
4
 @implementation RNNFontAttributesCreator
6
 @implementation RNNFontAttributesCreator
5
 
7
 
6
 + (NSDictionary *)createWithFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize defaultFontSize:(NSNumber *)defaultFontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color defaultColor:(UIColor *)defaultColor {
8
 + (NSDictionary *)createWithFontFamily:(NSString *)fontFamily fontSize:(NSNumber *)fontSize defaultFontSize:(NSNumber *)defaultFontSize fontWeight:(NSString *)fontWeight color:(UIColor *)color defaultColor:(UIColor *)defaultColor {
21
 	NSMutableDictionary* titleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:attributesDictionary];\
23
 	NSMutableDictionary* titleTextAttributes = [NSMutableDictionary dictionaryWithDictionary:attributesDictionary];\
22
     UIFont* currentFont = attributesDictionary[NSFontAttributeName];
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
     if (color) {
27
     if (color) {
26
         titleTextAttributes[NSForegroundColorAttributeName] = color;
28
         titleTextAttributes[NSForegroundColorAttributeName] = color;
27
     }
29
     }
29
         titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize weight:[RCTConvert UIFontWeight:fontWeight]];
31
         titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize weight:[RCTConvert UIFontWeight:fontWeight]];
30
     } else if (fontFamily){
32
     } else if (fontFamily){
31
         titleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:fontFamily size:resolvedFontSize];
33
         titleTextAttributes[NSFontAttributeName] = [UIFont fontWithName:fontFamily size:resolvedFontSize];
32
-    } else if (fontSize) {
34
+    } else if (fontSize && currentFont) {
33
         titleTextAttributes[NSFontAttributeName] = [UIFont fontWithDescriptor:currentFont.fontDescriptor size:resolvedFontSize];
35
         titleTextAttributes[NSFontAttributeName] = [UIFont fontWithDescriptor:currentFont.fontDescriptor size:resolvedFontSize];
36
+    } else if (fontSize) {
37
+        titleTextAttributes[NSFontAttributeName] = [UIFont systemFontOfSize:resolvedFontSize];
34
     }
38
     }
35
 	
39
 	
36
 	return titleTextAttributes;
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
 @end
53
 @end