-
Notifications
You must be signed in to change notification settings - Fork 103
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
Touch Manager Gesture Cancellation #727
Touch Manager Gesture Cancellation #727
Conversation
Signed-off-by: NicoleYarroch <nicole@livio.io>
Signed-off-by: NicoleYarroch <nicole@livio.io>
- Added test cases for onTouchEvent CANCEL Signed-off-by: NicoleYarroch <nicole@livio.io>
- Test cases written for single tap, double tap, and pan gesture cancellation Signed-off-by: NicoleYarroch <nicole@livio.io>
- got rid of unnecessary repeated code Signed-off-by: NicoleYarroch <nicole@livio.io>
Signed-off-by: NicoleYarroch <nicole@livio.io>
Signed-off-by: NicoleYarroch <nicole@livio.io>
SmartDeviceLink/SDLTouchManager.m
Outdated
@@ -141,39 +153,42 @@ - (void)sdl_handleTouchBegan:(SDLTouch *)touch { | |||
_performingTouchType = SDLPerformingTouchTypeSingleTouch; | |||
|
|||
switch (touch.identifier) { | |||
case SDLTouchIdentifierFirstFinger: | |||
case SDLTouchIdentifierFirstFinger: |
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.
This indentation for the whole switch is incorrect, should look like:
switch (touch.identifier) {
case SDLTouchIdentifierFirstFinger: {
self.previousTouch = touch;
} break;
case SDLTouchIdentifierSecondFinger: {
_performingTouchType = SDLPerformingTouchTypeMultiTouch;
self.currentPinchGesture = [[SDLPinchGesture alloc] initWithFirstTouch:self.previousTouch secondTouch:touch];
self.previousPinchDistance = self.currentPinchGesture.distance;
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:pinchDidStartAtCenterPoint:)]) {
[self.touchEventDelegate touchManager:self pinchDidStartAtCenterPoint:self.currentPinchGesture.center];
}
} break;
}
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.
Fixed
SmartDeviceLink/SDLTouchManager.m
Outdated
- (void)sdl_handleTouchMoved:(SDLTouch *)touch { | ||
if ((touch.timeStamp - self.previousTouch.timeStamp) <= (self.movementTimeThreshold * NSEC_PER_USEC) || !self.isTouchEnabled) { | ||
return; // no-op | ||
} | ||
|
||
switch (self.performingTouchType) { | ||
case SDLPerformingTouchTypeMultiTouch: | ||
case SDLPerformingTouchTypeMultiTouch: |
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.
Also indented incorrectly:
switch (self.performingTouchType) {
case SDLPerformingTouchTypeMultiTouch: {
switch (touch.identifier) {
case SDLTouchIdentifierFirstFinger: {
self.currentPinchGesture.firstTouch = touch;
} break;
case SDLTouchIdentifierSecondFinger: {
self.currentPinchGesture.secondTouch = touch;
} break;
}
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceivePinchAtCenterPoint:withScale:)]) {
CGFloat scale = self.currentPinchGesture.distance / self.previousPinchDistance;
[self.touchEventDelegate touchManager:self
didReceivePinchAtCenterPoint:self.currentPinchGesture.center
withScale:scale];
}
self.previousPinchDistance = self.currentPinchGesture.distance;
} break;
case SDLPerformingTouchTypeSingleTouch: {
_performingTouchType = SDLPerformingTouchTypePanningTouch;
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:panningDidStartAtPoint:)]) {
[self.touchEventDelegate touchManager:self
panningDidStartAtPoint:touch.location];
}
} break;
case SDLPerformingTouchTypePanningTouch: {
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceivePanningFromPoint:toPoint:)]) {
[self.touchEventDelegate touchManager:self
didReceivePanningFromPoint:self.previousTouch.location
toPoint:touch.location];
}
} break;
case SDLPerformingTouchTypeNone: break;
}
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.
Fixed
SmartDeviceLink/SDLTouchManager.m
Outdated
break; | ||
} | ||
|
||
case SDLPerformingTouchTypeMultiTouch: |
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.
Also indented incorrectly:
switch (self.performingTouchType) {
case SDLPerformingTouchTypeMultiTouch: {
[self sdl_setMultiTouchFingerTouchForTouch:touch];
if (self.currentPinchGesture.isValid) {
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:pinchDidEndAtCenterPoint:)]) {
[self.touchEventDelegate touchManager:self pinchDidEndAtCenterPoint:self.currentPinchGesture.center];
}
self.currentPinchGesture = nil;
}
} break;
case SDLPerformingTouchTypePanningTouch: {
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:panningDidEndAtPoint:)]) {
[self.touchEventDelegate touchManager:self panningDidEndAtPoint:touch.location];
}
} break;
case SDLPerformingTouchTypeSingleTouch: {
if (self.singleTapTimer == nil) {
// Initial Tap
self.singleTapTouch = touch;
[self sdl_initializeSingleTapTimerAtPoint:self.singleTapTouch.location];
} else {
// Double Tap
[self sdl_cancelSingleTapTimer];
NSUInteger timeStampDelta = touch.timeStamp - self.singleTapTouch.timeStamp;
CGFloat xDelta = fabs(touch.location.x - self.singleTapTouch.location.x);
CGFloat yDelta = fabs(touch.location.y - self.singleTapTouch.location.y);
if (timeStampDelta <= self.tapTimeThreshold * NSEC_PER_USEC && xDelta <= self.tapDistanceThreshold && yDelta <= self.tapDistanceThreshold) {
CGPoint centerPoint = CGPointCenterOfPoints(touch.location,
self.singleTapTouch.location);
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceiveDoubleTapAtPoint:)]) {
[self.touchEventDelegate touchManager:self
didReceiveDoubleTapAtPoint:centerPoint];
}
}
self.singleTapTouch = nil;
}
} break;
case SDLPerformingTouchTypeNone: break;
}
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.
Fixed
SmartDeviceLink/SDLTouchManager.m
Outdated
} | ||
|
||
switch (self.performingTouchType) { | ||
case SDLPerformingTouchTypeMultiTouch: |
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.
Also indented incorrectly:
switch (self.performingTouchType) {
case SDLPerformingTouchTypeMultiTouch: {
[self sdl_setMultiTouchFingerTouchForTouch:touch];
if (self.currentPinchGesture.isValid) {
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:pinchCanceledAtCenterPoint:)]) {
[self.touchEventDelegate touchManager:self pinchCanceledAtCenterPoint:self.currentPinchGesture.center];
}
self.currentPinchGesture = nil;
}
} break;
case SDLPerformingTouchTypePanningTouch: {
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:panningCanceledAtPoint:)]) {
[self.touchEventDelegate touchManager:self panningCanceledAtPoint:touch.location];
}
} break;
case SDLPerformingTouchTypeSingleTouch: // fallthrough
case SDLPerformingTouchTypeNone: break;
}
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.
Fixed
SmartDeviceLink/SDLTouchManager.m
Outdated
* @param touch Gesture information | ||
*/ | ||
- (void)sdl_handleTouchCanceled:(SDLTouch *)touch { | ||
if (!self.isTouchEnabled) { |
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.
This already exists in the calling method and should not be repeated here or in the other sub-handlers.
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.
Fixed. Removed from all sub-handlers
SmartDeviceLink/SDLTouchManager.m
Outdated
break; | ||
|
||
case SDLPerformingTouchTypeNone: | ||
case SDLPerformingTouchTypeSingleTouch: |
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.
Reverse this and the above case, they should be in the same order as other sub-handlers (this is done in the code provided in the above comment)
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.
Fixed
SmartDeviceLink/SDLTouchManager.m
Outdated
switch (touch.identifier) { | ||
case SDLTouchIdentifierFirstFinger: | ||
self.currentPinchGesture.firstTouch = touch; | ||
break; |
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.
Add braces as in above cases
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.
Fixed
…ture_cancellation
- fixed braces on switch statements - removed unnecessary checking for isTouchEnabled - added documentation to private method Signed-off-by: NicoleYarroch <nicole@livio.io>
Fixes #673
This PR is ready for review.
Risk
This PR makes minor API changes.
Testing Plan
Test cases were added to the
SDLTouchManagerSpec
class to test canceling tap, pan, and pinch gestures.Summary
Adds support for detecting a
SDLTouchType
of typeCANCEL
. TheSDLTouchManager
handles parsing theSDLOnTouchType
notification from Core and issues a cancel delegate callback for pinch and pan gestures. If a single or double tap gesture is canceled, the tap is simply canceled.Changelog
Enhancements
SDLTouchType
of typeCANCEL
in theSDLTouchManager
class.SDLTouchManagerDelegate
:touchManager:manager pinchCanceledAtCenterPoint:point
touchManager:manager panningCanceledAtPoint:point
.Bug Fixes
SDLRectangle.h
to both of the.podspec
files.CLA