Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@
*/
@implementation RNGestureHandlerButton {
CALayer *_underlayLayer;
BOOL _isTouchInsideBounds;
}

- (void)commonInit
{
_isTouchInsideBounds = NO;
_hitTestEdgeInsets = UIEdgeInsetsZero;
_userEnabled = YES;
_pointerEvents = RNGestureHandlerPointerEventsAuto;
Expand Down Expand Up @@ -275,6 +277,52 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
return CGRectContainsPoint(hitFrame, point);
}

- (BOOL)beginTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
_isTouchInsideBounds = YES;
return [super beginTrackingWithTouch:touch withEvent:event];
}

- (BOOL)continueTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
// DO NOT call super. We are entirely taking over the drag event generation.

CGPoint location = [touch locationInView:self];
CGRect hitFrame = UIEdgeInsetsInsetRect(self.bounds, self.hitTestEdgeInsets);
BOOL currentlyInside = CGRectContainsPoint(hitFrame, location);

if (currentlyInside) {
if (!_isTouchInsideBounds) {
[self sendActionsForControlEvents:UIControlEventTouchDragEnter];
_isTouchInsideBounds = YES;
}
[self sendActionsForControlEvents:UIControlEventTouchDragInside];
} else {
if (_isTouchInsideBounds) {
[self sendActionsForControlEvents:UIControlEventTouchDragExit];
_isTouchInsideBounds = NO;
Comment thread
j-piasecki marked this conversation as resolved.
}
[self sendActionsForControlEvents:UIControlEventTouchDragOutside];
}

// If `cancelTrackingWithEvent` was called, `self.tracking` will be NO.
return self.tracking;
}

- (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
{
// Also bypass super here so that the final "up" event respects the
// strict bounds, rather than Apple's 70-point.

CGPoint location = [touch locationInView:self];
CGRect hitFrame = UIEdgeInsetsInsetRect(self.bounds, self.hitTestEdgeInsets);
if (CGRectContainsPoint(hitFrame, location)) {
[self sendActionsForControlEvents:UIControlEventTouchUpInside];
} else {
[self sendActionsForControlEvents:UIControlEventTouchUpOutside];
}
Comment thread
j-piasecki marked this conversation as resolved.
Outdated
}

- (RNGHUIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
RNGestureHandlerPointerEvents pointerEvents = _pointerEvents;
Expand Down
Loading