diff --git a/packages/react-native/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp index cc1b1a447ba..9724456948c 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp @@ -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) { diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputShadowNode.h b/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputShadowNode.h index ca450b3e0c6..85ec361b7da 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputShadowNode.h +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputShadowNode.h @@ -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; } diff --git a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp index 22f2f6e4df0..ef8a581a28e 100644 --- a/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp +++ b/packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp @@ -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; } diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextLayoutManager.cpp b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextLayoutManager.cpp deleted file mode 100644 index a547003fe45..00000000000 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextLayoutManager.cpp +++ /dev/null @@ -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 diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextLayoutManager.h b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextLayoutManager.h index 42f22ded1ca..14a6527aac2 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextLayoutManager.h +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextLayoutManager.h @@ -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. diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h index 0a9ff8c78d5..ecd6798f47f 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h @@ -35,6 +35,13 @@ struct LineMeasurement { LineMeasurement(const folly::dynamic& data); bool operator==(const LineMeasurement& rhs) const; + + static inline Float baseline(const std::vector& lines) { + if (!lines.empty()) { + return lines[0].ascender; + } + return 0; + } }; using LinesMeasurements = std::vector;