Skip to content

Commit 6f0a0a5

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Correctly Pass SurfaceID to TextLayoutManager (#51005)
Summary: Pull Request resolved: #51005 We need to get a context corresponding to the root being passed, to be able to resolve things like theme to use. RIght now that's a TODO, that's been around since new arch. Let's pass the real data along. Changelog: [Android][Fixed] - Correctly Pass SurfaceID to TextLayoutManager Reviewed By: javache Differential Revision: D73819640 fbshipit-source-id: 1ae2505b59b8577d35a4dc5bb2a524663f3bd47f
1 parent 2e42eab commit 6f0a0a5

File tree

6 files changed

+31
-20
lines changed

6 files changed

+31
-20
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,11 @@ Size ParagraphShadowNode::measureContent(
181181
attributedString.appendFragment({string, textAttributes, {}});
182182
}
183183

184-
TextLayoutContext textLayoutContext{};
185-
textLayoutContext.pointScaleFactor = layoutContext.pointScaleFactor;
184+
TextLayoutContext textLayoutContext{
185+
.pointScaleFactor = layoutContext.pointScaleFactor,
186+
.surfaceId = getSurfaceId(),
187+
};
188+
186189
return textLayoutManager_
187190
->measure(
188191
AttributedStringBox{attributedString},
@@ -242,8 +245,10 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
242245

243246
updateStateIfNeeded(content);
244247

245-
TextLayoutContext textLayoutContext{};
246-
textLayoutContext.pointScaleFactor = layoutContext.pointScaleFactor;
248+
TextLayoutContext textLayoutContext{
249+
.pointScaleFactor = layoutContext.pointScaleFactor,
250+
.surfaceId = getSurfaceId(),
251+
};
247252
auto measurement = TextMeasurement{};
248253

249254
AttributedStringBox attributedStringBox{content.attributedString};

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ class BaseTextInputShadowNode : public ConcreteViewShadowNode<
7575
auto textConstraints = getTextConstraints(layoutConstraints);
7676

7777
TextLayoutContext textLayoutContext{
78-
.pointScaleFactor = layoutContext.pointScaleFactor};
78+
.pointScaleFactor = layoutContext.pointScaleFactor,
79+
.surfaceId = BaseShadowNode::getSurfaceId(),
80+
};
7981
auto textSize = textLayoutManager_
8082
->measure(
8183
attributedStringBoxToMeasure(layoutContext),

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,17 @@ Size AndroidTextInputShadowNode::measureContent(
3131
const LayoutConstraints& layoutConstraints) const {
3232
auto textConstraints = getTextConstraints(layoutConstraints);
3333

34+
TextLayoutContext textLayoutContext{
35+
.pointScaleFactor = layoutContext.pointScaleFactor,
36+
.surfaceId = getSurfaceId(),
37+
};
38+
3439
if (getStateData().cachedAttributedStringId != 0) {
3540
auto textSize = textLayoutManager_
3641
->measureCachedSpannableById(
3742
getStateData().cachedAttributedStringId,
3843
getConcreteProps().paragraphAttributes,
44+
textLayoutContext,
3945
textConstraints)
4046
.size;
4147
return layoutConstraints.clamp(textSize);
@@ -58,8 +64,6 @@ Size AndroidTextInputShadowNode::measureContent(
5864
return {.width = 0, .height = 0};
5965
}
6066

61-
TextLayoutContext textLayoutContext;
62-
textLayoutContext.pointScaleFactor = layoutContext.pointScaleFactor;
6367
auto textSize = textLayoutManager_
6468
->measure(
6569
AttributedStringBox{attributedString},

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#pragma once
99

10+
#include <react/renderer/core/ReactPrimitives.h>
1011
#include <react/renderer/graphics/Float.h>
1112

1213
namespace facebook::react {
@@ -23,18 +24,13 @@ struct TextLayoutContext {
2324
* to `pixel value`.
2425
*/
2526
Float pointScaleFactor{1.0};
26-
};
2727

28-
inline bool operator==(
29-
const TextLayoutContext& lhs,
30-
const TextLayoutContext& rhs) {
31-
return std::tie(lhs.pointScaleFactor) == std::tie(rhs.pointScaleFactor);
32-
}
28+
/**
29+
* The ID of the surface being laid out
30+
*/
31+
SurfaceId surfaceId{-1};
3332

34-
inline bool operator!=(
35-
const TextLayoutContext& lhs,
36-
const TextLayoutContext& rhs) {
37-
return !(lhs == rhs);
38-
}
33+
bool operator==(const TextLayoutContext& rhs) const = default;
34+
};
3935

4036
} // namespace facebook::react

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ TextMeasurement doMeasure(
9191
const ContextContainer::Shared& contextContainer,
9292
const AttributedString& attributedString,
9393
const ParagraphAttributes& paragraphAttributes,
94+
const TextLayoutContext& layoutContext,
9495
const LayoutConstraints& layoutConstraints) {
9596
const int attachmentCount = countAttachments(attributedString);
9697
auto env = jni::Environment::current();
@@ -110,7 +111,7 @@ TextMeasurement doMeasure(
110111

111112
auto size = measureAndroidComponent(
112113
contextContainer,
113-
-1, // TODO: we should pass rootTag in
114+
layoutContext.surfaceId,
114115
"RCTText",
115116
std::move(attributedStringMap),
116117
std::move(paragraphAttributesMap),
@@ -185,6 +186,7 @@ TextMeasurement TextLayoutManager::measure(
185186
contextContainer_,
186187
attributedString,
187188
paragraphAttributes,
189+
layoutContext,
188190
layoutConstraints);
189191

190192
if (telemetry != nullptr) {
@@ -201,6 +203,7 @@ TextMeasurement TextLayoutManager::measure(
201203
TextMeasurement TextLayoutManager::measureCachedSpannableById(
202204
int64_t cacheId,
203205
const ParagraphAttributes& paragraphAttributes,
206+
const TextLayoutContext& layoutContext,
204207
const LayoutConstraints& layoutConstraints) const {
205208
auto env = jni::Environment::current();
206209
auto attachmentPositions = env->NewFloatArray(0);
@@ -214,7 +217,7 @@ TextMeasurement TextLayoutManager::measureCachedSpannableById(
214217

215218
auto size = measureAndroidComponent(
216219
contextContainer_,
217-
-1, // TODO: we should pass rootTag in
220+
layoutContext.surfaceId,
218221
"RCTText",
219222
localDataBuilder.build(),
220223
toMapBuffer(paragraphAttributes),

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class TextLayoutManager {
5555
TextMeasurement measureCachedSpannableById(
5656
int64_t cacheId,
5757
const ParagraphAttributes& paragraphAttributes,
58+
const TextLayoutContext& layoutContext,
5859
const LayoutConstraints& layoutConstraints) const;
5960

6061
/*

0 commit comments

Comments
 (0)