mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Back out "Make font styling work when using specific font name on the new architecture" (#42919)
Summary: Changelog: [IOS] [FIXED] - backout https://github.com/facebook/react-native/pull/37109 Pull Request resolved: https://github.com/facebook/react-native/pull/42919 Original commit changeset: 1f0a6a52a714 Original Phabricator Diff: D45351185 Reviewed By: cipolleschi Differential Revision: D53566506 fbshipit-source-id: e96813edfee4b54a7828ac02c3dc8aaffc83d6b7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3dfedbc1ae
commit
f6b984d504
+6
-15
@@ -35,6 +35,9 @@ 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;
|
||||
@@ -113,15 +116,9 @@ UIFont *RCTFontWithFontProperties(RCTFontProperties fontProperties)
|
||||
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
|
||||
@@ -132,24 +129,18 @@ UIFont *RCTFontWithFontProperties(RCTFontProperties fontProperties)
|
||||
// Failback to system font.
|
||||
font = [UIFont systemFontOfSize:effectiveFontSize weight:fontProperties.weight];
|
||||
}
|
||||
|
||||
fontNames = [UIFont fontNamesForFamilyName:font.familyName];
|
||||
fontWeight = isnan(fontWeight) ? RCTGetFontWeight(font) : fontWeight;
|
||||
fontStyle = fontStyle == RCTFontStyleUndefined ? RCTGetFontStyle(font) : fontStyle;
|
||||
}
|
||||
|
||||
if (fontNames.count != 0) {
|
||||
} else {
|
||||
// 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) != fontStyle) {
|
||||
if (RCTGetFontStyle(fontMatch) != fontProperties.style) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CGFloat testWeight = RCTGetFontWeight(fontMatch);
|
||||
if (ABS(testWeight - fontWeight) < ABS(closestWeight - fontWeight)) {
|
||||
if (ABS(testWeight - fontProperties.weight) < ABS(closestWeight - fontProperties.weight)) {
|
||||
font = fontMatch;
|
||||
closestWeight = testWeight;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user