diff --git a/Source/ASTextNode.h b/Source/ASTextNode.h index 783eafc53..a67f1f574 100644 --- a/Source/ASTextNode.h +++ b/Source/ASTextNode.h @@ -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) diff --git a/Source/ASTextNode.mm b/Source/ASTextNode.mm index f4d89f0df..0d65dbb0f 100644 --- a/Source/ASTextNode.mm +++ b/Source/ASTextNode.mm @@ -209,6 +209,7 @@ @implementation ASTextNode { ASTextNodeHighlightStyle _highlightStyle; BOOL _longPressCancelsTouches; BOOL _passthroughNonlinkTouches; + BOOL _alwaysHandleTruncationTokenTap; } @dynamic placeholderEnabled; @@ -992,11 +993,16 @@ - (UIImage *)placeholderImage - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { ASDisplayNodeAssertMainThread(); - + ASLockScopeSelf(); // Protect usage of _passthroughNonlinkTouches and _alwaysHandleTruncationTokenTap ivars. + if (!_passthroughNonlinkTouches) { return [super pointInside:point withEvent:event]; } + if (_alwaysHandleTruncationTokenTap) { + return YES; + } + NSRange range = NSMakeRange(0, 0); NSString *linkAttributeName = nil; BOOL inAdditionalTruncationMessage = NO; @@ -1132,6 +1138,18 @@ - (BOOL)_pendingTruncationTap return [_highlightedLinkAttributeName isEqualToString:ASTextNodeTruncationTokenAttributeName]; } +- (BOOL)alwaysHandleTruncationTokenTap +{ + ASLockScopeSelf(); + return _alwaysHandleTruncationTokenTap; +} + +- (void)setAlwaysHandleTruncationTokenTap:(BOOL)alwaysHandleTruncationTokenTap +{ + ASLockScopeSelf(); + _alwaysHandleTruncationTokenTap = alwaysHandleTruncationTokenTap; +} + #pragma mark - Shadow Properties - (CGColorRef)shadowColor diff --git a/Source/ASTextNode2.h b/Source/ASTextNode2.h index 254ce40a7..b46a0bcb4 100644 --- a/Source/ASTextNode2.h +++ b/Source/ASTextNode2.h @@ -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 diff --git a/Source/ASTextNode2.mm b/Source/ASTextNode2.mm index 2a25b4498..92c2b813d 100644 --- a/Source/ASTextNode2.mm +++ b/Source/ASTextNode2.mm @@ -177,6 +177,7 @@ @implementation AS_TN2_CLASSNAME { ASTextNodeHighlightStyle _highlightStyle; BOOL _longPressCancelsTouches; BOOL _passthroughNonlinkTouches; + BOOL _alwaysHandleTruncationTokenTap; } @dynamic placeholderEnabled; @@ -967,10 +968,15 @@ - (UIImage *)placeholderImage - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event { ASDisplayNodeAssertMainThread(); - + ASLockScopeSelf(); // Protect usage of _passthroughNonlinkTouches and _alwaysHandleTruncationTokenTap ivars. + if (!_passthroughNonlinkTouches) { return [super pointInside:point withEvent:event]; } + + if (_alwaysHandleTruncationTokenTap) { + return YES; + } NSRange range = NSMakeRange(0, 0); NSString *linkAttributeName = nil; @@ -1117,6 +1123,18 @@ - (BOOL)_pendingTruncationTap return [ASLockedSelf(_highlightedLinkAttributeName) isEqualToString:ASTextNodeTruncationTokenAttributeName]; } +- (BOOL)alwaysHandleTruncationTokenTap +{ + ASLockScopeSelf(); + return _alwaysHandleTruncationTokenTap; +} + +- (void)setAlwaysHandleTruncationTokenTap:(BOOL)alwaysHandleTruncationTokenTap +{ + ASLockScopeSelf(); + _alwaysHandleTruncationTokenTap = alwaysHandleTruncationTokenTap; +} + #pragma mark - Shadow Properties /**