Skip to content

Commit ab622b6

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Extract TextLayoutManager::baseline()
Summary: 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] Differential Revision: D73555465
1 parent 996327b commit ab622b6

File tree

6 files changed

+14
-41
lines changed

6 files changed

+14
-41
lines changed

packages/react-native/ReactCommon/react/renderer/components/text/ParagraphShadowNode.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,9 @@ Float ParagraphShadowNode::baseline(
214214
}
215215

216216
AttributedStringBox attributedStringBox{attributedString};
217-
return textLayoutManager_->baseline(
218-
attributedStringBox, getConcreteProps().paragraphAttributes, size);
217+
218+
return LineMeasurement::baseline(textLayoutManager_->measureLines(
219+
attributedStringBox, getConcreteProps().paragraphAttributes, size));
219220
}
220221

221222
void ParagraphShadowNode::layout(LayoutContext layoutContext) {

packages/react-native/ReactCommon/react/renderer/components/textinput/BaseTextInputShadowNode.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class BaseTextInputShadowNode : public ConcreteViewShadowNode<
106106
&(YogaLayoutableShadowNode::yogaNode_), YGEdgeTop);
107107

108108
AttributedStringBox attributedStringBox{attributedString};
109-
return textLayoutManager_->baseline(
110-
attributedStringBox, props.paragraphAttributes, size) +
109+
return LineMeasurement::baseline(textLayoutManager_->measureLines(
110+
attributedStringBox, props.paragraphAttributes, size)) +
111111
top;
112112
}
113113

packages/react-native/ReactCommon/react/renderer/components/textinput/platform/android/react/renderer/components/androidtextinput/AndroidTextInputShadowNode.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ Float AndroidTextInputShadowNode::baseline(
9292
YGNodeLayoutGetPadding(&yogaNode_, YGEdgeTop);
9393

9494
AttributedStringBox attributedStringBox{attributedString};
95-
return textLayoutManager_->baseline(
95+
return LineMeasurement::baseline(textLayoutManager_->measureLines(
9696
attributedStringBox,
9797
getConcreteProps().paragraphAttributes,
98-
size) +
98+
size)) +
9999
top;
100100
}
101101

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextLayoutManager.cpp

-26
This file was deleted.

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextLayoutManager.h

-9
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@ class TextLayoutManager {
6969
const ParagraphAttributes& paragraphAttributes,
7070
const Size& size) const;
7171

72-
/*
73-
* Calculates baseline of `attributedString` using native text rendering
74-
* infrastructure.
75-
*/
76-
Float baseline(
77-
const AttributedStringBox& attributedStringBox,
78-
const ParagraphAttributes& paragraphAttributes,
79-
const Size& size) const;
80-
8172
#ifdef __APPLE__
8273
/*
8374
* Returns an opaque pointer to platform-specific TextLayoutManager.

packages/react-native/ReactCommon/react/renderer/textlayoutmanager/TextMeasureCache.h

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ struct LineMeasurement {
3535
LineMeasurement(const folly::dynamic& data);
3636

3737
bool operator==(const LineMeasurement& rhs) const;
38+
39+
static inline Float baseline(const std::vector<LineMeasurement>& lines) {
40+
if (lines.empty()) {
41+
return lines[0].ascender;
42+
}
43+
return 0;
44+
}
3845
};
3946

4047
using LinesMeasurements = std::vector<LineMeasurement>;

0 commit comments

Comments
 (0)