From 60a6582380e5094116860fa262464af0d083f083 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 14 Nov 2020 17:03:22 -0600 Subject: [PATCH] Fix conflicting touch action handling on UIAppView and UIComputerView --- Limelight/UIAppView.m | 22 ++++++++++++---------- Limelight/UIComputerView.m | 22 ++++++++++++---------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Limelight/UIAppView.m b/Limelight/UIAppView.m index 0429f218..6ad9cf48 100644 --- a/Limelight/UIAppView.m +++ b/Limelight/UIAppView.m @@ -46,15 +46,19 @@ static UIImage* noImage; [_appImage setImage:noImage]; [self addSubview:_appImage]; + // Use UIContextMenuInteraction on iOS 13.0+ and a standard UILongPressGestureRecognizer + // for tvOS devices and iOS prior to 13.0. #if !TARGET_OS_TV if (@available(iOS 13.0, *)) { UIContextMenuInteraction* rightClickInteraction = [[UIContextMenuInteraction alloc] initWithDelegate:self]; [self addInteraction:rightClickInteraction]; } + else #endif - - UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(appLongClicked:)]; - [self addGestureRecognizer:longPressRecognizer]; + { + UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(appLongClicked:)]; + [self addGestureRecognizer:longPressRecognizer]; + } [self addTarget:self action:@selector(appClicked:) forControlEvents:UIControlEventPrimaryActionTriggered]; @@ -92,13 +96,6 @@ static UIImage* noImage; } - (void) appLongClicked:(UILongPressGestureRecognizer*)gesture { -#if !TARGET_OS_TV - if (@available(iOS 13.0, *)) { - // contextMenuInteraction will handle this - return; - } -#endif - if (gesture.state == UIGestureRecognizerStateBegan) { [_callback appLongClicked:_app view:self]; } @@ -107,6 +104,11 @@ static UIImage* noImage; #if !TARGET_OS_TV - (UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction configurationForMenuAtLocation:(CGPoint)location { + // We don't want to trigger the primary action at this point, so cancel + // tracking touch on this view now. This will also have the (intended) + // effect of removing the touch highlight on this view. + [self cancelTrackingWithEvent:nil]; + [_callback appLongClicked:_app view:self]; return nil; } diff --git a/Limelight/UIComputerView.m b/Limelight/UIComputerView.m index ed1650ad..450ce3b8 100644 --- a/Limelight/UIComputerView.m +++ b/Limelight/UIComputerView.m @@ -119,15 +119,19 @@ static const int LABEL_DY = 20; _host = host; _callback = callback; - UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(hostLongClicked:)]; - [self addGestureRecognizer:longPressRecognizer]; - + // Use UIContextMenuInteraction on iOS 13.0+ and a standard UILongPressGestureRecognizer + // for tvOS devices and iOS prior to 13.0. #if !TARGET_OS_TV if (@available(iOS 13.0, *)) { UIContextMenuInteraction* rightClickInteraction = [[UIContextMenuInteraction alloc] initWithDelegate:self]; [self addInteraction:rightClickInteraction]; } + else #endif + { + UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(hostLongClicked:)]; + [self addGestureRecognizer:longPressRecognizer]; + } [self addTarget:self action:@selector(hostClicked) forControlEvents:UIControlEventPrimaryActionTriggered]; @@ -206,13 +210,6 @@ static const int LABEL_DY = 20; } - (void) hostLongClicked:(UILongPressGestureRecognizer*)gesture { -#if !TARGET_OS_TV - if (@available(iOS 13.0, *)) { - // contextMenuInteraction will handle this - return; - } -#endif - if (gesture.state == UIGestureRecognizerStateBegan) { [_callback hostLongClicked:_host view:self]; } @@ -221,6 +218,11 @@ static const int LABEL_DY = 20; #if !TARGET_OS_TV - (UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction configurationForMenuAtLocation:(CGPoint)location { + // We don't want to trigger the primary action at this point, so cancel + // tracking touch on this view now. This will also have the (intended) + // effect of removing the touch highlight on this view. + [self cancelTrackingWithEvent:nil]; + [_callback hostLongClicked:_host view:self]; return nil; }