WKWebview allowsLinkPreview to false breaks text selection

十年热恋 提交于 2020-06-12 06:17:33

问题


We have an app that uses WKWebview, but sets allowsLinkPreview to false because we don't want link preview behavior. It seems that starting with iOS 13.4, on devices that don't have 3D touch functionality (older devices and newer iphone models), setting allowsLinkPreview to false also disables all text selection in the page! For our app, text selection is critically important.

I came up with this theory reading between the lines in the documentation:

In iOS this property is available on devices that support 3D Touch.

On devices running iOS 13 and later, people can use the touch and hold gesture to open a context menu, regardless of whether the device supports 3D Touch. On 3D Touch devices, the gesture can reveal the context menu more quickly.

It seems like a bug that disabling link preview disables all press and hold gestures in the webview.

The only workaround I've been able to come up with is to set allowsLinkPreview to true, and then disabling the context menu via the WKUIDelegate protocol. This disables the popup for clicked links, but does not disable the popup for clicked images. And, it still allows users to drag-drop the link into a split screen view in safari, which we do not want.

Any suggestions for how to completely disable link preview/context menu/drag-drop behavior while still allowing text selection would be appreciated!

UPDATE
Since I control the content of my app, I was able to disable press-hold of images by using the following css: -webkit-touch-callout: none; So my remaining problem is just to disallow drag interactions out of the app from the WKWebView.

UPDATE 2 Similarly, I was able to use -webkit-user-drag: none; to disable dragging of links, but it would still be useful to know a non-css fix for what seems to me like an Apple bug.


回答1:


I encountered the same problem, and this is how I solved it.

wkwebview.UIDelegate = self;

...

- (BOOL)webView:(WKWebView *)webView shouldPreviewElement:(WKPreviewElementInfo *)elementInfo API_AVAILABLE(ios(10.0)) {
    return NO;
}



回答2:


This may be related to a known Webkit bug that is presumably already fixed (as of this writing):

https://bugs.webkit.org/show_bug.cgi?id=210191



来源:https://stackoverflow.com/questions/61106626/wkwebview-allowslinkpreview-to-false-breaks-text-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!