@@ -166,30 +166,6 @@ - (void)layout
166166 [self applyUnderlayCornerRadii ];
167167}
168168
169- - (BOOL )shouldHandleTouch:(RNGHUIView *)view
170- {
171- if ([view isKindOfClass: [RNGestureHandlerButton class ]]) {
172- RNGestureHandlerButton *button = (RNGestureHandlerButton *)view;
173- return button.userEnabled ;
174- }
175-
176- // Certain subviews such as RCTViewComponentView have been observed to have disabled
177- // accessibility gesture recognizers such as _UIAccessibilityHUDGateGestureRecognizer,
178- // ostensibly set by iOS. Such gesture recognizers cause this function to return YES
179- // even when the passed view is static text and does not respond to touches. This in
180- // turn prevents the button from receiving touches, breaking functionality. To handle
181- // such case, we can count only the enabled gesture recognizers when determining
182- // whether a view should receive touches.
183- NSPredicate *isEnabledPredicate = [NSPredicate predicateWithFormat: @" isEnabled == YES " ];
184- NSArray *enabledGestureRecognizers = [view.gestureRecognizers filteredArrayUsingPredicate: isEnabledPredicate];
185-
186- #if !TARGET_OS_OSX
187- return [view isKindOfClass: [UIControl class ]] || [enabledGestureRecognizers count ] > 0 ;
188- #else
189- return [view isKindOfClass: [NSControl class ]] || [enabledGestureRecognizers count ] > 0 ;
190- #endif
191- }
192-
193169- (void )animateUnderlayToOpacity:(float )toOpacity duration:(NSTimeInterval )durationMs
194170{
195171 _underlayLayer.opacity =
@@ -667,6 +643,44 @@ - (void)endTrackingWithTouch:(UITouch *)touch withEvent:(UIEvent *)event
667643 _isTouchInsideBounds = NO ;
668644}
669645
646+ - (BOOL )shouldHandleTouch:(RNGHUIView *)view atPoint:(CGPoint)point
647+ {
648+ if ([view isKindOfClass: [RNGestureHandlerButton class ]]) {
649+ RNGestureHandlerButton *button = (RNGestureHandlerButton *)view;
650+ return button.userEnabled ;
651+ }
652+
653+ // Certain subviews such as RCTViewComponentView have been observed to have disabled
654+ // accessibility gesture recognizers such as _UIAccessibilityHUDGateGestureRecognizer,
655+ // ostensibly set by iOS. Such gesture recognizers cause this function to return YES
656+ // even when the passed view is static text and does not respond to touches. This in
657+ // turn prevents the button from receiving touches, breaking functionality. To handle
658+ // such case, we can count only the enabled gesture recognizers when determining
659+ // whether a view should receive touches.
660+ NSPredicate *isEnabledPredicate = [NSPredicate predicateWithFormat: @" isEnabled == YES " ];
661+ NSArray *enabledGestureRecognizers = [view.gestureRecognizers filteredArrayUsingPredicate: isEnabledPredicate];
662+
663+ BOOL gestureRecognizerWantsEvent = NO ;
664+ for (UIGestureRecognizer *recognizer in enabledGestureRecognizers) {
665+ RNGestureHandler *handler = [RNGestureHandler findGestureHandlerByRecognizer: recognizer];
666+ if (handler != nil ) {
667+ CGPoint pointInView = [self convertPoint: point toView: view];
668+ gestureRecognizerWantsEvent = [handler wantsToHandleEventsAtPoint: pointInView];
669+ } else {
670+ gestureRecognizerWantsEvent = YES ;
671+ }
672+ if (gestureRecognizerWantsEvent) {
673+ break ;
674+ }
675+ }
676+
677+ #if !TARGET_OS_OSX
678+ return [view isKindOfClass: [UIControl class ]] || gestureRecognizerWantsEvent;
679+ #else
680+ return [view isKindOfClass: [NSControl class ]] || [enabledGestureRecognizers count ] > 0 ;
681+ #endif
682+ }
683+
670684- (RNGHUIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
671685{
672686 RNGestureHandlerPointerEvents pointerEvents = _pointerEvents;
@@ -680,7 +694,7 @@ - (RNGHUIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
680694 if (!subview.isHidden && subview.alpha > 0 ) {
681695 CGPoint convertedPoint = [subview convertPoint: point fromView: self ];
682696 UIView *hitView = [subview hitTest: convertedPoint withEvent: event];
683- if (hitView != nil && [self shouldHandleTouch: hitView]) {
697+ if (hitView != nil && [self shouldHandleTouch: hitView atPoint: point ]) {
684698 return hitView;
685699 }
686700 }
@@ -693,7 +707,7 @@ - (RNGHUIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
693707 }
694708
695709 RNGHUIView *inner = [super hitTest: point withEvent: event];
696- while (inner && ![self shouldHandleTouch: inner]) {
710+ while (inner && ![self shouldHandleTouch: inner atPoint: point ]) {
697711 inner = inner.superview ;
698712 }
699713 return inner;
0 commit comments