Home:ALL Converter>WKWebview allowsLinkPreview to false breaks text selection

WKWebview allowsLinkPreview to false breaks text selection

Ask Time:2020-04-09T01:36:04         Author:Jon Brooks

Json Formatter

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.

Author:Jon Brooks,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/61106626/wkwebview-allowslinkpreview-to-false-breaks-text-selection
XSDCoder :

I encountered the same problem, and this is how I solved it.\n\nwkwebview.UIDelegate = self;\n\n\n...\n\n- (BOOL)webView:(WKWebView *)webView shouldPreviewElement:(WKPreviewElementInfo *)elementInfo API_AVAILABLE(ios(10.0)) {\n return NO;\n}\n",
2020-04-19T17:44:21
yy