Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new property alwaysHandleTapTruncationAction to ASTextNode2 and ASTextNode. #1520

Merged
merged 7 commits into from
Jul 30, 2019
8 changes: 8 additions & 0 deletions Source/ASTextNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,17 @@ NS_ASSUME_NONNULL_BEGIN

/**
@abstract if YES will not intercept touches for non-link areas of the text. Default is NO.
@discussion If you still want to handle tap truncation action when passthroughNonlinkTouches is YES,
you should set the alwaysHandleTruncationTokenTap to YES.
*/
@property (nonatomic) BOOL passthroughNonlinkTouches;

/**
@abstract Always handle tap truncationAction, even the passthroughNonlinkTouches is YES. Default is NO.
@discussion if this is set to YES, the [ASTextNodeDelegate textNodeTappedTruncationToken:] callback will be called.
*/
@property (nonatomic) BOOL alwaysHandleTruncationTokenTap;

@end

@interface ASTextNode (Unavailable)
Expand Down
10 changes: 9 additions & 1 deletion Source/ASTextNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ @implementation ASTextNode {
ASTextNodeHighlightStyle _highlightStyle;
BOOL _longPressCancelsTouches;
BOOL _passthroughNonlinkTouches;
BOOL _alwaysHandleTruncationTokenTap;
}
@dynamic placeholderEnabled;

Expand Down Expand Up @@ -1010,7 +1011,8 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
NSUInteger lastCharIndex = NSIntegerMax;
BOOL linkCrossesVisibleRange = (lastCharIndex > range.location) && (lastCharIndex < NSMaxRange(range) - 1);

if (range.length > 0 && !linkCrossesVisibleRange && linkAttributeValue != nil && linkAttributeName != nil) {
if (_alwaysHandleTruncationTokenTap ||
dirtmelon marked this conversation as resolved.
Show resolved Hide resolved
(range.length > 0 && !linkCrossesVisibleRange && linkAttributeValue != nil && linkAttributeName != nil)) {
return YES;
} else {
return NO;
Expand Down Expand Up @@ -1132,6 +1134,12 @@ - (BOOL)_pendingTruncationTap
return [_highlightedLinkAttributeName isEqualToString:ASTextNodeTruncationTokenAttributeName];
}

- (BOOL)alwaysHandleTruncationTokenTap
{
ASLockScopeSelf();
return _alwaysHandleTruncationTokenTap;
}

dirtmelon marked this conversation as resolved.
Show resolved Hide resolved
#pragma mark - Shadow Properties

- (CGColorRef)shadowColor
Expand Down
8 changes: 8 additions & 0 deletions Source/ASTextNode2.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,17 @@ NS_ASSUME_NONNULL_BEGIN

/**
@abstract if YES will not intercept touches for non-link areas of the text. Default is NO.
@discussion If you still want to handle tap truncation action when passthroughNonlinkTouches is YES,
you should set the alwaysHandleTruncationTokenTap to YES.
*/
@property (nonatomic) BOOL passthroughNonlinkTouches;

/**
@abstract Always handle tap truncationAction, even the passthroughNonlinkTouches is YES. Default is NO.
@discussion if this is set to YES, the [ASTextNodeDelegate textNodeTappedTruncationToken:] callback will be called.
*/
@property (nonatomic) BOOL alwaysHandleTruncationTokenTap;

+ (void)enableDebugging;

#pragma mark - Layout and Sizing
Expand Down
10 changes: 9 additions & 1 deletion Source/ASTextNode2.mm
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ @implementation AS_TN2_CLASSNAME {
ASTextNodeHighlightStyle _highlightStyle;
BOOL _longPressCancelsTouches;
BOOL _passthroughNonlinkTouches;
BOOL _alwaysHandleTruncationTokenTap;
}
@dynamic placeholderEnabled;

Expand Down Expand Up @@ -985,7 +986,8 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
NSUInteger lastCharIndex = NSIntegerMax;
BOOL linkCrossesVisibleRange = (lastCharIndex > range.location) && (lastCharIndex < NSMaxRange(range) - 1);

if (range.length > 0 && !linkCrossesVisibleRange && linkAttributeValue != nil && linkAttributeName != nil) {
if (_alwaysHandleTruncationTokenTap ||
(range.length > 0 && !linkCrossesVisibleRange && linkAttributeValue != nil && linkAttributeName != nil)) {
return YES;
} else {
return NO;
Expand Down Expand Up @@ -1117,6 +1119,12 @@ - (BOOL)_pendingTruncationTap
return [ASLockedSelf(_highlightedLinkAttributeName) isEqualToString:ASTextNodeTruncationTokenAttributeName];
}

- (BOOL)alwaysHandleTruncationTokenTap
{
ASLockScopeSelf();
return _alwaysHandleTruncationTokenTap;
}

#pragma mark - Shadow Properties

/**
Expand Down