Enable right-click context menus on iPadOS

This commit is contained in:
Cameron Gutman
2020-11-14 15:57:16 -06:00
parent dc9b5b7c96
commit 78f2b8ac47
4 changed files with 52 additions and 0 deletions

View File

@@ -122,6 +122,13 @@ static const int LABEL_DY = 20;
UILongPressGestureRecognizer* longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(hostLongClicked:)];
[self addGestureRecognizer:longPressRecognizer];
#if !TARGET_OS_TV
if (@available(iOS 13.0, *)) {
UIContextMenuInteraction* rightClickInteraction = [[UIContextMenuInteraction alloc] initWithDelegate:self];
[self addInteraction:rightClickInteraction];
}
#endif
[self addTarget:self action:@selector(hostClicked) forControlEvents:UIControlEventPrimaryActionTriggered];
[self updateContentsForHost:host];
@@ -194,11 +201,26 @@ 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];
}
}
#if !TARGET_OS_TV
- (UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction
configurationForMenuAtLocation:(CGPoint)location {
[_callback hostLongClicked:_host view:self];
return nil;
}
#endif
- (void) hostClicked {
[_callback hostClicked:_host view:self];
}