@@ -35,9 +35,6 @@ static RCTFontProperties RCTResolveFontProperties(
35
35
{
36
36
fontProperties.family = fontProperties.family .length ? fontProperties.family : baseFontProperties.family ;
37
37
fontProperties.size = !isnan (fontProperties.size ) ? fontProperties.size : baseFontProperties.size ;
38
- fontProperties.weight = !isnan (fontProperties.weight ) ? fontProperties.weight : baseFontProperties.weight ;
39
- fontProperties.style =
40
- fontProperties.style != RCTFontStyleUndefined ? fontProperties.style : baseFontProperties.style ;
41
38
fontProperties.variant =
42
39
fontProperties.variant != RCTFontVariantUndefined ? fontProperties.variant : baseFontProperties.variant ;
43
40
return fontProperties;
@@ -116,9 +113,15 @@ static RCTFontStyle RCTGetFontStyle(UIFont *font)
116
113
if ([fontProperties.family isEqualToString: defaultFontProperties.family]) {
117
114
// Handle system font as special case. This ensures that we preserve
118
115
// the specific metrics of the standard system font as closely as possible.
116
+ fontProperties.weight = !isnan (fontProperties.weight ) ? fontProperties.weight : defaultFontProperties.weight ;
117
+ fontProperties.style =
118
+ fontProperties.style != RCTFontStyleUndefined ? fontProperties.style : defaultFontProperties.style ;
119
+
119
120
font = RCTDefaultFontWithFontProperties (fontProperties);
120
121
} else {
121
122
NSArray <NSString *> *fontNames = [UIFont fontNamesForFamilyName: fontProperties.family];
123
+ UIFontWeight fontWeight = fontProperties.weight ;
124
+ RCTFontStyle fontStyle = fontProperties.style ;
122
125
123
126
if (fontNames.count == 0 ) {
124
127
// Gracefully handle being given a font name rather than font family, for
@@ -129,18 +132,24 @@ static RCTFontStyle RCTGetFontStyle(UIFont *font)
129
132
// Failback to system font.
130
133
font = [UIFont systemFontOfSize: effectiveFontSize weight: fontProperties.weight];
131
134
}
132
- } else {
135
+
136
+ fontNames = [UIFont fontNamesForFamilyName: font.familyName];
137
+ fontWeight = isnan (fontWeight) ? RCTGetFontWeight (font) : fontWeight;
138
+ fontStyle = fontStyle == RCTFontStyleUndefined ? RCTGetFontStyle (font) : fontStyle;
139
+ }
140
+
141
+ if (fontNames.count != 0 ) {
133
142
// Get the closest font that matches the given weight for the fontFamily
134
143
CGFloat closestWeight = INFINITY;
135
144
for (NSString *name in fontNames) {
136
145
UIFont *fontMatch = [UIFont fontWithName: name size: effectiveFontSize];
137
146
138
- if (RCTGetFontStyle (fontMatch) != fontProperties. style ) {
147
+ if (RCTGetFontStyle (fontMatch) != fontStyle ) {
139
148
continue ;
140
149
}
141
150
142
151
CGFloat testWeight = RCTGetFontWeight (fontMatch);
143
- if (ABS (testWeight - fontProperties. weight ) < ABS (closestWeight - fontProperties. weight )) {
152
+ if (ABS (testWeight - fontWeight ) < ABS (closestWeight - fontWeight )) {
144
153
font = fontMatch;
145
154
closestWeight = testWeight;
146
155
}
0 commit comments