turbolinks / turbolinks-ios

Native iOS adapter for building hybrid apps with Turbolinks 5
MIT License
881 stars 92 forks source link

Disable Force-Touch/3D Touch preview on buttons/links #95

Closed michiels closed 7 years ago

michiels commented 7 years ago

In my Turbolinks iOS view when someone force touches on a button or link it first opens the preview and then goes to the link in external Safari browser. Can I disable this behaviour? It causes the app experience to break/give a less native experience.

According to https://developer.apple.com/reference/webkit/wkwebview/1415000-allowslinkpreview this behaviour is off by default, but this doesn't seem to be the case for Turbolinks iOS.

Does anyone know what's up?

benreyn commented 7 years ago

I just discovered this same thing is happening for our app. It doesnt look like the Basecamp app does this, meaning that there is some way to turn it off. (I work on our rails app, not the native app, so this may be a well known option to turn off for ios devs)

It also looks like the basecamp app has some special interactions on some links with force touch that I really like.

zachwaugh commented 7 years ago

In iOS 10, there is a WKUIDelegate method to disable this, which is what we do in Basecamp:

func webView(_ webView: WKWebView, shouldPreviewElement elementInfo: WKPreviewElementInfo) -> Bool {
    return false
}
benreyn commented 7 years ago

Is there any way to turn this off in earlier versions of iOS? Looks like our app is 9.0 or higher.

zachwaugh commented 7 years ago

According this this WebKit post, allowsLinkPreview is false by default on iOS 9 and enabled by default on iOS 10:

WebKit supports Peek and Pop as an easy way to preview links. Apps built against the iOS 10 SDK will have Peek and Pop link preview enabled by default, but the feature is not new; since iOS 9, WKWebView clients could opt into Peek-based link previews on 3D Touch-capable devices using the allowsLinkPreview property on WKWebView. When the allowsLinkPreview property is set to true, users can gently press on links to peek them, which loads the link in another view over the app and blurs the app in the background.

So setting allowsLinkPreview explicitly to false should disable on all versions of iOS, but I haven't tested that. I think that would be a reasonable default for Turbolinks.framework. I can't see many cases where you'd want that, and if so, you could override those properties/delegates to turn it back on