@@ -481,24 +481,6 @@ + (CGColorRef)CGColor:(id)json
481
481
return [self UIColor: json].CGColor ;
482
482
}
483
483
484
- #if !defined(__IPHONE_8_2) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_8_2
485
-
486
- // These constants are defined in iPhone SDK 8.2, but the app cannot run on
487
- // iOS < 8.2 unless we redefine them here. If you target iOS 8.2 or above
488
- // as a base target, the standard constants will be used instead.
489
-
490
- #define UIFontWeightUltraLight -0.8
491
- #define UIFontWeightThin -0.6
492
- #define UIFontWeightLight -0.4
493
- #define UIFontWeightRegular 0
494
- #define UIFontWeightMedium 0.23
495
- #define UIFontWeightSemibold 0.3
496
- #define UIFontWeightBold 0.4
497
- #define UIFontWeightHeavy 0.56
498
- #define UIFontWeightBlack 0.62
499
-
500
- #endif
501
-
502
484
typedef CGFloat RCTFontWeight;
503
485
RCT_ENUM_CONVERTER (RCTFontWeight, (@{
504
486
@" normal" : @(UIFontWeightRegular),
@@ -575,49 +557,52 @@ + (UIFont *)UIFont:(id)json
575
557
size: json[@" fontSize" ]
576
558
weight: json[@" fontWeight" ]
577
559
style: json[@" fontStyle" ]
578
- scaleMultiplier: 1 . 0f ];
560
+ scaleMultiplier: 1 ];
579
561
}
580
562
581
563
+ (UIFont *)UIFont : (UIFont *)font withSize : (id )json
582
564
{
583
- return [self UIFont: font withFamily: nil size: json weight: nil style: nil scaleMultiplier: 1.0 ];
565
+ return [self UIFont: font withFamily: nil size: json weight: nil style: nil scaleMultiplier: 1 ];
584
566
}
585
567
586
568
+ (UIFont *)UIFont : (UIFont *)font withWeight : (id )json
587
569
{
588
- return [self UIFont: font withFamily: nil size: nil weight: json style: nil scaleMultiplier: 1.0 ];
570
+ return [self UIFont: font withFamily: nil size: nil weight: json style: nil scaleMultiplier: 1 ];
589
571
}
590
572
591
573
+ (UIFont *)UIFont : (UIFont *)font withStyle : (id )json
592
574
{
593
- return [self UIFont: font withFamily: nil size: nil weight: nil style: json scaleMultiplier: 1.0 ];
575
+ return [self UIFont: font withFamily: nil size: nil weight: nil style: json scaleMultiplier: 1 ];
594
576
}
595
577
596
578
+ (UIFont *)UIFont : (UIFont *)font withFamily : (id )json
597
579
{
598
- return [self UIFont: font withFamily: json size: nil weight: nil style: nil scaleMultiplier: 1.0 ];
580
+ return [self UIFont: font withFamily: json size: nil weight: nil style: nil scaleMultiplier: 1 ];
599
581
}
600
582
601
583
+ (UIFont *)UIFont : (UIFont *)font withFamily : (id )family
602
584
size : (id )size weight : (id )weight style : (id )style
603
585
scaleMultiplier : (CGFloat)scaleMultiplier
604
586
{
605
587
// Defaults
606
- NSString *const RCTDefaultFontFamily = @" System" ;
607
- NSString *const RCTIOS8SystemFontFamily = @" Helvetica Neue" ;
608
- const RCTFontWeight RCTDefaultFontWeight = UIFontWeightRegular;
609
- const CGFloat RCTDefaultFontSize = 14 ;
588
+ static NSString *defaultFontFamily;
589
+ static dispatch_once_t onceToken;
590
+ dispatch_once (&onceToken, ^{
591
+ defaultFontFamily = [UIFont systemFontOfSize: 14 ].familyName ;
592
+ });
593
+ const RCTFontWeight defaultFontWeight = UIFontWeightRegular;
594
+ const CGFloat defaultFontSize = 14 ;
610
595
611
596
// Initialize properties to defaults
612
- CGFloat fontSize = RCTDefaultFontSize ;
613
- RCTFontWeight fontWeight = RCTDefaultFontWeight ;
614
- NSString *familyName = RCTDefaultFontFamily ;
597
+ CGFloat fontSize = defaultFontSize ;
598
+ RCTFontWeight fontWeight = defaultFontWeight ;
599
+ NSString *familyName = defaultFontFamily ;
615
600
BOOL isItalic = NO ;
616
601
BOOL isCondensed = NO ;
617
602
618
603
if (font) {
619
- familyName = font.familyName ?: RCTDefaultFontFamily ;
620
- fontSize = font.pointSize ?: RCTDefaultFontSize ;
604
+ familyName = font.familyName ?: defaultFontFamily ;
605
+ fontSize = font.pointSize ?: defaultFontSize ;
621
606
fontWeight = RCTWeightOfFont (font);
622
607
isItalic = RCTFontIsItalic (font);
623
608
isCondensed = RCTFontIsCondensed (font);
@@ -634,7 +619,7 @@ + (UIFont *)UIFont:(UIFont *)font withFamily:(id)family
634
619
635
620
// Handle system font as special case. This ensures that we preserve
636
621
// the specific metrics of the standard system font as closely as possible.
637
- if ([familyName isEqual: RCTDefaultFontFamily ]) {
622
+ if ([familyName isEqual: defaultFontFamily] || [familyName isEqualToString: @" System " ]) {
638
623
if ([UIFont respondsToSelector: @selector (systemFontOfSize:weight: )]) {
639
624
font = [UIFont systemFontOfSize: fontSize weight: fontWeight];
640
625
if (isItalic || isCondensed) {
@@ -650,10 +635,6 @@ + (UIFont *)UIFont:(UIFont *)font withFamily:(id)family
650
635
font = [UIFont fontWithDescriptor: fontDescriptor size: fontSize];
651
636
}
652
637
return font;
653
- } else {
654
- // systemFontOfSize:weight: isn't available prior to iOS 8.2, so we
655
- // fall back to finding the correct font manually, by linear search.
656
- familyName = RCTIOS8SystemFontFamily;
657
638
}
658
639
}
659
640
0 commit comments