Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit f52bc78

Browse files
GitGaddAdlai Holler
authored andcommitted
Respect hitTestSlop when determining if a tracked touch is inside for ASControlNode (#2896)
1 parent 30194fe commit f52bc78

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

AsyncDisplayKit/ASControlNode.mm

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ @interface ASControlNode ()
6363
*/
6464
void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, void (^block)(ASControlNodeEvent anEvent));
6565

66+
/**
67+
@abstract Returns the expanded bounds used to determine if a touch is considered 'inside' during tracking.
68+
@param controlNode A control node.
69+
@result The expanded bounds of the node.
70+
*/
71+
CGRect _ASControlNodeGetExpandedBounds(ASControlNode *controlNode);
72+
73+
6674
@end
6775

6876
@implementation ASControlNode
@@ -158,7 +166,7 @@ - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
158166
BOOL dragIsInsideBounds = [self pointInside:touchLocation withEvent:nil];
159167

160168
// Update our highlighted state.
161-
CGRect expandedBounds = CGRectInset(self.view.bounds, kASControlNodeExpandedInset, kASControlNodeExpandedInset);
169+
CGRect expandedBounds = _ASControlNodeGetExpandedBounds(self);
162170
BOOL dragIsInsideExpandedBounds = CGRectContainsPoint(expandedBounds, touchLocation);
163171
self.touchInside = dragIsInsideExpandedBounds;
164172
self.highlighted = dragIsInsideExpandedBounds;
@@ -216,7 +224,7 @@ - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
216224
[self endTrackingWithTouch:theTouch withEvent:event];
217225

218226
// Send the appropriate touch-up control event.
219-
CGRect expandedBounds = CGRectInset(self.view.bounds, kASControlNodeExpandedInset, kASControlNodeExpandedInset);
227+
CGRect expandedBounds = _ASControlNodeGetExpandedBounds(self);
220228
BOOL touchUpIsInsideExpandedBounds = CGRectContainsPoint(expandedBounds, touchLocation);
221229

222230
[self sendActionsForControlEvents:(touchUpIsInsideExpandedBounds ? ASControlNodeEventTouchUpInside : ASControlNodeEventTouchUpOutside)
@@ -428,6 +436,10 @@ void _ASEnumerateControlEventsIncludedInMaskWithBlock(ASControlNodeEvent mask, v
428436
}
429437
}
430438

439+
CGRect _ASControlNodeGetExpandedBounds(ASControlNode *controlNode) {
440+
return CGRectInset(UIEdgeInsetsInsetRect(controlNode.view.bounds, controlNode.hitTestSlop), kASControlNodeExpandedInset, kASControlNodeExpandedInset);
441+
}
442+
431443
#pragma mark - For Subclasses
432444
- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)touchEvent
433445
{

0 commit comments

Comments
 (0)