Skip to content
Open
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 @@ -405,6 +405,9 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
const AttributedString::Fragment &fragment,
UIImage *placeholderImage)
{
NSString *string;
NSMutableDictionary<NSAttributedStringKey, id> *attributes;

if (fragment.isAttachment()) {
auto layoutMetrics = fragment.parentShadowView.layoutMetrics;
CGRect bounds = {
Expand All @@ -415,41 +418,28 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
attachment.image = placeholderImage;
attachment.bounds = bounds;

return [[NSMutableAttributedString attributedStringWithAttachment:attachment] mutableCopy];
string = [NSString stringWithFormat:@"%C", (unichar)NSAttachmentCharacter];
attributes = [NSMutableDictionary dictionaryWithObject:attachment forKey:NSAttachmentAttributeName];
} else {
NSString *decoded = [[NSString alloc] initWithBytes:fragment.string.data()
length:fragment.string.size()
encoding:NSUTF8StringEncoding];
NSString *string = decoded != nil ? decoded : @"";
string = decoded != nil ? decoded : @"";

if (fragment.textAttributes.textTransform.has_value()) {
auto textTransform = fragment.textAttributes.textTransform.value();
string = RCTNSStringFromStringApplyingTextTransform(string, textTransform);
}

return [[NSMutableAttributedString alloc]
initWithString:string
attributes:RCTNSTextAttributesFromTextAttributes(fragment.textAttributes)];
attributes = RCTNSTextAttributesFromTextAttributes(fragment.textAttributes);
}
}

static NSMutableAttributedString *RCTNSAttributedStringFragmentWithAttributesFromFragment(
const AttributedString::Fragment &fragment,
UIImage *placeholderImage)
{
auto nsAttributedStringFragment = RCTNSAttributedStringFragmentFromFragment(fragment, placeholderImage);

// Set with the initial attributes; adding it afterwards would re-split the runs.
if (fragment.parentShadowView.componentHandle) {
auto eventEmitterWrapper = RCTWrapEventEmitter(fragment.parentShadowView.eventEmitter);

NSDictionary<NSAttributedStringKey, id> *additionalTextAttributes =
@{RCTAttributedStringEventEmitterKey : eventEmitterWrapper};

[nsAttributedStringFragment addAttributes:additionalTextAttributes
range:NSMakeRange(0, nsAttributedStringFragment.length)];
attributes[RCTAttributedStringEventEmitterKey] = RCTWrapEventEmitter(fragment.parentShadowView.eventEmitter);
}

return nsAttributedStringFragment;
return [[NSMutableAttributedString alloc] initWithString:string attributes:attributes];
}

NSAttributedString *RCTNSAttributedStringFromAttributedString(const AttributedString &attributedString)
Expand All @@ -464,9 +454,9 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)

[nsAttributedString beginEditing];

for (auto fragment : attributedString.getFragments()) {
for (const auto &fragment : attributedString.getFragments()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

NSMutableAttributedString *nsAttributedStringFragment =
RCTNSAttributedStringFragmentWithAttributesFromFragment(fragment, placeholderImage);
RCTNSAttributedStringFragmentFromFragment(fragment, placeholderImage);

[nsAttributedString appendAttributedString:nsAttributedStringFragment];
}
Expand Down
Loading