Nagender Singh Nagender Singh - 1 year ago 232
iOS Question

How to get selection object from react-native webview

I have an app where I'm using react-native webview to display a document.

The user can select some text and perform some custom action that I provide.

How do I get the selection object from webview into my app?

Answer Source

From 0.37.0 onwards there is a new feature in RN that might help you. There is a new prop in the WebView: onMessage and also a new method, postMessage that enable two-way communication. From the WebView, you have to call window.postMessage, and it will invoke the function that you define as callback for onMessage. You can see a full example in the documentation. As for getting the selected text, check out this answer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download