Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalidate NSTextStorage on AttributedString change #38070

Closed
wants to merge 1 commit into from
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 @@ -42,20 +42,22 @@ bool ParagraphLayoutManager::shoudMeasureString(
AttributedString const &attributedString,
ParagraphAttributes const &paragraphAttributes,
LayoutConstraints layoutConstraints) const {
size_t newHash = folly::hash::hash_combine(
0,
textAttributedStringHashLayoutWise(attributedString),
paragraphAttributes);
size_t newParagraphInputHash =
folly::hash::hash_combine(0, attributedString, paragraphAttributes);

if (newHash != paragraphInputHash_) {
if (newParagraphInputHash != paragraphInputHash_) {
// AttributedString or ParagraphAttributes have changed.
// Must create new host text storage and trigger measure.
hostTextStorage_ = textLayoutManager_->getHostTextStorage(
attributedString, paragraphAttributes, layoutConstraints);
paragraphInputHash_ = newHash;
paragraphInputHash_ = newParagraphInputHash;

return true; // Must measure again.
}

// Detect the case when available width for Paragraph meaningfully changes.
// This is to prevent unnecessary re-creation of NSTextStorage on iOS.
// On Android, this is no-op.
bool hasMaximumSizeChanged =
layoutConstraints.maximumSize.width != lastAvailableWidth_;
Float threshold = 0.01f;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

#include <react/renderer/components/text/BaseTextShadowNode.h>
#include <react/renderer/components/text/ParagraphEventEmitter.h>
#include <react/renderer/components/text/ParagraphLayoutManager.h>
#include <react/renderer/components/text/ParagraphProps.h>
#include <react/renderer/components/text/ParagraphState.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
Expand Down