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

Don’t handle touches on additional attributed message if passthrough is enabled #1184

Merged
merged 5 commits into from
Oct 24, 2018

Conversation

maicki
Copy link
Contributor

@maicki maicki commented Oct 22, 2018

This diff will change the behavior handling tapping on the additional attributed message:
If passthroughNonlinkTouches is set to YES, taps on the additional attributed message will not call the textNodeTappedTruncationToken: delegate method anymore. Previously tapping on the additional attributed message always called textNodeTappedTruncationToken: without any dependence on passthroughNonlinkTouches.

Another approach could be to add a new property like: handleAdditionalTruncationString that if set to YES will call textNodeTappedTruncationToken: otherwise not. This would not depend on passthroughNonlinkTouches.

Furthermore this diff fixes taps within the additional attributed message within ASTextNode2 what currently didn't really work. Before this the tap was not detected if tapped directly on the additional attributed text, it was only detected if tapped a bit outside of the additional attributed text but still within the ASTextNode2 bounds.

@@ -974,7 +974,7 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
BOOL linkCrossesVisibleRange = (lastCharIndex > range.location) && (lastCharIndex < NSMaxRange(range) - 1);

if (inAdditionalTruncationMessage) {
return YES;
return !_passthroughNonlinkTouches;
Copy link
Member

Choose a reason for hiding this comment

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

Right above here we short-circuit if (!_passthroughNonlinkTouches). So this is equivalent to return NO. We should ideally remove this branch entirely, and simply return YES if we're in a link and NO otherwise. Whether we're in the truncation message or not doesn't matter for this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Adlai-Holler Agree and addressed

@ghost
Copy link

ghost commented Oct 23, 2018

🚫 CI failed with log

@maicki maicki requested a review from nguyenhuy October 23, 2018 15:35
@maicki maicki force-pushed the MSPassthroughNonlinkTouchesClarification branch from 83846ac to c9cd1b5 Compare October 23, 2018 18:06
Copy link
Member

@appleguy appleguy left a comment

Choose a reason for hiding this comment

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

Mostly small feedback, land when you're ready!

if (inAdditionalTruncationMessage) {
return YES;
} else if (range.length && !linkCrossesVisibleRange && linkAttributeValue != nil && linkAttributeName != nil) {
if (range.length && !linkCrossesVisibleRange && linkAttributeValue != nil && linkAttributeName != nil) {
Copy link
Member

Choose a reason for hiding this comment

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

The range.length check should probably have > 0 just to be a bit more formal than implicit cast to BOOL. If you decide to change it, there's another instance of this check below in ASTextNode2.

@@ -194,6 +194,7 @@ - (instancetype)init
self.userInteractionEnabled = NO;
self.needsDisplayOnBoundsChange = YES;

// The default truncation type is end for truncation
Copy link
Member

Choose a reason for hiding this comment

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

Probably don't need a comment here, but one in the header file (if not there already) would be useful.

BOOL inAdditionalTruncationMessage = NO;

CTLineRef truncatedCTLine = layout.truncatedLine.CTLine;
if (truncatedCTLine != NULL && _additionalTruncationMessage != nil) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we check _additionalTruncationMessage.length > 0 in these various cases? Probably rare for the value to be set to @"" I guess, so it may not matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Across the text nodes where are checking _additionalTruncationMessage != nil if we determine if the an _additionalTruncationMessage is set. I would suggest we keep it as _additionalTruncationMessage != nil

CFIndex truncatedCTLineGlyphCount = CTLineGetGlyphCount(truncatedCTLine);

CTLineRef truncationTokenLine =
CTLineCreateWithAttributedString((CFAttributedStringRef)_truncationAttributedText);
Copy link
Member

Choose a reason for hiding this comment

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

Bump this to the line above, and on the several lines below. No 100 char line limits in Texture, thank goodness!

switch (_textContainer.truncationType) {
case ASTextTruncationTypeStart: {
if (stringIndexForPosition > truncationTokenLineGlyphCount &&
stringIndexForPosition < (additionalTruncationTokenLineGlyphCount + truncationTokenLineGlyphCount)) {
Copy link
Member

Choose a reason for hiding this comment

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

This expression is used here and on line 648, though with the variables added together in the opposite order. Is there a descriptive name we can give for this value and put it in a variable for better readability?

+ (ASConfiguration *)textureConfiguration
{
ASConfiguration *configuration = [ASConfiguration new];
// configuration.experimentalFeatures = ASExperimentalTextNode;
Copy link
Member

Choose a reason for hiding this comment

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

Possibly worth landing it with this enabled :). Otherwise probably delete the commented line.

@maicki maicki merged commit dab3281 into master Oct 24, 2018
@maicki maicki deleted the MSPassthroughNonlinkTouchesClarification branch October 24, 2018 22:18
mikezucc pushed a commit to mikezucc/Texture that referenced this pull request Nov 7, 2018
… is enabled (TextureGroup#1184)

* Don’t handle touches on additional attributed message if passthrough is enabled

* Cleanup

* Don't handle extra inAdditionalTruncationMessage within pointInside:withEvent:

* Update changelog

* Address comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants