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 @@ -403,7 +403,8 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)

static NSMutableAttributedString *RCTNSAttributedStringFragmentFromFragment(
const AttributedString::Fragment &fragment,
UIImage *placeholderImage)
UIImage *placeholderImage,
NSData *_Nullable eventEmitterWrapper)
{
if (fragment.isAttachment()) {
auto layoutMetrics = fragment.parentShadowView.layoutMetrics;
Expand All @@ -427,21 +428,28 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
string = RCTNSStringFromStringApplyingTextTransform(string, textTransform);
}

return [[NSMutableAttributedString alloc]
initWithString:string
attributes:RCTNSTextAttributesFromTextAttributes(fragment.textAttributes)];
// Set with the initial attributes; adding it afterwards would re-split the runs.
NSMutableDictionary<NSAttributedStringKey, id> *attributes =
RCTNSTextAttributesFromTextAttributes(fragment.textAttributes);
if (eventEmitterWrapper != nil) {
attributes[RCTAttributedStringEventEmitterKey] = eventEmitterWrapper;
}

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

static NSMutableAttributedString *RCTNSAttributedStringFragmentWithAttributesFromFragment(
const AttributedString::Fragment &fragment,
UIImage *placeholderImage)
{
auto nsAttributedStringFragment = RCTNSAttributedStringFragmentFromFragment(fragment, placeholderImage);
NSData *eventEmitterWrapper =
fragment.parentShadowView.componentHandle ? RCTWrapEventEmitter(fragment.parentShadowView.eventEmitter) : nil;

if (fragment.parentShadowView.componentHandle) {
auto eventEmitterWrapper = RCTWrapEventEmitter(fragment.parentShadowView.eventEmitter);
auto nsAttributedStringFragment =
RCTNSAttributedStringFragmentFromFragment(fragment, placeholderImage, eventEmitterWrapper);

if (fragment.isAttachment() && eventEmitterWrapper != nil) {
NSDictionary<NSAttributedStringKey, id> *additionalTextAttributes =
@{RCTAttributedStringEventEmitterKey : eventEmitterWrapper};

Expand All @@ -464,7 +472,7 @@ void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)

[nsAttributedString beginEditing];

for (auto fragment : attributedString.getFragments()) {
for (const auto &fragment : attributedString.getFragments()) {
NSMutableAttributedString *nsAttributedStringFragment =
RCTNSAttributedStringFragmentWithAttributesFromFragment(fragment, placeholderImage);

Expand Down
Loading