如何从 react-native webview 中获取选择对象 [英] How to get selection object from react-native webview

查看:55
本文介绍了如何从 react-native webview 中获取选择对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用,我在其中使用 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.

如何将选择对象从 webview 导入我的应用程序?

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

推荐答案

从 0.37.0 开始,RN 中有一项新功能可能会对您有所帮助.WebView 中有一个新道具:onMessage 以及一种新的方法,postMessage 可以实现双向通信.您必须从 WebView 调用 window.postMessage,它会调用您定义为 onMessage 回调的函数.您可以在文档中查看完整示例.至于获取所选文本,请查看此答案.

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.

这篇关于如何从 react-native webview 中获取选择对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆