-
-
Notifications
You must be signed in to change notification settings - Fork 1k
[ios] fix pressable with intercepting detector #4041
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,6 +223,37 @@ - (void)animateTarget:(RNGHUIView *)target toOpacity:(CGFloat)opacity scale:(CGF | |
| #endif | ||
| } | ||
|
|
||
| #if !TARGET_OS_OSX | ||
|
|
||
| - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event | ||
| { | ||
| [super touchesBegan:touches withEvent:event]; | ||
| UITouch *touch = [touches anyObject]; | ||
| if (touch.view != self) { | ||
| [self sendActionsForControlEvents:UIControlEventTouchDown]; | ||
| } | ||
| } | ||
|
|
||
| - (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event | ||
| { | ||
| [super touchesEnded:touches withEvent:event]; | ||
| UITouch *touch = [touches anyObject]; | ||
| if (touch.view != self) { | ||
| [self sendActionsForControlEvents:UIControlEventTouchUpInside]; | ||
| } | ||
| } | ||
|
Comment on lines
+228
to
+244
|
||
|
|
||
| - (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event | ||
| { | ||
| [super touchesCancelled:touches withEvent:event]; | ||
| UITouch *touch = [touches anyObject]; | ||
| if (touch.view != self) { | ||
| [self sendActionsForControlEvents:UIControlEventTouchCancel]; | ||
| } | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| - (void)handleAnimatePressIn | ||
| { | ||
| RNGHUIView *target = self.animationTarget ?: self; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
touchesEndedunconditionally sendsUIControlEventTouchUpInsidewhenever the touch began on a subview (touch.view != self). This can fire the press action even when the finger is released outside the control bounds (drag-out cancellation), which breaks expected Pressable/UIControl semantics. Consider checking the touch end location againstpointInside:withEvent:(respectinghitTestEdgeInsets) and sendingUIControlEventTouchUpInsideonly when inside; otherwise sendUIControlEventTouchUpOutside(or cancel as appropriate).