Skip to content

Commit 21ab455

Browse files
NickGerlemanmeta-codesync[bot]
authored andcommitted
PreparedLayout -> PreparedTextLayout (facebook#55558)
Summary: Pull Request resolved: facebook#55558 `PreparedLayout`, in the Android context, refers to an `android.text.Layout`, but is ambiguous, outside of areas which are not clearly namespaced. Lets rename some instances of `PreparedLayout` to `PreparedTextLayout` where ambiguous, which also better matches the feature flag name, `enablePreparedTextLayout`, and the Android view `PreparedLayoutTextView`. Changelog: [Internal] Reviewed By: lenaic Differential Revision: D93381797 fbshipit-source-id: 9988ccb4d948118c298570cbdf27f540c3cd8273
1 parent 7e4c994 commit 21ab455

7 files changed

Lines changed: 47 additions & 46 deletions

File tree

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ void ParagraphShadowNode::setTextLayoutManager(
144144
template <typename ParagraphStateT>
145145
void ParagraphShadowNode::updateStateIfNeeded(
146146
const Content& content,
147-
const MeasuredPreparedLayout& layout) {
147+
const MeasuredPreparedTextLayout& layout) {
148148
ensureUnsealed();
149149

150150
auto& state = static_cast<const ParagraphStateT&>(getStateData());
@@ -182,10 +182,10 @@ void ParagraphShadowNode::updateStateIfNeeded(const Content& content) {
182182
textLayoutManager_});
183183
}
184184

185-
MeasuredPreparedLayout* ParagraphShadowNode::findUsableLayout() {
186-
MeasuredPreparedLayout* ret = nullptr;
185+
MeasuredPreparedTextLayout* ParagraphShadowNode::findUsableLayout() {
186+
MeasuredPreparedTextLayout* ret = nullptr;
187187

188-
if constexpr (TextLayoutManagerExtended::supportsPreparedLayout()) {
188+
if constexpr (TextLayoutManagerExtended::supportsPreparedTextLayout()) {
189189
// We consider the layout to be reusable, if our content measurement,
190190
// combined with padding/border (not snapped) exactly corresponds to the
191191
// measurement of the node, before layout rounding. We may not find a
@@ -222,7 +222,7 @@ Size ParagraphShadowNode::rawContentSize() {
222222
Size ParagraphShadowNode::measureContent(
223223
const LayoutContext& layoutContext,
224224
const LayoutConstraints& layoutConstraints) const {
225-
if constexpr (TextLayoutManagerExtended::supportsPreparedLayout()) {
225+
if constexpr (TextLayoutManagerExtended::supportsPreparedTextLayout()) {
226226
for (const auto& layout : measuredLayouts_) {
227227
if (layout.layoutConstraints == layoutConstraints) {
228228
return layout.measurement.size;
@@ -238,7 +238,7 @@ Size ParagraphShadowNode::measureContent(
238238
.surfaceId = getSurfaceId(),
239239
};
240240

241-
if constexpr (TextLayoutManagerExtended::supportsPreparedLayout()) {
241+
if constexpr (TextLayoutManagerExtended::supportsPreparedTextLayout()) {
242242
if (ReactNativeFeatureFlags::enablePreparedTextLayout()) {
243243
TextLayoutManagerExtended tme(*textLayoutManager_);
244244

@@ -251,12 +251,12 @@ Size ParagraphShadowNode::measureContent(
251251
preparedLayout, textLayoutContext, layoutConstraints);
252252

253253
measuredLayouts_.push_back(
254-
MeasuredPreparedLayout{
254+
MeasuredPreparedTextLayout{
255255
.layoutConstraints = layoutConstraints,
256256
.measurement = measurement,
257-
// PreparedLayout is not trivially copyable on all platforms
257+
// PreparedTextLayout is not trivially copyable on all platforms
258258
// NOLINTNEXTLINE(performance-move-const-arg)
259-
.preparedLayout = std::move(preparedLayout)});
259+
.preparedTextLayout = std::move(preparedLayout)});
260260
assert_valid_size(measurement.size, layoutConstraints);
261261
return measurement.size;
262262
}
@@ -316,7 +316,7 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
316316
auto measuredLayout = findUsableLayout();
317317

318318
if constexpr (
319-
TextLayoutManagerExtended::supportsPreparedLayout() &&
319+
TextLayoutManagerExtended::supportsPreparedTextLayout() &&
320320
std::is_constructible_v<
321321
ParagraphState,
322322
decltype(content.attributedString),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ParagraphShadowNode final
106106
* `TextLayoutManager`) if needed.
107107
*/
108108
template <typename ParagraphStateT>
109-
void updateStateIfNeeded(const Content &content, const MeasuredPreparedLayout &layout);
109+
void updateStateIfNeeded(const Content &content, const MeasuredPreparedTextLayout &layout);
110110

111111
/*
112112
* Creates a `State` object (with `AttributedText` and
@@ -118,7 +118,7 @@ class ParagraphShadowNode final
118118
* Returns any previously prepared layout, generated for measurement, which
119119
* may be used, given the currently assigned layout to the ShadowNode
120120
*/
121-
MeasuredPreparedLayout *findUsableLayout();
121+
MeasuredPreparedTextLayout *findUsableLayout();
122122

123123
/**
124124
* Returns the final measure of the content frame, before layout rounding
@@ -136,7 +136,7 @@ class ParagraphShadowNode final
136136
* Intermediate layout results generated during measurement, that may be
137137
* reused by the platform.
138138
*/
139-
mutable std::vector<MeasuredPreparedLayout> measuredLayouts_;
139+
mutable std::vector<MeasuredPreparedTextLayout> measuredLayouts_;
140140
};
141141

142142
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ MapBuffer ParagraphState::getMapBuffer() const {
2525
}
2626

2727
jni::local_ref<jobject> ParagraphState::getJNIReference() const {
28-
return jni::make_local(measuredLayout.preparedLayout.get());
28+
return jni::make_local(measuredLayout.preparedTextLayout.get());
2929
}
3030

3131
} // namespace facebook::react

packages/react-native/ReactCommon/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ class ParagraphState final {
5555
/**
5656
* A fully prepared representation of a text layout to mount
5757
*/
58-
MeasuredPreparedLayout measuredLayout;
58+
MeasuredPreparedTextLayout measuredLayout;
5959

6060
ParagraphState(
6161
AttributedString attributedString,
6262
ParagraphAttributes paragraphAttributes,
6363
std::weak_ptr<const TextLayoutManager> layoutManager,
64-
MeasuredPreparedLayout measuredLayout)
64+
MeasuredPreparedTextLayout measuredLayout)
6565
: attributedString(std::move(attributedString)),
6666
paragraphAttributes(std::move(paragraphAttributes)),
6767
layoutManager(std::move(layoutManager)),

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@
1919
namespace facebook::react {
2020

2121
template <typename TextLayoutManagerT>
22-
concept TextLayoutManagerWithPreparedLayout = requires(
22+
concept TextLayoutManagerWithPreparedTextLayout = requires(
2323
TextLayoutManagerT textLayoutManager,
2424
AttributedString attributedString,
2525
ParagraphAttributes paragraphAttributes,
2626
TextLayoutContext layoutContext,
2727
LayoutConstraints layoutConstraints,
28-
typename TextLayoutManagerT::PreparedLayout preparedLayout) {
29-
sizeof(typename TextLayoutManagerT::PreparedLayout);
28+
typename TextLayoutManagerT::PreparedTextLayout preparedTextLayout) {
29+
sizeof(typename TextLayoutManagerT::PreparedTextLayout);
3030
{
3131
textLayoutManager.prepareLayout(attributedString, paragraphAttributes, layoutContext, layoutConstraints)
32-
} -> std::same_as<typename TextLayoutManagerT::PreparedLayout>;
32+
} -> std::same_as<typename TextLayoutManagerT::PreparedTextLayout>;
3333
{
34-
textLayoutManager.measurePreparedLayout(preparedLayout, layoutContext, layoutConstraints)
34+
textLayoutManager.measurePreparedLayout(preparedTextLayout, layoutContext, layoutConstraints)
3535
} -> std::same_as<TextMeasurement>;
3636
};
3737

3838
namespace detail {
3939
template <typename T>
40-
struct PreparedLayoutT {
40+
struct PreparedTextLayoutT {
4141
using type = std::nullptr_t;
4242
};
4343

44-
template <TextLayoutManagerWithPreparedLayout T>
45-
struct PreparedLayoutT<T> {
46-
using type = typename T::PreparedLayout;
44+
template <TextLayoutManagerWithPreparedTextLayout T>
45+
struct PreparedTextLayoutT<T> {
46+
using type = typename T::PreparedTextLayout;
4747
};
4848

4949
/**
@@ -64,12 +64,12 @@ class TextLayoutManagerExtended {
6464
};
6565
}
6666

67-
static constexpr bool supportsPreparedLayout()
67+
static constexpr bool supportsPreparedTextLayout()
6868
{
69-
return TextLayoutManagerWithPreparedLayout<TextLayoutManagerT>;
69+
return TextLayoutManagerWithPreparedTextLayout<TextLayoutManagerT>;
7070
}
7171

72-
using PreparedLayout = typename PreparedLayoutT<TextLayoutManagerT>::type;
72+
using PreparedTextLayout = typename PreparedTextLayoutT<TextLayoutManagerT>::type;
7373

7474
TextLayoutManagerExtended(const TextLayoutManagerT &textLayoutManager) : textLayoutManager_(textLayoutManager) {}
7575

@@ -84,24 +84,24 @@ class TextLayoutManagerExtended {
8484
LOG(FATAL) << "Platform TextLayoutManager does not support measureLines";
8585
}
8686

87-
PreparedLayout prepareLayout(
87+
PreparedTextLayout prepareLayout(
8888
const AttributedString &attributedString,
8989
const ParagraphAttributes &paragraphAttributes,
9090
const TextLayoutContext &layoutContext,
9191
const LayoutConstraints &layoutConstraints) const
9292
{
93-
if constexpr (supportsPreparedLayout()) {
93+
if constexpr (supportsPreparedTextLayout()) {
9494
return textLayoutManager_.prepareLayout(attributedString, paragraphAttributes, layoutContext, layoutConstraints);
9595
}
9696
LOG(FATAL) << "Platform TextLayoutManager does not support prepareLayout";
9797
}
9898

9999
TextMeasurement measurePreparedLayout(
100-
const PreparedLayout &layout,
100+
const PreparedTextLayout &layout,
101101
const TextLayoutContext &layoutContext,
102102
const LayoutConstraints &layoutConstraints) const
103103
{
104-
if constexpr (supportsPreparedLayout()) {
104+
if constexpr (supportsPreparedTextLayout()) {
105105
return textLayoutManager_.measurePreparedLayout(layout, layoutContext, layoutConstraints);
106106
}
107107
LOG(FATAL) << "Platform TextLayoutManager does not support measurePreparedLayout";
@@ -114,10 +114,10 @@ class TextLayoutManagerExtended {
114114

115115
using TextLayoutManagerExtended = detail::TextLayoutManagerExtended<TextLayoutManager>;
116116

117-
struct MeasuredPreparedLayout {
117+
struct MeasuredPreparedTextLayout {
118118
LayoutConstraints layoutConstraints;
119119
TextMeasurement measurement;
120-
TextLayoutManagerExtended::PreparedLayout preparedLayout{};
120+
TextLayoutManagerExtended::PreparedTextLayout preparedTextLayout{};
121121
};
122122

123123
} // namespace facebook::react

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
namespace facebook::react {
2424

2525
static_assert(TextLayoutManagerExtended::supportsLineMeasurement());
26-
static_assert(TextLayoutManagerExtended::supportsPreparedLayout());
26+
static_assert(TextLayoutManagerExtended::supportsPreparedTextLayout());
2727

2828
namespace {
2929

@@ -296,7 +296,7 @@ LinesMeasurements TextLayoutManager::measureLines(
296296
std::move(doMeasureLines));
297297
}
298298

299-
TextLayoutManager::PreparedLayout TextLayoutManager::prepareLayout(
299+
TextLayoutManager::PreparedTextLayout TextLayoutManager::prepareLayout(
300300
const AttributedString& attributedString,
301301
const ParagraphAttributes& paragraphAttributes,
302302
const TextLayoutContext& layoutContext,
@@ -333,7 +333,7 @@ TextLayoutManager::PreparedLayout TextLayoutManager::prepareLayout(
333333
auto minimumSize = layoutConstraints.minimumSize;
334334
auto maximumSize = layoutConstraints.maximumSize;
335335

336-
return PreparedLayout{jni::make_global(prepareTextLayout(
336+
return PreparedTextLayout{jni::make_global(prepareTextLayout(
337337
fabricUIManager,
338338
layoutContext.surfaceId,
339339
attributedStringMB.get(),
@@ -371,15 +371,16 @@ TextLayoutManager::PreparedLayout TextLayoutManager::prepareLayout(
371371

372372
const auto& fabricUIManager =
373373
contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager");
374-
return PreparedLayout{jni::make_global(reusePreparedLayoutWithNewReactTags(
375-
fabricUIManager, preparedText->get(), javaReactTags.get()))};
374+
return PreparedTextLayout{
375+
jni::make_global(reusePreparedLayoutWithNewReactTags(
376+
fabricUIManager, preparedText->get(), javaReactTags.get()))};
376377
} else {
377-
return PreparedLayout{*preparedText};
378+
return PreparedTextLayout{*preparedText};
378379
}
379380
}
380381

381382
TextMeasurement TextLayoutManager::measurePreparedLayout(
382-
const PreparedLayout& preparedLayout,
383+
const PreparedTextLayout& preparedLayout,
383384
const TextLayoutContext& /*layoutContext*/,
384385
const LayoutConstraints& layoutConstraints) const {
385386
const auto& fabricUIManager =

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class TextLayoutManager;
2929
*/
3030
class TextLayoutManager {
3131
public:
32-
using PreparedLayout = SafeReleaseJniRef<jni::global_ref<JPreparedLayout>>;
32+
using PreparedTextLayout = SafeReleaseJniRef<jni::global_ref<JPreparedLayout>>;
3333

3434
TextLayoutManager(const std::shared_ptr<const ContextContainer> &contextContainer);
3535

@@ -77,25 +77,25 @@ class TextLayoutManager {
7777
* Create a platform representation of fully laid out text, to later be
7878
* reused.
7979
*/
80-
PreparedLayout prepareLayout(
80+
PreparedTextLayout prepareLayout(
8181
const AttributedString &attributedString,
8282
const ParagraphAttributes &paragraphAttributes,
8383
const TextLayoutContext &layoutContext,
8484
const LayoutConstraints &layoutConstraints) const;
8585

8686
/**
87-
* Derive text and attachment measurements from a PreparedLayout.
87+
* Derive text and attachment measurements from a PreparedTextLayout.
8888
*/
8989
TextMeasurement measurePreparedLayout(
90-
const PreparedLayout &layout,
90+
const PreparedTextLayout &layout,
9191
const TextLayoutContext &layoutContext,
9292
const LayoutConstraints &layoutConstraints) const;
9393

9494
private:
9595
std::shared_ptr<const ContextContainer> contextContainer_;
9696
TextMeasureCache textMeasureCache_;
9797
LineMeasureCache lineMeasureCache_;
98-
SimpleThreadSafeCache<PreparedTextCacheKey, PreparedLayout, -1 /* Set dynamically*/> preparedTextCache_;
98+
SimpleThreadSafeCache<PreparedTextCacheKey, PreparedTextLayout, -1 /* Set dynamically*/> preparedTextCache_;
9999
};
100100

101101
} // namespace facebook::react

0 commit comments

Comments
 (0)