[ASTextNode2] Fix background color drawing (#831)

* Fix TextNode2 not respecting background color

* ASTextNode2: Use locks and copies right

* Increment changelog

* Make the Dangerfile accept any license header with Pinterest in it
This commit is contained in:
Adlai Holler 2018-03-12 13:42:33 -07:00 committed by GitHub
parent ed6da29057
commit 5cafdb9062
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 17 deletions

View File

@ -34,6 +34,7 @@
- Fix UIResponder handling with view backing ASDisplayNode. [Michael Schneider](https://github.com/maicki) [#789] (https://github.com/TextureGroup/Texture/pull/789/) - Fix UIResponder handling with view backing ASDisplayNode. [Michael Schneider](https://github.com/maicki) [#789] (https://github.com/TextureGroup/Texture/pull/789/)
- Optimized thread-local storage by replacing pthread_specific with C11 thread-local variables. [Adlai Holler](https://github.com/Adlai-Holler) [#811] (https://github.com/TextureGroup/Texture/pull/811/) - Optimized thread-local storage by replacing pthread_specific with C11 thread-local variables. [Adlai Holler](https://github.com/Adlai-Holler) [#811] (https://github.com/TextureGroup/Texture/pull/811/)
- Fixed a thread-sanitizer warning in ASTextNode. [Adlai Holler](https://github.com/Adlai-Holler) [#830] (https://github.com/TextureGroup/Texture/pull/830/) - Fixed a thread-sanitizer warning in ASTextNode. [Adlai Holler](https://github.com/Adlai-Holler) [#830] (https://github.com/TextureGroup/Texture/pull/830/)
- Fix ASTextNode2 handling background color incorrectly. [Adlai Holler](https://github.com/Adlai-Holler) [#831] (https://github.com/TextureGroup/Texture/pull/831/)
## 2.6 ## 2.6
- [Xcode 9] Updated to require Xcode 9 (to fix warnings) [Garrett Moon](https://github.com/garrettmoon) - [Xcode 9] Updated to require Xcode 9 (to fix warnings) [Garrett Moon](https://github.com/garrettmoon)

View File

@ -54,11 +54,7 @@ def check_file_header(files_to_check, licenses)
correct_license = false correct_license = false
licenses.each do |license| licenses.each do |license|
license_header = full_license(license, filename) license_header = full_license(license, filename)
# Hack for https://github.com/TextureGroup/Texture/issues/745 if data.include? "Pinterest, Inc."
# If it's already a "modified-post-Texture" file, leave it with it original copyright year.
if data.include? "Modifications to this file made after 4/13/2017"
correct_license = true
elsif data.start_with?(license_header)
correct_license = true correct_license = true
end end
end end

View File

@ -359,20 +359,17 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
[self prepareAttributedString: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,
}; @"bgColor": self.backgroundColor
};
} }
/** /**
* If it can't find a compatible layout, this method creates one. * If it can't find a compatible layout, this method creates one.
*
* NOTE: Be careful to copy `text` if needed.
*/ */
+ (ASTextLayout *)compatibleLayoutWithContainer:(ASTextContainer *)container + (ASTextLayout *)compatibleLayoutWithContainer:(ASTextContainer *)container
text:(NSAttributedString *)text text:(NSAttributedString *)text
@ -391,7 +388,7 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
cacheValue = [textLayoutCache objectForKey:text]; cacheValue = [textLayoutCache objectForKey:text];
if (cacheValue == nil) { if (cacheValue == nil) {
cacheValue = [[ASTextCacheValue alloc] init]; cacheValue = [[ASTextCacheValue alloc] init];
[textLayoutCache setObject:cacheValue forKey:text]; [textLayoutCache setObject:cacheValue forKey:[text copy]];
} }
cacheValue; cacheValue;
}); });
@ -458,15 +455,25 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
return layout; return layout;
} }
+ (void)drawRect:(CGRect)bounds withParameters:(NSDictionary *)layoutDict isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock isRasterizing:(BOOL)isRasterizing; + (void)drawRect:(CGRect)bounds withParameters:(NSDictionary *)layoutDict isCancelled:(asdisplaynode_iscancelled_block_t)isCancelledBlock isRasterizing:(BOOL)isRasterizing
{ {
ASTextContainer *container = layoutDict[@"container"]; ASTextContainer *container = layoutDict[@"container"];
NSAttributedString *text = layoutDict[@"text"]; NSAttributedString *text = layoutDict[@"text"];
UIColor *bgColor = layoutDict[@"bgColor"];
ASTextLayout *layout = [self compatibleLayoutWithContainer:container text:text]; ASTextLayout *layout = [self compatibleLayoutWithContainer:container text:text];
if (isCancelledBlock()) { if (isCancelledBlock()) {
return; return;
} }
// Fill background color.
// They may have already drawn into this context in the pre-context block
// so unfortunately we have to use the normal blend mode, not copy.
if (CGColorGetAlpha(bgColor.CGColor) > 0) {
[bgColor setFill];
UIRectFillUsingBlendMode(bounds, kCGBlendModeNormal);
}
CGContextRef context = UIGraphicsGetCurrentContext(); CGContextRef context = UIGraphicsGetCurrentContext();
ASDisplayNodeAssert(context, @"This is no good without a context."); ASDisplayNodeAssert(context, @"This is no good without a context.");
@ -941,11 +948,21 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
- (void)setPointSizeScaleFactors:(NSArray<NSNumber *> *)scaleFactors - (void)setPointSizeScaleFactors:(NSArray<NSNumber *> *)scaleFactors
{ {
AS_TEXT_ALERT_UNIMPLEMENTED_FEATURE(); AS_TEXT_ALERT_UNIMPLEMENTED_FEATURE();
_pointSizeScaleFactors = [scaleFactors copy]; {
ASDN::MutexLocker l(__instanceLock__);
if (ASObjectIsEqual(scaleFactors, _pointSizeScaleFactors)) {
return;
}
_pointSizeScaleFactors = [scaleFactors copy];
}
[self setNeedsLayout];
} }
- (NSArray *)pointSizeScaleFactors - (NSArray *)pointSizeScaleFactors
{ {
ASDN::MutexLocker l(__instanceLock__);
return _pointSizeScaleFactors; return _pointSizeScaleFactors;
} }