douglashill / KeyboardKit

The easiest way to add comprehensive hardware keyboard control to an iPad, iPhone, or Mac Catalyst app.
MIT License
444 stars 11 forks source link

SFSafariViewController Support #4

Open pedrommcarrasco opened 4 years ago

pedrommcarrasco commented 4 years ago

Is there a way to at least navigate away from SFSafariViewController via keyboard? Also, how should we deal with modals in general?

douglashill commented 4 years ago

For popovers and sheets there's support for dismissing them in KeyboardWindow. The idea is this replicates how the user could tap outside a popover or drag down on a sheet.

For other modal view controllers that are usually dismissed via buttons the idea is to use KeyboardNavigationController and KeyboardBarButtonItem to get a key equivalent to tapping the dismiss button. A key equivalent will be supplied automatically for system bar button items.

Neither of these would work for SFSafariViewController so I think the best option would be to provide a subclass that adds a key command for dismissing it.

pedrommcarrasco commented 4 years ago

For popovers and sheets there's support for dismissing them in KeyboardWindow. The idea is this replicates how the user could tap outside a popover or drag down on a sheet.

I guess I should've read the README carefully because you mention it there... I'm sorry @douglashill 😞

Neither of these would work for SFSafariViewController so I think the best option would be to provide a subclass that adds a key command for dismissing it.

That's what I had in mind but you don't expose most of the Sugar/API that would allow me to create it easily. Do you rather expose the API or create a KeyboardSafariViewController here? I can help you with whatever you decide!

douglashill commented 4 years ago

This isn’t at all specific to your app. It’s something that ideally SFSafariViewController would provide out if the box. Therefore KeyboardKit should provide a subclass.

Want to take over making a PR?

The question is, is this more of a back action or a close action?

Tapping Done is most like close, but swiping from the edge is more like back. When the user has some navigation history, the swipe from the edge gesture goes back in web history instead.

I’m thinking for a first pass just have cmd-W to dismiss? A possible extension would be to support a back command (cmd-left/right or cmd-[/] depending on RtL) if there’s no navigation history. If it’s even possible to detect this.

What do you think?

pedrommcarrasco commented 4 years ago

I can give it a shot, but I've been pretty busy lately so it'll probably take me some time.

Regarding the "requirements", they look fine to me but I don't think we can check the navigation history according to Apple's docs

The user's activity and interaction with SFSafariViewController are not visible to your app, which cannot access AutoFill data, browsing history, or website data

So we should probably only handle the dismissal and since we can present it in a "modal" or "push" flow we should probably allow both shortcuts, no?

douglashill commented 4 years ago

No pressure. It's your feature request so you set the timeline.

It might be possible somehow by virtue of the Safari VC not handling the event but I think that's pretty unlikely to be the case.