forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact-native+0.75.2+002+iOSFontResolution.patch
58 lines (56 loc) · 3.45 KB
/
react-native+0.75.2+002+iOSFontResolution.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
diff --git a/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTFontUtils.mm b/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTFontUtils.mm
index 1ff8c1f..921b495 100644
--- a/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTFontUtils.mm
+++ b/node_modules/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTFontUtils.mm
@@ -37,9 +37,6 @@ static RCTFontProperties RCTResolveFontProperties(
{
fontProperties.family = fontProperties.family.length ? fontProperties.family : baseFontProperties.family;
fontProperties.size = !isnan(fontProperties.size) ? fontProperties.size : baseFontProperties.size;
- fontProperties.weight = !isnan(fontProperties.weight) ? fontProperties.weight : baseFontProperties.weight;
- fontProperties.style =
- fontProperties.style != RCTFontStyleUndefined ? fontProperties.style : baseFontProperties.style;
fontProperties.variant =
fontProperties.variant != RCTFontVariantUndefined ? fontProperties.variant : baseFontProperties.variant;
return fontProperties;
@@ -161,10 +158,14 @@ static RCTFontStyle RCTGetFontStyle(UIFont *font)
if ([fontProperties.family isEqualToString:defaultFontProperties.family]) {
// Handle system font as special case. This ensures that we preserve
// the specific metrics of the standard system font as closely as possible.
+ fontProperties.weight = !isnan(fontProperties.weight) ? fontProperties.weight : defaultFontProperties.weight;
+ fontProperties.style =
+ fontProperties.style != RCTFontStyleUndefined ? fontProperties.style : defaultFontProperties.style;
font = RCTDefaultFontWithFontProperties(fontProperties);
} else {
NSArray<NSString *> *fontNames = [UIFont fontNamesForFamilyName:fontProperties.family];
-
+ UIFontWeight fontWeight = fontProperties.weight;
+ RCTFontStyle fontStyle = fontProperties.style;
if (fontNames.count == 0) {
// Gracefully handle being given a font name rather than font family, for
// example: "Helvetica Light Oblique" rather than just "Helvetica".
@@ -174,18 +175,24 @@ static RCTFontStyle RCTGetFontStyle(UIFont *font)
// Failback to system font.
font = [UIFont systemFontOfSize:effectiveFontSize weight:fontProperties.weight];
}
- } else {
+
+ fontNames = [UIFont fontNamesForFamilyName:font.familyName];
+ fontWeight = isnan(fontWeight) ? RCTGetFontWeight(font) : fontWeight;
+ fontStyle = fontStyle == RCTFontStyleUndefined ? RCTGetFontStyle(font) : fontStyle;
+ }
+
+ if (fontNames.count != 0) {
// Get the closest font that matches the given weight for the fontFamily
CGFloat closestWeight = INFINITY;
for (NSString *name in fontNames) {
UIFont *fontMatch = [UIFont fontWithName:name size:effectiveFontSize];
- if (RCTGetFontStyle(fontMatch) != fontProperties.style) {
+ if (RCTGetFontStyle(fontMatch) != fontStyle) {
continue;
}
CGFloat testWeight = RCTGetFontWeight(fontMatch);
- if (ABS(testWeight - fontProperties.weight) < ABS(closestWeight - fontProperties.weight)) {
+ if (ABS(testWeight - fontWeight) < ABS(closestWeight - fontWeight)) {
font = fontMatch;
closestWeight = testWeight;
}