mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-06 04:32:06 +00:00
Fix ASTextNode2 is accessing backgroundColor off main while sizing / layout is happening (#794)
This commit is contained in:
parent
5ea4d51596
commit
600b6cb76d
@ -232,7 +232,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
|||||||
[self _ensureTruncationText];
|
[self _ensureTruncationText];
|
||||||
|
|
||||||
NSMutableAttributedString *mutableText = [attributedText mutableCopy];
|
NSMutableAttributedString *mutableText = [attributedText mutableCopy];
|
||||||
[self prepareAttributedStringForDrawing:mutableText];
|
[self prepareAttributedString:mutableText];
|
||||||
ASTextLayout *layout = [ASTextNode2 compatibleLayoutWithContainer:container text:mutableText];
|
ASTextLayout *layout = [ASTextNode2 compatibleLayoutWithContainer:container text:mutableText];
|
||||||
|
|
||||||
[self setNeedsDisplay];
|
[self setNeedsDisplay];
|
||||||
@ -319,7 +319,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
|||||||
return _textContainer.exclusionPaths;
|
return _textContainer.exclusionPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)prepareAttributedStringForDrawing:(NSMutableAttributedString *)attributedString
|
- (void)prepareAttributedString:(NSMutableAttributedString *)attributedString
|
||||||
{
|
{
|
||||||
ASDN::MutexLocker lock(__instanceLock__);
|
ASDN::MutexLocker lock(__instanceLock__);
|
||||||
|
|
||||||
@ -334,12 +334,6 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
|||||||
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
|
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range];
|
||||||
}];
|
}];
|
||||||
|
|
||||||
// Apply background color if needed
|
|
||||||
UIColor *backgroundColor = self.backgroundColor;
|
|
||||||
if (CGColorGetAlpha(backgroundColor.CGColor) > 0) {
|
|
||||||
[attributedString addAttribute:NSBackgroundColorAttributeName value:backgroundColor range:NSMakeRange(0, attributedString.length)];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply shadow if needed
|
// Apply shadow if needed
|
||||||
if (_shadowOpacity > 0 && (_shadowRadius != 0 || !CGSizeEqualToSize(_shadowOffset, CGSizeZero)) && CGColorGetAlpha(_shadowColor) > 0) {
|
if (_shadowOpacity > 0 && (_shadowRadius != 0 || !CGSizeEqualToSize(_shadowOffset, CGSizeZero)) && CGColorGetAlpha(_shadowColor) > 0) {
|
||||||
NSShadow *shadow = [[NSShadow alloc] init];
|
NSShadow *shadow = [[NSShadow alloc] init];
|
||||||
@ -362,11 +356,19 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
|
|||||||
ASTextContainer *copiedContainer = [_textContainer copy];
|
ASTextContainer *copiedContainer = [_textContainer copy];
|
||||||
copiedContainer.size = self.bounds.size;
|
copiedContainer.size = self.bounds.size;
|
||||||
NSMutableAttributedString *mutableText = [self.attributedText mutableCopy] ?: [[NSMutableAttributedString alloc] init];
|
NSMutableAttributedString *mutableText = [self.attributedText mutableCopy] ?: [[NSMutableAttributedString alloc] init];
|
||||||
[self prepareAttributedStringForDrawing:mutableText];
|
|
||||||
|
[self prepareAttributedString:mutableText];
|
||||||
|
|
||||||
|
// Apply background color if needed before drawing. To access the backgroundColor we need to be on the main thread
|
||||||
|
UIColor *backgroundColor = self.backgroundColor;
|
||||||
|
if (CGColorGetAlpha(backgroundColor.CGColor) > 0) {
|
||||||
|
[mutableText addAttribute:NSBackgroundColorAttributeName value:backgroundColor range:NSMakeRange(0, mutableText.length)];
|
||||||
|
}
|
||||||
|
|
||||||
return @{
|
return @{
|
||||||
@"container": copiedContainer,
|
@"container": copiedContainer,
|
||||||
@"text": mutableText
|
@"text": mutableText
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user