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

Hit test for a single tap now checked on main thread #1209

Merged
12 changes: 12 additions & 0 deletions SmartDeviceLink/SDLTouchManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,10 @@ - (void)sdl_handleTouchBegan:(SDLTouch *)touch {
self.currentPinchGesture = [[SDLPinchGesture alloc] initWithFirstTouch:self.previousTouch secondTouch:touch];
self.previousPinchDistance = self.currentPinchGesture.distance;
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:pinchDidStartInView:atCenterPoint:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:self.currentPinchGesture.center] : nil;
[self.touchEventDelegate touchManager:self pinchDidStartInView:hitView atCenterPoint:self.currentPinchGesture.center];
});
}
} break;
}
Expand Down Expand Up @@ -275,8 +277,10 @@ - (void)sdl_handleTouchMoved:(SDLTouch *)touch {

_performingTouchType = SDLPerformingTouchTypePanningTouch;
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:panningDidStartInView:atPoint:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:touch.location] : nil;
[self.touchEventDelegate touchManager:self panningDidStartInView:hitView atPoint:touch.location];
});
}
} break;
case SDLPerformingTouchTypePanningTouch: {
Expand All @@ -302,18 +306,22 @@ - (void)sdl_handleTouchEnded:(SDLTouch *)touch {
[self sdl_setMultiTouchFingerTouchForTouch:touch];
if (self.currentPinchGesture.isValid) {
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:pinchDidEndInView:atCenterPoint:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:self.currentPinchGesture.center] : nil;
[self.touchEventDelegate touchManager:self pinchDidEndInView:hitView atCenterPoint:self.currentPinchGesture.center];
self.currentPinchGesture = nil;
});
} else {
self.currentPinchGesture = nil;
}
}
} break;
case SDLPerformingTouchTypePanningTouch: {
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:panningDidEndInView:atPoint:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:touch.location] : nil;
[self.touchEventDelegate touchManager:self panningDidEndInView:hitView atPoint:touch.location];
});
}
} break;
case SDLPerformingTouchTypeSingleTouch: {
Expand All @@ -333,8 +341,10 @@ - (void)sdl_handleTouchEnded:(SDLTouch *)touch {
CGPoint centerPoint = CGPointCenterOfPoints(touch.location,
self.singleTapTouch.location);
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceiveDoubleTapForView:atPoint:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:centerPoint] : nil;
[self.touchEventDelegate touchManager:self didReceiveDoubleTapForView:hitView atPoint:centerPoint];
});
}
}

Expand Down Expand Up @@ -420,8 +430,10 @@ - (void)sdl_initializeSingleTapTimerAtPoint:(CGPoint)point {
strongSelf.singleTapTouch = nil;
[strongSelf sdl_cancelSingleTapTimer];
if ([strongSelf.touchEventDelegate respondsToSelector:@selector(touchManager:didReceiveSingleTapForView:atPoint:)]) {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:point] : nil;
[strongSelf.touchEventDelegate touchManager:strongSelf didReceiveSingleTapForView:hitView atPoint:point];
});
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ @interface SDLTouchManager ()
__block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) = ^(SDLTouchManager* touchManager, SDLOnTouchEvent* onTouchEvent) {
SDLRPCNotificationNotification *notification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidReceiveTouchEventNotification object:nil rpcNotification:onTouchEvent];
[[NSNotificationCenter defaultCenter] postNotification:notification];

// Since notifications are sent to te SDLTouchManagerDelegate observers on the main thread, force the block to execute manually on the main thread. If this is not done, the test cases may fail.
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
};

beforeEach(^{
Expand Down