mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Extract TextLayoutManager::baseline() (#50888)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/50888 This is shared between platforms using a very strange pattern. Let's just extract this into its own function. Not considering breaking, since TextLayoutManager is internal interface. Changelog: [internal] Reviewed By: rshest Differential Revision: D73555465 fbshipit-source-id: ea99fbebd9db44efd1dc56c2cad68b5b56e77ad1
This commit is contained in:
committed by
Facebook GitHub Bot
parent
eb459a9f42
commit
01cc16bbfe
+3
-2
@@ -214,8 +214,9 @@ Float ParagraphShadowNode::baseline(
|
||||
}
|
||||
|
||||
AttributedStringBox attributedStringBox{attributedString};
|
||||
return textLayoutManager_->baseline(
|
||||
attributedStringBox, getConcreteProps().paragraphAttributes, size);
|
||||
|
||||
return LineMeasurement::baseline(textLayoutManager_->measureLines(
|
||||
attributedStringBox, getConcreteProps().paragraphAttributes, size));
|
||||
}
|
||||
|
||||
void ParagraphShadowNode::layout(LayoutContext layoutContext) {
|
||||
|
||||
+2
-2
@@ -106,8 +106,8 @@ class BaseTextInputShadowNode : public ConcreteViewShadowNode<
|
||||
&(YogaLayoutableShadowNode::yogaNode_), YGEdgeTop);
|
||||
|
||||
AttributedStringBox attributedStringBox{attributedString};
|
||||
return textLayoutManager_->baseline(
|
||||
attributedStringBox, props.paragraphAttributes, size) +
|
||||
return LineMeasurement::baseline(textLayoutManager_->measureLines(
|
||||
attributedStringBox, props.paragraphAttributes, size)) +
|
||||
top;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -92,10 +92,10 @@ Float AndroidTextInputShadowNode::baseline(
|
||||
YGNodeLayoutGetPadding(&yogaNode_, YGEdgeTop);
|
||||
|
||||
AttributedStringBox attributedStringBox{attributedString};
|
||||
return textLayoutManager_->baseline(
|
||||
return LineMeasurement::baseline(textLayoutManager_->measureLines(
|
||||
attributedStringBox,
|
||||
getConcreteProps().paragraphAttributes,
|
||||
size) +
|
||||
size)) +
|
||||
top;
|
||||
}
|
||||
|
||||
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#include "TextLayoutManager.h"
|
||||
|
||||
namespace facebook::react {
|
||||
|
||||
Float TextLayoutManager::baseline(
|
||||
const AttributedStringBox& attributedStringBox,
|
||||
const ParagraphAttributes& paragraphAttributes,
|
||||
const Size& size) const {
|
||||
auto lines =
|
||||
this->measureLines(attributedStringBox, paragraphAttributes, size);
|
||||
|
||||
if (!lines.empty()) {
|
||||
return lines[0].ascender;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
@@ -69,15 +69,6 @@ class TextLayoutManager {
|
||||
const ParagraphAttributes& paragraphAttributes,
|
||||
const Size& size) const;
|
||||
|
||||
/*
|
||||
* Calculates baseline of `attributedString` using native text rendering
|
||||
* infrastructure.
|
||||
*/
|
||||
Float baseline(
|
||||
const AttributedStringBox& attributedStringBox,
|
||||
const ParagraphAttributes& paragraphAttributes,
|
||||
const Size& size) const;
|
||||
|
||||
#ifdef __APPLE__
|
||||
/*
|
||||
* Returns an opaque pointer to platform-specific TextLayoutManager.
|
||||
|
||||
@@ -35,6 +35,13 @@ struct LineMeasurement {
|
||||
LineMeasurement(const folly::dynamic& data);
|
||||
|
||||
bool operator==(const LineMeasurement& rhs) const;
|
||||
|
||||
static inline Float baseline(const std::vector<LineMeasurement>& lines) {
|
||||
if (!lines.empty()) {
|
||||
return lines[0].ascender;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
using LinesMeasurements = std::vector<LineMeasurement>;
|
||||
|
||||
Reference in New Issue
Block a user