Skip to content

Commit

Permalink
Instead of textLayoutForConstraint: expose shouldTruncateForConstrain…
Browse files Browse the repository at this point in the history
…edSize: in ASTextNode
  • Loading branch information
maicki committed Oct 19, 2018
1 parent 60c12b3 commit 14a905c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
8 changes: 3 additions & 5 deletions Source/ASTextNode+Beta.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

#import <AsyncDisplayKit/ASTextNode.h>

@class ASTextLayout;

NS_ASSUME_NONNULL_BEGIN

@interface ASTextNode ()
Expand All @@ -37,10 +35,10 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (readonly) BOOL usingExperiment;

/*
* Returns layout for textNode that fit to constrainedSize's max size.
/**
* Returns a Boolean indicating if the text node will truncate for the given constrained size
*/
- (ASTextLayout *)textLayoutForConstraint:(ASSizeRange)constrainedSize;
- (BOOL)shouldTruncateForConstrainedSize:(ASSizeRange)constrainedSize;

@end

Expand Down
15 changes: 5 additions & 10 deletions Source/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#import <AsyncDisplayKit/ASTextKitRenderer+Positioning.h>
#import <AsyncDisplayKit/ASTextKitShadower.h>

#import <AsyncDisplayKit/ASTextLayout.h>

#import <AsyncDisplayKit/ASInternalHelpers.h>
#import <AsyncDisplayKit/ASLayout.h>

Expand Down Expand Up @@ -1220,6 +1218,11 @@ - (BOOL)isTruncated
return ASLockedSelf([[self _locked_renderer] isTruncated]);
}

- (BOOL)shouldTruncateForConstrainedSize:(ASSizeRange)constrainedSize
{
return ASLockedSelf([[self _locked_rendererWithBounds:{.size = constrainedSize.max}] isTruncated]);
}

- (void)setPointSizeScaleFactors:(NSArray<NSNumber *> *)pointSizeScaleFactors
{
if (ASLockedSelfCompareAssignCopy(_pointSizeScaleFactors, pointSizeScaleFactors)) {
Expand Down Expand Up @@ -1386,14 +1389,6 @@ + (id)allocWithZone:(struct _NSZone *)zone
}
}

#pragma mark - Unavailable

- (ASTextLayout *)textLayoutForConstraint:(ASSizeRange)constrainedSize
{
ASDisplayNodeFailAssert(@"This method is only available in ASTextNode2");
return nil;
}

@end

@implementation ASTextNode (Deprecated)
Expand Down
13 changes: 8 additions & 5 deletions Source/ASTextNode2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1083,15 +1083,18 @@ - (void)setTruncationMode:(NSLineBreakMode)truncationMode

- (BOOL)isTruncated
{
AS_TEXT_ALERT_UNIMPLEMENTED_FEATURE();
return NO;
return ASLockedSelf([self locked_textLayoutForSize:[self _locked_threadSafeBounds].size].truncatedLine == nil);
}

- (ASTextLayout *)textLayoutForConstraint:(ASSizeRange)constrainedSize
- (BOOL)shouldTruncateForConstrainedSize:(ASSizeRange)constrainedSize
{
return ASLockedSelf([self locked_textLayoutForSize:constrainedSize.max].truncatedLine == nil);
}

- (ASTextLayout *)locked_textLayoutForSize:(CGSize)size
{
ASLockScopeSelf();
ASTextContainer *container = [_textContainer copy];
container.size = constrainedSize.max;
container.size = size;
return ASTextNodeCompatibleLayoutWithContainerAndText(container, _attributedText);
}

Expand Down

0 comments on commit 14a905c

Please sign in to comment.