各位大神们,react 与原生客户端 webview 的交互有 demo 么?比如我用WebViewJavascriptBridge简单实现了和 iOS 客户端的交互,但是不知道怎么和 react 整合在一起?
谢谢了~
PS:暂时使用的是 react,非 react-native。暂时针对的是 iOS 平台。
高洛峰2017-04-17 17:53:55
Now that you have implemented the interaction between WebViewJavascriptBridge and the front end, just treat it as an ordinary js call. It has nothing to do with whether you use react or not.
The interaction between native and js is actually just exposing some methods. Native is exposed on the WebViewJavascriptBridge object, while js is usually exposed on the window object (because I have dealt with the interaction between the front end and the App, so I know that it can It does not have to be exposed on the window object, you can customize an object). What you call integration with react here, I don't know if you mean, native directly calls the react.xxx method.
What I just said can be exposed to custom objects. Of course, it can also be exposed to native through react objects. However, this is not recommended. There are mainly the following reasons:
1. This can easily cause coupling or even conflict with react;
2. In fact, I don’t even recommend directly exposing methods on the front end for native calls (unless necessary). Because the efficiency of native calling front-end methods is very low (especially Android, compared with front-end calling native methods). I recommend using callbacks so that native does not rely on front-end methods.
It should be noted that the react you are talking about here should be React.js, not React Native.
黄舟2017-04-17 17:53:55
If you are talking about the webview encapsulated by React Native, unfortunately, there is no direct interaction with js. You can only use url hash. iOS can intercept the jump request and Android does not support it for the time being.
But it seems that there is a third Three-party webview that supports js interaction