2

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?

jwpfox
  • 5,124
  • 11
  • 45
  • 42

1 Answers1

1

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.

Community
  • 1
  • 1
martinarroyo
  • 9,389
  • 3
  • 38
  • 75