Right-Click, UIContextMenuInteraction, & UITouch.Type.indirectPointer in iOS 13.4

Hello


I'm working to enable proper trackpad support for iOS 13.4+, with the new iPad Magic Keyboard. This has been a relatively straightfoward process, but I've run into an issue around Right-Click support.


TLDR: I'd like to be able to tell if a UIContextMenuInteraction was triggered via a right-click from a trackpad (indirect pointer), or from a long-press from a single-tap figure gesture (direct) but that seems impossible given that you cannot navigate from the Interaction to the TouchType that invoked it.


---


AFAIK, "right-click" support in iPadOS is enabled via a UIContextMenuInteraction. The one required delegate method returns a nullable UIContextMenuConfiguration. Our app does not support UIContextMenus at this time, but we'd like to use right-clicking, so we run custom code in the delegate method prior to returning nil for the confiiguration. This all works as expected.


The problem comes from the fact that now we "support" UIContextMenus. The interaction is added to our view, which also has a custom long-press gesture recognizer. This long press is triiggered at the same time as the UIContextMenuInteraction, causing conflicting behaviors as both gestures activate.


Unfortunately, it seems impossible to work backward from a UIContextMenuInteraction to the touchType that invoked it. You can retrieve the view property, but you can't work backwards from there to the active touch. Overriding the touchesBegan/etc methods allows for touchType detection, but the timing throws things off: the UIContextMenuInteractioniDelegate method triggers before any of the touch handlers, so I can't even track activeTouches independently.


Additionially, since the gestures that track UIContextMenuInteractioni & Trackpad support etc are private, I can't subclass them to properly track touchType either.


---


Is there any way to differentiiate UIContextMenuIInteractions triggered from a trackpad right-click, vs one from direct long press?


Thanks,

Nick

Anyone have an answer for this? Also similarly, iosquestions.com/ipados-prevent-uicontextmenuinteraction-from-triggering-when-not-using-pointer/
On iOS 14 you can determine if it is not from a right click when menuAppearance is UIContextMenuInteractionAppearanceRich and return nil. When you do this your long press gesture recognizer will still work.

Code Block
- (nullable UIContextMenuConfiguration *)contextMenuInteraction:(UIContextMenuInteraction *)interaction configurationForMenuAtLocation:(CGPoint)location API_AVAILABLE(ios(14.0)){
   
    if (interaction.menuAppearance == UIContextMenuInteractionAppearanceRich) {
        return nil;
    }
//Do what you want on right click
...



Right-Click, UIContextMenuInteraction, & UITouch.Type.indirectPointer in iOS 13.4
 
 
Q