Correct linePositionModifier behavior (#1192)

This commit is contained in:
Michael Schneider 2018-10-26 07:43:22 -07:00 committed by GitHub
parent 8382edd7ef
commit 25a3d331ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 15 deletions

View File

@ -65,6 +65,7 @@
- Add NSLocking conformance to ASNodeController [Michael Schneider](https://github.com/maicki)[#1179] (https://github.com/TextureGroup/Texture/pull/1179) - Add NSLocking conformance to ASNodeController [Michael Schneider](https://github.com/maicki)[#1179] (https://github.com/TextureGroup/Texture/pull/1179)
- Dont handle touches on additional attributed message if passthrough is enabled [Michael Schneider](https://github.com/maicki)[#1184] (https://github.com/TextureGroup/Texture/pull/1184) - Dont handle touches on additional attributed message if passthrough is enabled [Michael Schneider](https://github.com/maicki)[#1184] (https://github.com/TextureGroup/Texture/pull/1184)
- Yoga integration improvements [Michael Schneider](https://github.com/maicki)[#1187] (https://github.com/TextureGroup/Texture/pull/1187) - Yoga integration improvements [Michael Schneider](https://github.com/maicki)[#1187] (https://github.com/TextureGroup/Texture/pull/1187)
- Correct linePositionModifier behavior [Michael Schneider](https://github.com/maicki)[#1192] (https://github.com/TextureGroup/Texture/pull/1192)
## 2.7 ## 2.7
- Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877) - Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877)

View File

@ -217,6 +217,15 @@ NS_ASSUME_NONNULL_BEGIN
@end @end
/**
* @abstract Text node unsupported properties
*/
@interface ASTextNode (Unsupported)
@property (nullable, nonatomic) id textContainerLinePositionModifier;
@end
/** /**
* @abstract Text node deprecated properties * @abstract Text node deprecated properties
*/ */

View File

@ -1389,6 +1389,21 @@ static NSAttributedString *DefaultTruncationAttributedString()
@end @end
@implementation ASTextNode (Unsupported)
- (void)setTextContainerLinePositionModifier:(id)textContainerLinePositionModifier
{
AS_TEXT_ALERT_UNIMPLEMENTED_FEATURE();
}
- (id)textContainerLinePositionModifier
{
AS_TEXT_ALERT_UNIMPLEMENTED_FEATURE();
return nil;
}
@end
@implementation ASTextNode (Deprecated) @implementation ASTextNode (Deprecated)
- (void)setAttributedString:(NSAttributedString *)attributedString - (void)setAttributedString:(NSAttributedString *)attributedString

View File

@ -9,6 +9,8 @@
#import <AsyncDisplayKit/ASControlNode.h> #import <AsyncDisplayKit/ASControlNode.h>
#import <AsyncDisplayKit/ASTextNodeCommon.h> #import <AsyncDisplayKit/ASTextNodeCommon.h>
@protocol ASTextLinePositionModifier;
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
/** /**
@ -207,6 +209,10 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)enableDebugging; + (void)enableDebugging;
#pragma mark - Layout and Sizing
@property (nullable, nonatomic) id<ASTextLinePositionModifier> textContainerLinePositionModifier;
@end @end
@interface ASTextNode2 (Unavailable) @interface ASTextNode2 (Unavailable)

View File

@ -318,6 +318,17 @@ static NSArray *DefaultLinkAttributeNames = @[ NSLinkAttributeName ];
return _textContainer.insets; return _textContainer.insets;
} }
- (void)setTextContainerLinePositionModifier:(id<ASTextLinePositionModifier>)modifier
{
ASLockedSelfCompareAssignObjects(_textContainer.linePositionModifier, modifier);
}
- (id<ASTextLinePositionModifier>)textContainerLinePositionModifier
{
ASLockScopeSelf();
return _textContainer.linePositionModifier;
}
- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize - (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{ {
ASDisplayNodeAssert(constrainedSize.width >= 0, @"Constrained width for text (%f) is too narrow", constrainedSize.width); ASDisplayNodeAssert(constrainedSize.width >= 0, @"Constrained width for text (%f) is too narrow", constrainedSize.width);

View File

@ -102,6 +102,13 @@ static CGColorRef ASTextGetCGColor(CGColorRef color) {
id<ASTextLinePositionModifier> _linePositionModifier; id<ASTextLinePositionModifier> _linePositionModifier;
} }
- (NSString *)description
{
return [NSString
stringWithFormat:@"immutable: %@, insets: %@, size: %@", self->_readonly ? @"YES" : @"NO",
NSStringFromUIEdgeInsets(self->_insets), NSStringFromCGSize(self->_size)];
}
+ (instancetype)containerWithSize:(CGSize)size NS_RETURNS_RETAINED { + (instancetype)containerWithSize:(CGSize)size NS_RETURNS_RETAINED {
return [self containerWithSize:size insets:UIEdgeInsetsZero]; return [self containerWithSize:size insets:UIEdgeInsetsZero];
} }
@ -373,6 +380,14 @@ dispatch_semaphore_signal(_lock);
return self; return self;
} }
- (NSString *)description
{
return [NSString stringWithFormat:@"lines: %ld, visibleRange:%@, textBoundingRect:%@",
[self.lines count],
NSStringFromRange(self.visibleRange),
NSStringFromCGRect(self.textBoundingRect)];
}
+ (ASTextLayout *)layoutWithContainerSize:(CGSize)size text:(NSAttributedString *)text { + (ASTextLayout *)layoutWithContainerSize:(CGSize)size text:(NSAttributedString *)text {
ASTextContainer *container = [ASTextContainer containerWithSize:size]; ASTextContainer *container = [ASTextContainer containerWithSize:size];
return [self layoutWithContainer:container text:text]; return [self layoutWithContainer:container text:text];
@ -599,15 +614,24 @@ dispatch_semaphore_signal(_lock);
position.y = cgPathBox.size.height + cgPathBox.origin.y - ctLineOrigin.y; position.y = cgPathBox.size.height + cgPathBox.origin.y - ctLineOrigin.y;
ASTextLine *line = [ASTextLine lineWithCTLine:ctLine position:position vertical:isVerticalForm]; ASTextLine *line = [ASTextLine lineWithCTLine:ctLine position:position vertical:isVerticalForm];
[lines addObject:line];
}
// Give user a chance to modify the line's position.
[container.linePositionModifier modifyLines:lines fromText:text inContainer:container];
NSUInteger i = 0;
for (ASTextLine *line in lines) {
CGPoint position = line.position;
CGRect rect = line.bounds; CGRect rect = line.bounds;
if (constraintSizeIsExtended) { if (constraintSizeIsExtended) {
if (isVerticalForm) { if (isVerticalForm) {
if (rect.origin.x + rect.size.width > if (rect.origin.x + rect.size.width >
constraintRectBeforeExtended.origin.x + constraintRectBeforeExtended.origin.x +
constraintRectBeforeExtended.size.width) { constraintRectBeforeExtended.size.width) {
measuringBeyondConstraints = YES; measuringBeyondConstraints = YES;
}; }
} else { } else {
if (rect.origin.y + rect.size.height > if (rect.origin.y + rect.size.height >
constraintRectBeforeExtended.origin.y + constraintRectBeforeExtended.origin.y +
@ -640,11 +664,11 @@ dispatch_semaphore_signal(_lock);
line.index = lineCurrentIdx; line.index = lineCurrentIdx;
line.row = rowIdx; line.row = rowIdx;
[lines addObject:line];
rowCount = rowIdx + 1; rowCount = rowIdx + 1;
lineCurrentIdx ++; lineCurrentIdx ++;
if (i == 0) { if (i++ == 0) {
textBoundingRect = rect; textBoundingRect = rect;
} else if (!measuringBeyondConstraints) { } else if (!measuringBeyondConstraints) {
if (maximumNumberOfRows == 0 || rowIdx < maximumNumberOfRows) { if (maximumNumberOfRows == 0 || rowIdx < maximumNumberOfRows) {
@ -679,17 +703,6 @@ dispatch_semaphore_signal(_lock);
} }
} }
// Give user a chance to modify the line's position.
if (container.linePositionModifier) {
[container.linePositionModifier modifyLines:lines fromText:text inContainer:container];
textBoundingRect = CGRectZero;
for (NSUInteger i = 0, max = lines.count; i < max; i++) {
ASTextLine *line = lines[i];
if (i == 0) textBoundingRect = line.bounds;
else textBoundingRect = CGRectUnion(textBoundingRect, line.bounds);
}
}
lineRowsEdge = (ASRowEdge *) calloc(rowCount, sizeof(ASRowEdge)); lineRowsEdge = (ASRowEdge *) calloc(rowCount, sizeof(ASRowEdge));
if (lineRowsEdge == NULL) FAIL_AND_RETURN if (lineRowsEdge == NULL) FAIL_AND_RETURN
lineRowsIndex = (NSUInteger *) calloc(rowCount, sizeof(NSUInteger)); lineRowsIndex = (NSUInteger *) calloc(rowCount, sizeof(NSUInteger));