Skip to content

Commit

Permalink
Correct linePositionModifier behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
maicki committed Oct 25, 2018
1 parent 8382edd commit 990b240
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
- Add NSLocking conformance to ASNodeController [Michael Schneider](https://github.com/maicki)[#1179] (https://github.com/TextureGroup/Texture/pull/1179)
- Don’t 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)
- Correct linePositionModifier behavior [Michael Schneider](https://github.com/maicki)[#1192] (https://github.com/TextureGroup/Texture/pull/1192)

## 2.7
- Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877)
Expand Down
9 changes: 9 additions & 0 deletions Source/ASTextNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ NS_ASSUME_NONNULL_BEGIN

@end

/**
* @abstract Text node unsupported properties
*/
@interface ASTextNode (Unsupported)

@property (nullable, nonatomic) id textContainerLinePositionModifier;

@end

/**
* @abstract Text node deprecated properties
*/
Expand Down
15 changes: 15 additions & 0 deletions Source/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1389,6 +1389,21 @@ + (id)allocWithZone:(struct _NSZone *)zone

@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)

- (void)setAttributedString:(NSAttributedString *)attributedString
Expand Down
6 changes: 6 additions & 0 deletions Source/ASTextNode2.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#import <AsyncDisplayKit/ASControlNode.h>
#import <AsyncDisplayKit/ASTextNodeCommon.h>

@protocol ASTextLinePositionModifier;

NS_ASSUME_NONNULL_BEGIN

/**
Expand Down Expand Up @@ -207,6 +209,10 @@ NS_ASSUME_NONNULL_BEGIN

+ (void)enableDebugging;

#pragma mark - Layout and Sizing

@property (nullable, nonatomic) id<ASTextLinePositionModifier> textContainerLinePositionModifier;

@end

@interface ASTextNode2 (Unavailable)
Expand Down
11 changes: 11 additions & 0 deletions Source/ASTextNode2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,17 @@ - (UIEdgeInsets)textContainerInset
return _textContainer.insets;
}

- (void)setTextContainerLinePositionModifier:(id<ASTextLinePositionModifier>)modifier
{
ASLockedSelfCompareAssignObjects(_textContainer.linePositionModifier, modifier);
}

- (id<ASTextLinePositionModifier>)textContainerLinePositionModifier
{
ASLockScopeSelf();
return _textContainer.linePositionModifier;
}

- (CGSize)calculateSizeThatFits:(CGSize)constrainedSize
{
ASDisplayNodeAssert(constrainedSize.width >= 0, @"Constrained width for text (%f) is too narrow", constrainedSize.width);
Expand Down
43 changes: 28 additions & 15 deletions Source/Private/TextExperiment/Component/ASTextLayout.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ @implementation ASTextContainer {
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 {
return [self containerWithSize:size insets:UIEdgeInsetsZero];
}
Expand Down Expand Up @@ -373,6 +380,14 @@ - (instancetype)_init {
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 {
ASTextContainer *container = [ASTextContainer containerWithSize:size];
return [self layoutWithContainer:container text:text];
Expand Down Expand Up @@ -599,15 +614,24 @@ + (ASTextLayout *)layoutWithContainer:(ASTextContainer *)container text:(NSAttri
position.y = cgPathBox.size.height + cgPathBox.origin.y - ctLineOrigin.y;

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;

if (constraintSizeIsExtended) {
if (isVerticalForm) {
if (rect.origin.x + rect.size.width >
constraintRectBeforeExtended.origin.x +
constraintRectBeforeExtended.size.width) {
measuringBeyondConstraints = YES;
};
}
} else {
if (rect.origin.y + rect.size.height >
constraintRectBeforeExtended.origin.y +
Expand Down Expand Up @@ -640,11 +664,11 @@ + (ASTextLayout *)layoutWithContainer:(ASTextContainer *)container text:(NSAttri

line.index = lineCurrentIdx;
line.row = rowIdx;
[lines addObject:line];

rowCount = rowIdx + 1;
lineCurrentIdx ++;

if (i == 0) {
if (i++ == 0) {
textBoundingRect = rect;
} else if (!measuringBeyondConstraints) {
if (maximumNumberOfRows == 0 || rowIdx < maximumNumberOfRows) {
Expand Down Expand Up @@ -679,17 +703,6 @@ + (ASTextLayout *)layoutWithContainer:(ASTextContainer *)container text:(NSAttri
}
}

// 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));
if (lineRowsEdge == NULL) FAIL_AND_RETURN
lineRowsIndex = (NSUInteger *) calloc(rowCount, sizeof(NSUInteger));
Expand Down

0 comments on commit 990b240

Please sign in to comment.