Skip to content

Commit

Permalink
Pass LayoutContext to TextLayoutManager (facebook#40873)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: facebook#40873

Some host platforms may require the LayoutContext for computing the size of text, e.g. to read the pointScaleFactor value. This change passes the LayoutContext to TextLayoutManager so it can be used during text measurement.

Please note, for now, this does not wire any fields from LayoutContext through to the TextMeasureCache, TextLayoutManager::getHostTextStorage, or TextLayoutManager::measureCachedSpannableById  (on Android).

## Changelog:

[General] [Internal]

Reviewed By: NickGerleman

Differential Revision: D50227592

fbshipit-source-id: 6ab19ac6289699bfffddc085f863c4555aec744f
  • Loading branch information
rozele authored and facebook-github-bot committed Oct 13, 2023
1 parent dd10ce0 commit 6d971c8
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace facebook::react {
TextMeasurement ParagraphLayoutManager::measure(
const AttributedString& attributedString,
const ParagraphAttributes& paragraphAttributes,
const LayoutContext& layoutContext,
LayoutConstraints layoutConstraints) const {
if (CoreFeatures::cacheLastTextMeasurement) {
bool shouldMeasure = shouldMeasureString(
Expand All @@ -23,6 +24,7 @@ TextMeasurement ParagraphLayoutManager::measure(
cachedTextMeasurement_ = textLayoutManager_->measure(
AttributedStringBox(attributedString),
paragraphAttributes,
layoutContext,
layoutConstraints,
hostTextStorage_);
lastAvailableWidth_ = layoutConstraints.maximumSize.width;
Expand All @@ -33,6 +35,7 @@ TextMeasurement ParagraphLayoutManager::measure(
return textLayoutManager_->measure(
AttributedStringBox(attributedString),
paragraphAttributes,
layoutContext,
layoutConstraints,
nullptr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <react/renderer/attributedstring/AttributedString.h>
#include <react/renderer/attributedstring/ParagraphAttributes.h>
#include <react/renderer/core/LayoutConstraints.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>

namespace facebook::react {
Expand All @@ -26,6 +27,8 @@ class ParagraphLayoutManager {
TextMeasurement measure(
const AttributedString& attributedString,
const ParagraphAttributes& paragraphAttributes,
const LayoutContext& layoutContext,

LayoutConstraints layoutConstraints) const;

LinesMeasurements measureLines(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ Size ParagraphShadowNode::measureContent(

return getStateData()
.paragraphLayoutManager
.measure(attributedString, content.paragraphAttributes, layoutConstraints)
.measure(
attributedString,
content.paragraphAttributes,
layoutContext,
layoutConstraints)
.size;
}

Expand All @@ -172,7 +176,10 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {
updateStateIfNeeded(content);

auto measurement = getStateData().paragraphLayoutManager.measure(
content.attributedString, content.paragraphAttributes, layoutConstraints);
content.attributedString,
content.paragraphAttributes,
layoutContext,
layoutConstraints);

if (getConcreteProps().onTextLayout) {
auto linesMeasurements = getStateData().paragraphLayoutManager.measureLines(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void AndroidTextInputShadowNode::updateStateIfNeeded() {
#pragma mark - LayoutableShadowNode

Size AndroidTextInputShadowNode::measureContent(
const LayoutContext& /*layoutContext*/,
const LayoutContext& layoutContext,
const LayoutConstraints& layoutConstraints) const {
if (getStateData().cachedAttributedStringId != 0) {
return textLayoutManager_
Expand Down Expand Up @@ -187,6 +187,7 @@ Size AndroidTextInputShadowNode::measureContent(
->measure(
AttributedStringBox{attributedString},
getConcreteProps().paragraphAttributes,
layoutContext,
layoutConstraints,
nullptr)
.size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ Size TextInputShadowNode::measureContent(
->measure(
attributedStringBoxToMeasure(layoutContext),
getConcreteProps().getEffectiveParagraphAttributes(),
layoutContext,
layoutConstraints,
nullptr)
.size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ void* TextLayoutManager::getNativeTextLayoutManager() const {
TextMeasurement TextLayoutManager::measure(
const AttributedStringBox& attributedStringBox,
const ParagraphAttributes& paragraphAttributes,
const LayoutContext& layoutContext,

LayoutConstraints layoutConstraints,
std::shared_ptr<void> /* hostTextStorage */) const {
auto& attributedString = attributedStringBox.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <react/renderer/attributedstring/AttributedString.h>
#include <react/renderer/attributedstring/AttributedStringBox.h>
#include <react/renderer/core/LayoutConstraints.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/textlayoutmanager/TextMeasureCache.h>
#include <react/utils/ContextContainer.h>

Expand Down Expand Up @@ -45,6 +46,7 @@ class TextLayoutManager {
TextMeasurement measure(
const AttributedStringBox& attributedStringBox,
const ParagraphAttributes& paragraphAttributes,
const LayoutContext& layoutContext,
LayoutConstraints layoutConstraints,
std::shared_ptr<void> /* hostTextStorage */) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ void* TextLayoutManager::getNativeTextLayoutManager() const {
TextMeasurement TextLayoutManager::measure(
AttributedStringBox attributedStringBox,
ParagraphAttributes paragraphAttributes,
const LayoutContext& /*layoutContext*/,
LayoutConstraints layoutConstraints,
std::shared_ptr<void>) const {
TextMeasurement::Attachments attachments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <react/renderer/attributedstring/AttributedStringBox.h>
#include <react/renderer/attributedstring/ParagraphAttributes.h>
#include <react/renderer/core/LayoutConstraints.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/textlayoutmanager/TextMeasureCache.h>
#include <react/utils/ContextContainer.h>

Expand All @@ -37,6 +38,7 @@ class TextLayoutManager {
virtual TextMeasurement measure(
AttributedStringBox attributedStringBox,
ParagraphAttributes paragraphAttributes,
const LayoutContext& layoutContext,
LayoutConstraints layoutConstraints,
std::shared_ptr<void>) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <react/renderer/attributedstring/AttributedStringBox.h>
#include <react/renderer/attributedstring/ParagraphAttributes.h>
#include <react/renderer/core/LayoutConstraints.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/textlayoutmanager/TextMeasureCache.h>
#include <react/utils/ContextContainer.h>

Expand All @@ -32,6 +33,7 @@ class TextLayoutManager {
TextMeasurement measure(
AttributedStringBox attributedStringBox,
ParagraphAttributes paragraphAttributes,
const LayoutContext& layoutContext,
LayoutConstraints layoutConstraints,
std::shared_ptr<void> hostTextStorage) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
TextMeasurement TextLayoutManager::measure(
AttributedStringBox attributedStringBox,
ParagraphAttributes paragraphAttributes,
const LayoutContext &layoutContext,
LayoutConstraints layoutConstraints,
std::shared_ptr<void> hostTextStorage) const
{
Expand Down

0 comments on commit 6d971c8

Please sign in to comment.