mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-22 19:13:55 +08:00
Merge pull request #593 from shannonma/merge_fork
Fixes for ASTextNode test, setNeedsDisplay and font loading failures
This commit is contained in:
@@ -64,6 +64,22 @@ void ASDisplayNodePerformBlockOnMainThread(void (^block)())
|
||||
}
|
||||
}
|
||||
|
||||
void ASDisplayNodeRespectThreadAffinityOfNode(ASDisplayNode *node, void (^block)())
|
||||
{
|
||||
ASDisplayNodeCAssertNotNil(block, @"block is required");
|
||||
if (!block) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.nodeLoaded) {
|
||||
ASDisplayNodePerformBlockOnMainThread(^{
|
||||
block();
|
||||
});
|
||||
} else {
|
||||
block();
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
if (self == [ASDisplayNode class]) {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#import <AsyncDisplayKit/_ASDisplayLayer.h>
|
||||
#import <AsyncDisplayKit/ASAssert.h>
|
||||
#import <AsyncDisplayKit/ASDisplayNode+Subclasses.h>
|
||||
#import <AsyncDisplayKit/ASDisplayNodeInternal.h>
|
||||
#import <AsyncDisplayKit/ASHighlightOverlayLayer.h>
|
||||
#import <AsyncDisplayKit/ASTextNodeCoreTextAdditions.h>
|
||||
#import <AsyncDisplayKit/ASTextNodeTextKitHelpers.h>
|
||||
@@ -202,7 +203,9 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
|
||||
_constrainedSize = constrainedSizeForText;
|
||||
[self _invalidateRenderer];
|
||||
[self setNeedsDisplay];
|
||||
ASDisplayNodeRespectThreadAffinityOfNode(self, ^{
|
||||
[self setNeedsDisplay];
|
||||
});
|
||||
CGSize rendererSize = [[self _renderer] size];
|
||||
|
||||
// Add shadow padding back
|
||||
@@ -337,19 +340,21 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
// We need an entirely new renderer
|
||||
[self _invalidateRenderer];
|
||||
|
||||
// Tell the display node superclasses that the cached layout is incorrect now
|
||||
[self invalidateCalculatedLayout];
|
||||
ASDisplayNodeRespectThreadAffinityOfNode(self, ^{
|
||||
// Tell the display node superclasses that the cached layout is incorrect now
|
||||
[self invalidateCalculatedLayout];
|
||||
|
||||
[self setNeedsDisplay];
|
||||
[self setNeedsDisplay];
|
||||
|
||||
self.accessibilityLabel = _attributedString.string;
|
||||
self.accessibilityLabel = _attributedString.string;
|
||||
|
||||
if (_attributedString.length == 0) {
|
||||
// We're not an accessibility element by default if there is no string.
|
||||
self.isAccessibilityElement = NO;
|
||||
} else {
|
||||
self.isAccessibilityElement = YES;
|
||||
}
|
||||
if (_attributedString.length == 0) {
|
||||
// We're not an accessibility element by default if there is no string.
|
||||
self.isAccessibilityElement = NO;
|
||||
} else {
|
||||
self.isAccessibilityElement = YES;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#pragma mark - Text Layout
|
||||
@@ -360,7 +365,9 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
_exclusionPaths = exclusionPaths;
|
||||
[self _invalidateRenderer];
|
||||
[self invalidateCalculatedLayout];
|
||||
[self setNeedsDisplay];
|
||||
ASDisplayNodeRespectThreadAffinityOfNode(self, ^{
|
||||
[self setNeedsDisplay];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -897,7 +904,9 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
}
|
||||
_shadowColor = shadowColor;
|
||||
[self _invalidateShadower];
|
||||
[self setNeedsDisplay];
|
||||
ASDisplayNodeRespectThreadAffinityOfNode(self, ^{
|
||||
[self setNeedsDisplay];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -911,7 +920,9 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
if (!CGSizeEqualToSize(_shadowOffset, shadowOffset)) {
|
||||
_shadowOffset = shadowOffset;
|
||||
[self _invalidateShadower];
|
||||
[self setNeedsDisplay];
|
||||
ASDisplayNodeRespectThreadAffinityOfNode(self, ^{
|
||||
[self setNeedsDisplay];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -925,7 +936,9 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
if (_shadowOpacity != shadowOpacity) {
|
||||
_shadowOpacity = shadowOpacity;
|
||||
[self _invalidateShadower];
|
||||
[self setNeedsDisplay];
|
||||
ASDisplayNodeRespectThreadAffinityOfNode(self, ^{
|
||||
[self setNeedsDisplay];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -939,7 +952,9 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
if (_shadowRadius != shadowRadius) {
|
||||
_shadowRadius = shadowRadius;
|
||||
[self _invalidateShadower];
|
||||
[self setNeedsDisplay];
|
||||
ASDisplayNodeRespectThreadAffinityOfNode(self, ^{
|
||||
[self setNeedsDisplay];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -981,7 +996,9 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
if (_truncationMode != truncationMode) {
|
||||
_truncationMode = truncationMode;
|
||||
[self _invalidateRenderer];
|
||||
[self setNeedsDisplay];
|
||||
ASDisplayNodeRespectThreadAffinityOfNode(self, ^{
|
||||
[self setNeedsDisplay];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -994,8 +1011,10 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
{
|
||||
if (_maximumLineCount != maximumLineCount) {
|
||||
_maximumLineCount = maximumLineCount;
|
||||
[self _invalidateRenderer];
|
||||
[self _invalidateRenderer];
|
||||
ASDisplayNodeRespectThreadAffinityOfNode(self, ^{
|
||||
[self setNeedsDisplay];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1010,7 +1029,9 @@ ASDISPLAYNODE_INLINE CGFloat ceilPixelValue(CGFloat f)
|
||||
{
|
||||
_composedTruncationString = [self _prepareTruncationStringForDrawing:[self _composedTruncationString]];
|
||||
[self _invalidateRenderer];
|
||||
[self setNeedsDisplay];
|
||||
ASDisplayNodeRespectThreadAffinityOfNode(self, ^{
|
||||
[self setNeedsDisplay];
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#import <CoreText/CTFont.h>
|
||||
#import <CoreText/CTStringAttributes.h>
|
||||
|
||||
#import "ASAssert.h"
|
||||
|
||||
#pragma mark - Public
|
||||
BOOL ASAttributeWithNameIsUnsupportedCoreTextAttribute(NSString *attributeName)
|
||||
{
|
||||
@@ -65,8 +67,13 @@ NSDictionary *NSAttributedStringAttributesForCoreTextAttributes(NSDictionary *co
|
||||
CTFontRef coreTextFont = (__bridge CTFontRef)coreTextValue;
|
||||
NSString *fontName = (__bridge_transfer NSString *)CTFontCopyPostScriptName(coreTextFont);
|
||||
CGFloat fontSize = CTFontGetSize(coreTextFont);
|
||||
|
||||
cleanAttributes[NSFontAttributeName] = [UIFont fontWithName:fontName size:fontSize];
|
||||
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
|
||||
ASDisplayNodeCAssertNotNil(font, @"unable to load font %@ with size %f", fontName, fontSize);
|
||||
if (font == nil) {
|
||||
// Gracefully fail if we were unable to load the font.
|
||||
font = [UIFont systemFontOfSize:fontSize];
|
||||
}
|
||||
cleanAttributes[NSFontAttributeName] = font;
|
||||
}
|
||||
// kCTKernAttributeName -> NSKernAttributeName
|
||||
else if ([coreTextKey isEqualToString:(NSString *)kCTKernAttributeName]) {
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
BOOL ASDisplayNodeSubclassOverridesSelector(Class subclass, SEL selector);
|
||||
void ASDisplayNodePerformBlockOnMainThread(void (^block)());
|
||||
void ASDisplayNodeRespectThreadAffinityOfNode(ASDisplayNode *node, void (^block)());
|
||||
|
||||
typedef NS_OPTIONS(NSUInteger, ASDisplayNodeMethodOverrides) {
|
||||
ASDisplayNodeMethodOverrideNone = 0,
|
||||
|
||||
Reference in New Issue
Block a user