Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions AsyncDisplayKit/ASTextNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ typedef NS_ENUM(NSUInteger, ASTextNodeHighlightStyle) {
*/
@property (nonatomic, assign) NSUInteger maximumNumberOfLines;

/**
* @abstract flexShrink is YES by default for ASTextNode, allowing it to wrap to
* multple lines when contained in stacks.
* @default YES
*/
@property (nonatomic, assign) BOOL flexShrink;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@appleguy @nguyenhuy Why do we need to add this property to ASTextNode? It's already in ASLayoutable.h


/**
@abstract The number of lines in the text. Text must have been sized first.
*/
Expand Down
5 changes: 4 additions & 1 deletion AsyncDisplayKit/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ @implementation ASTextNode {

UILongPressGestureRecognizer *_longPressGestureRecognizer;
}
@dynamic placeholderEnabled;
@dynamic placeholderEnabled, flexShrink;

#pragma mark - NSObject

Expand All @@ -104,6 +104,9 @@ - (instancetype)init
self.userInteractionEnabled = NO;
self.needsDisplayOnBoundsChange = YES;

// Enable flexShrink by default so that text nodes wrap to multiple lines when in a stack.
self.flexShrink = YES;

_truncationMode = NSLineBreakByWordWrapping;
_composedTruncationString = DefaultTruncationAttributedString();

Expand Down
7 changes: 6 additions & 1 deletion examples/SocialAppLayout/Sample/PostNode.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,25 @@ - (instancetype)initWithPost:(Post *)post

// Name node
_nameNode = [[ASTextNode alloc] init];

_nameNode.flexShrink = NO; // Never truncate user's real name
_nameNode.attributedString = [[NSAttributedString alloc] initWithString:_post.name attributes:[TextStyles nameStyle]];
_nameNode.maximumNumberOfLines = 1;
[self addSubnode:_nameNode];

// Username node
_usernameNode = [[ASTextNode alloc] init];

_usernameNode.flexShrink = YES; // If real name and username don't fit to cell width, allow username shrink
_usernameNode.attributedString = [[NSAttributedString alloc] initWithString:_post.username attributes:[TextStyles usernameStyle]];
_usernameNode.flexShrink = YES; //if name and username don't fit to cell width, allow username shrink
_usernameNode.truncationMode = NSLineBreakByTruncatingTail;
_usernameNode.maximumNumberOfLines = 1;
[self addSubnode:_usernameNode];

// Time node
_timeNode = [[ASTextNode alloc] init];

_timeNode.flexShrink = NO; // Never truncate the time, as it is quite short.
_timeNode.attributedString = [[NSAttributedString alloc] initWithString:_post.time attributes:[TextStyles timeStyle]];
[self addSubnode:_timeNode];

Expand Down