UIKeyCommand provides no way to avoid continuously calling the target

Originator:oscar
Number:rdar://42509034 Date Originated:23-Jul-2018 01:53 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:11.4
Classification:Enhancement Reproducible:Always
 
Summary:
The UIKeyCommand API offers no way to limit the number of fires it produces if the user keeps pressing the associated keys on their keyboard. 

In our application, the user can have multiple documents opened on a layout similar to that of Safari, with tabs on the top and contents on the main area. If a user presses CMD-W and doesn't release the keys, the application will keep closing documents until there are none left.

Safari also behaves this way on iOS. 

I believe offering a way to determine the status of the UIKeyCommand (similar to how UIGestureRecognizer.state works) would be really useful because this way we could prevent our users from closing unintended documents, which could potentially cause data loss. Other applications such as Safari could benefit from this as well.

Steps to Reproduce:
Add external keyboard support to an iOS application and provide a set of custom UIKeyCommand instances.

Expected Results:
There's a way in the API to block the number of firings the UIKeyCommand can produce, either via an explicit property (.numberOfFires = 3) or via state observing (.state == .began).

Actual Results:
There's no way to prevent a UIKeyCommand from being fired indefinitely if the user keeps pressing the keys on their keyboard. 

Version:
11.4

Notes:
Inspecting the runtime, I found that UIKeyCommand has an ivar `_repeatable`. Setting this to false dynamically didn't affect the default behavior at all. It would seem that UIKeyCommand already supports this request to some extent.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!