From 74034ba23ad1096751dddc94fb4dcaf7d4e022cd Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Wed, 4 Mar 2020 04:57:48 -0800 Subject: [PATCH] Back out "Font size in Text now respects preferredContentSizeCategory" Summary: Original commit changeset: 3965a127069a Changelog: [Internal] Reviewed By: makovkastar Differential Revision: D20246919 fbshipit-source-id: d2238f279f44ac4394557949c8f148f08a60647e --- React/Base/RCTUtils.h | 2 -- React/Base/RCTUtils.m | 24 ------------------- React/Fabric/RCTSurfacePresenter.mm | 1 - .../text/paragraph/ParagraphShadowNode.cpp | 12 ++++------ .../text/paragraph/ParagraphShadowNode.h | 4 ++-- .../fabric/core/layout/LayoutContext.h | 5 ---- 6 files changed, 7 insertions(+), 41 deletions(-) diff --git a/React/Base/RCTUtils.h b/React/Base/RCTUtils.h index fba47a7fe15..9159d3d820e 100644 --- a/React/Base/RCTUtils.h +++ b/React/Base/RCTUtils.h @@ -44,8 +44,6 @@ RCT_EXTERN void RCTUnsafeExecuteOnMainQueueSync(dispatch_block_t block); RCT_EXTERN CGFloat RCTScreenScale(void); RCT_EXTERN CGSize RCTScreenSize(void); -RCT_EXTERN CGFloat RCTFontSizeMultiplier(void); - // Round float coordinates to nearest whole screen pixel (not point) RCT_EXTERN CGFloat RCTRoundPixelValue(CGFloat value); RCT_EXTERN CGFloat RCTCeilPixelValue(CGFloat value); diff --git a/React/Base/RCTUtils.m b/React/Base/RCTUtils.m index 2e8bc82f4c4..c5fd2d8e1ce 100644 --- a/React/Base/RCTUtils.m +++ b/React/Base/RCTUtils.m @@ -301,30 +301,6 @@ CGFloat RCTScreenScale() return scale; } -CGFloat RCTFontSizeMultiplier() -{ - static NSDictionary *mapping; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - mapping = @{ - UIContentSizeCategoryExtraSmall: @0.823, - UIContentSizeCategorySmall: @0.882, - UIContentSizeCategoryMedium: @0.941, - UIContentSizeCategoryLarge: @1.0, - UIContentSizeCategoryExtraLarge: @1.118, - UIContentSizeCategoryExtraExtraLarge: @1.235, - UIContentSizeCategoryExtraExtraExtraLarge: @1.353, - UIContentSizeCategoryAccessibilityMedium: @1.786, - UIContentSizeCategoryAccessibilityLarge: @2.143, - UIContentSizeCategoryAccessibilityExtraLarge: @2.643, - UIContentSizeCategoryAccessibilityExtraExtraLarge: @3.143, - UIContentSizeCategoryAccessibilityExtraExtraExtraLarge: @3.571 - }; - }); - - return mapping[RCTSharedApplication().preferredContentSizeCategory].floatValue; -} - CGSize RCTScreenSize() { // FIXME: this caches the bounds at app start, whatever those were, and then diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 1ef905f9d84..c96763a3928 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -39,7 +39,6 @@ using namespace facebook::react; static LayoutContext RCTCurrentLayoutContext() { return { .pointScaleFactor = RCTScreenScale(), - .fontSizeMultiplier = RCTFontSizeMultiplier() }; } diff --git a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp index a4edcacb91f..04b64d81289 100644 --- a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp +++ b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.cpp @@ -15,10 +15,9 @@ namespace react { char const ParagraphComponentName[] = "Paragraph"; -AttributedString ParagraphShadowNode::getAttributedString(Float fontSizeMultiplier) const { +AttributedString ParagraphShadowNode::getAttributedString() const { if (!cachedAttributedString_.has_value()) { auto textAttributes = TextAttributes::defaultTextAttributes(); - textAttributes.fontSizeMultiplier = fontSizeMultiplier; textAttributes.apply(getConcreteProps().textAttributes); cachedAttributedString_ = @@ -34,10 +33,10 @@ void ParagraphShadowNode::setTextLayoutManager( textLayoutManager_ = textLayoutManager; } -void ParagraphShadowNode::updateStateIfNeeded(LayoutContext layoutContext) { +void ParagraphShadowNode::updateStateIfNeeded() { ensureUnsealed(); - auto attributedString = getAttributedString(layoutContext.fontSizeMultiplier); + auto attributedString = getAttributedString(); auto const &state = getStateData(); assert(textLayoutManager_); @@ -58,8 +57,7 @@ void ParagraphShadowNode::updateStateIfNeeded(LayoutContext layoutContext) { #pragma mark - LayoutableShadowNode Size ParagraphShadowNode::measureContent(LayoutConstraints layoutConstraints, LayoutContext layoutContext) const { - AttributedString attributedString = getAttributedString(layoutContext.fontSizeMultiplier); - + AttributedString attributedString = getAttributedString(); if (attributedString.isEmpty()) { return layoutConstraints.clamp({0, 0}); } @@ -71,7 +69,7 @@ Size ParagraphShadowNode::measureContent(LayoutConstraints layoutConstraints, La } void ParagraphShadowNode::layout(LayoutContext layoutContext) { - updateStateIfNeeded(layoutContext); + updateStateIfNeeded(); ConcreteViewShadowNode::layout(layoutContext); } diff --git a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.h b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.h index fa427600e13..4c28dc820e1 100644 --- a/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.h +++ b/ReactCommon/fabric/components/text/paragraph/ParagraphShadowNode.h @@ -47,7 +47,7 @@ class ParagraphShadowNode : public ConcreteViewShadowNode< /* * Returns a `AttributedString` which represents text content of the node. */ - AttributedString getAttributedString(Float fontSizeMultiplier) const; + AttributedString getAttributedString() const; /* * Associates a shared TextLayoutManager with the node. @@ -66,7 +66,7 @@ class ParagraphShadowNode : public ConcreteViewShadowNode< * Creates a `State` object (with `AttributedText` and * `TextLayoutManager`) if needed. */ - void updateStateIfNeeded(LayoutContext layoutContext); + void updateStateIfNeeded(); SharedTextLayoutManager textLayoutManager_; diff --git a/ReactCommon/fabric/core/layout/LayoutContext.h b/ReactCommon/fabric/core/layout/LayoutContext.h index 3b9fd1f429f..b37bd26231d 100644 --- a/ReactCommon/fabric/core/layout/LayoutContext.h +++ b/ReactCommon/fabric/core/layout/LayoutContext.h @@ -33,11 +33,6 @@ struct LayoutContext { */ Float pointScaleFactor{1.0}; - /* - * Multiplier used to change size of the font in surface. - */ - Float fontSizeMultiplier{1.0}; - /* * A raw pointer to list of raw pointers to `LayoutableShadowNode`s that were * affected by the re-layout pass. If the field is not `nullptr`, a particular