Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,11 @@ - (void)drawRect:(CGRect)rect
return;
}

auto textLayoutManager = _state->getData().paragraphLayoutManager.getTextLayoutManager();
auto nsTextStorage = _state->getData().paragraphLayoutManager.getHostTextStorage();
auto textLayoutManager = _state->getData().layoutManager.lock();

if (!textLayoutManager) {
return;
}

RCTTextLayoutManager *nativeTextLayoutManager =
(RCTTextLayoutManager *)unwrapManagedObject(textLayoutManager->getNativeTextLayoutManager());
Expand All @@ -133,7 +136,6 @@ - (void)drawRect:(CGRect)rect
[nativeTextLayoutManager drawAttributedString:_state->getData().attributedString
paragraphAttributes:_paragraphAttributes
frame:frame
textStorage:unwrapManagedObject(nsTextStorage)
drawHighlightPath:^(UIBezierPath *highlightPath) {
if (highlightPath) {
if (!self->_highlightLayer) {
Expand Down Expand Up @@ -179,15 +181,18 @@ - (NSArray *)accessibilityElements
auto &data = _state->getData();

if (![_accessibilityProvider isUpToDate:data.attributedString]) {
auto textLayoutManager = data.paragraphLayoutManager.getTextLayoutManager();
RCTTextLayoutManager *nativeTextLayoutManager =
(RCTTextLayoutManager *)unwrapManagedObject(textLayoutManager->getNativeTextLayoutManager());
CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
_accessibilityProvider = [[RCTParagraphComponentAccessibilityProvider alloc] initWithString:data.attributedString
layoutManager:nativeTextLayoutManager
paragraphAttributes:data.paragraphAttributes
frame:frame
view:self];
auto textLayoutManager = data.layoutManager.lock();
if (textLayoutManager) {
RCTTextLayoutManager *nativeTextLayoutManager =
(RCTTextLayoutManager *)unwrapManagedObject(textLayoutManager->getNativeTextLayoutManager());
CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
_accessibilityProvider =
[[RCTParagraphComponentAccessibilityProvider alloc] initWithString:data.attributedString
layoutManager:nativeTextLayoutManager
paragraphAttributes:data.paragraphAttributes
frame:frame
view:self];
}
}

return _accessibilityProvider.accessibilityElements;
Expand All @@ -206,7 +211,11 @@ - (SharedTouchEventEmitter)touchEventEmitterAtPoint:(CGPoint)point
return _eventEmitter;
}

auto textLayoutManager = _state->getData().paragraphLayoutManager.getTextLayoutManager();
auto textLayoutManager = _state->getData().layoutManager.lock();

if (!textLayoutManager) {
return _eventEmitter;
}

RCTTextLayoutManager *nativeTextLayoutManager =
(RCTTextLayoutManager *)unwrapManagedObject(textLayoutManager->getNativeTextLayoutManager());
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,15 @@ Content ParagraphShadowNode::getContentWithMeasuredAttachments(
void ParagraphShadowNode::setTextLayoutManager(
std::shared_ptr<const TextLayoutManager> textLayoutManager) {
ensureUnsealed();
getStateData().paragraphLayoutManager.setTextLayoutManager(
std::move(textLayoutManager));
textLayoutManager_ = std::move(textLayoutManager);
}

void ParagraphShadowNode::updateStateIfNeeded(const Content& content) {
ensureUnsealed();

auto& state = getStateData();

react_native_assert(state.paragraphLayoutManager.getTextLayoutManager());
react_native_assert(textLayoutManager_);

if (state.attributedString == content.attributedString) {
return;
Expand All @@ -128,7 +127,7 @@ void ParagraphShadowNode::updateStateIfNeeded(const Content& content) {
setStateData(ParagraphState{
content.attributedString,
content.paragraphAttributes,
state.paragraphLayoutManager});
textLayoutManager_});
}

#pragma mark - LayoutableShadowNode
Expand All @@ -154,10 +153,9 @@ Size ParagraphShadowNode::measureContent(

TextLayoutContext textLayoutContext{};
textLayoutContext.pointScaleFactor = layoutContext.pointScaleFactor;
return getStateData()
.paragraphLayoutManager
.measure(
attributedString,
return textLayoutManager_
->measure(
AttributedStringBox{attributedString},
content.paragraphAttributes,
textLayoutContext,
layoutConstraints)
Expand All @@ -179,14 +177,14 @@ void ParagraphShadowNode::layout(LayoutContext layoutContext) {

TextLayoutContext textLayoutContext{};
textLayoutContext.pointScaleFactor = layoutContext.pointScaleFactor;
auto measurement = getStateData().paragraphLayoutManager.measure(
content.attributedString,
auto measurement = textLayoutManager_->measure(
AttributedStringBox{content.attributedString},
content.paragraphAttributes,
textLayoutContext,
layoutConstraints);

if (getConcreteProps().onTextLayout) {
auto linesMeasurements = getStateData().paragraphLayoutManager.measureLines(
auto linesMeasurements = textLayoutManager_->measureLines(
content.attributedString,
content.paragraphAttributes,
measurement.size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ class ParagraphShadowNode final : public ConcreteViewShadowNode<
*/
void updateStateIfNeeded(const Content& content);

std::shared_ptr<TextLayoutManager const> textLayoutManager_;

/*
* Cached content of the subtree started from the node.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <react/debug/react_native_assert.h>
#include <react/renderer/attributedstring/AttributedString.h>
#include <react/renderer/attributedstring/ParagraphAttributes.h>
#include <react/renderer/components/text/ParagraphLayoutManager.h>
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>

#ifdef ANDROID
#include <folly/dynamic.h>
Expand All @@ -32,7 +32,8 @@ constexpr static MapBuffer::Key TX_STATE_KEY_MOST_RECENT_EVENT_COUNT = 3;
* State for <Paragraph> component.
* Represents what to render and how to render.
*/
struct ParagraphState {
class ParagraphState final {
public:
/*
* All content of <Paragraph> component represented as an `AttributedString`.
*/
Expand All @@ -45,22 +46,22 @@ struct ParagraphState {
ParagraphAttributes paragraphAttributes;

/*
* `ParagraphLayoutManager` provides a connection to platform-specific
* `TextLayoutManager` provides a connection to platform-specific
* text rendering infrastructure which is capable to render the
* `AttributedString`.
* This is not on every platform. This is not used on Android, but is
* used on the iOS mounting layer.
*/
ParagraphLayoutManager paragraphLayoutManager;
std::weak_ptr<TextLayoutManager const> layoutManager;

#ifdef ANDROID
ParagraphState(
const AttributedString& attributedString,
const ParagraphAttributes& paragraphAttributes,
const ParagraphLayoutManager& paragraphLayoutManager)
AttributedString const& attributedString,
ParagraphAttributes const& paragraphAttributes,
std::weak_ptr<const TextLayoutManager> const& layoutManager)
: attributedString(attributedString),
paragraphAttributes(paragraphAttributes),
paragraphLayoutManager(paragraphLayoutManager) {}
layoutManager(layoutManager) {}
ParagraphState() = default;
ParagraphState(
const ParagraphState& previousState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ Size AndroidTextInputShadowNode::measureContent(
AttributedStringBox{attributedString},
getConcreteProps().paragraphAttributes,
textLayoutContext,
layoutConstraints,
nullptr)
layoutConstraints)
.size;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ Size TextInputShadowNode::measureContent(
attributedStringBoxToMeasure(layoutContext),
getConcreteProps().getEffectiveParagraphAttributes(),
textLayoutContext,
layoutConstraints,
nullptr)
layoutConstraints)
.size;
}

Expand Down
Loading