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

Touch Manager Gesture Cancellation #727

Conversation

NicoleYarroch
Copy link
Contributor

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 type CANCEL. The SDLTouchManager handles parsing the SDLOnTouchType 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
  • Added support for detecting a SDLTouchType of type CANCEL in the SDLTouchManager class.
  • Added two new optional methods to the SDLTouchManagerDelegate:
    • touchManager:manager pinchCanceledAtCenterPoint:point
    • touchManager:manager panningCanceledAtPoint:point.
Bug Fixes
  • Added SDLRectangle.h to both of the .podspec files.

CLA

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>
@NicoleYarroch NicoleYarroch self-assigned this Sep 8, 2017
@NicoleYarroch NicoleYarroch added this to the 5.0.0 milestone Sep 8, 2017
@joeljfischer joeljfischer changed the base branch from master to release/5.0.0 September 8, 2017 19:36
@joeljfischer joeljfischer changed the title Issue 673 Touch Manager Gesture Cancellation Touch Manager Gesture Cancellation Sep 11, 2017
@joeljfischer joeljfischer added the proposal Accepted SDL Evolution Proposal label Sep 11, 2017
@@ -141,39 +153,42 @@ - (void)sdl_handleTouchBegan:(SDLTouch *)touch {
_performingTouchType = SDLPerformingTouchTypeSingleTouch;

switch (touch.identifier) {
case SDLTouchIdentifierFirstFinger:
case SDLTouchIdentifierFirstFinger:
Copy link
Contributor

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;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

- (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:
Copy link
Contributor

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;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

break;
}

case SDLPerformingTouchTypeMultiTouch:
Copy link
Contributor

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;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

}

switch (self.performingTouchType) {
case SDLPerformingTouchTypeMultiTouch:
Copy link
Contributor

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;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

* @param touch Gesture information
*/
- (void)sdl_handleTouchCanceled:(SDLTouch *)touch {
if (!self.isTouchEnabled) {
Copy link
Contributor

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.

Copy link
Contributor Author

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

break;

case SDLPerformingTouchTypeNone:
case SDLPerformingTouchTypeSingleTouch:
Copy link
Contributor

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

switch (touch.identifier) {
case SDLTouchIdentifierFirstFinger:
self.currentPinchGesture.firstTouch = touch;
break;
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

- fixed braces on switch statements
- removed unnecessary checking for isTouchEnabled
- added documentation to private method

Signed-off-by: NicoleYarroch <nicole@livio.io>
@joeljfischer joeljfischer merged commit 10ce67a into release/5.0.0 Sep 12, 2017
@joeljfischer joeljfischer deleted the feature/issue_673_touch_manager_gesture_cancellation branch September 12, 2017 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Accepted SDL Evolution Proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants