我已经在ReactJS中编写了Web部件(不是React Native,这很重要)。我还有一个简单的Android应用程序,其中包含一个WebView,我在其中打开一个在ReactJS上运行的网站。在Android本机WebView(打开ReactJS网站)和ReactJS网站之间是否存在适当的通信方式?
我已经经历过这个Facebook React Native Communication,但这是React Native的模型案例。这意味着,在原生Android应用程序中通过ReactActivity扩展Activity等等都是没有用的……
这是ReactJS源代码,我想在其中执行JS调用Mobile.showToast("Test")(不仅在这里,在许多.tsx文件中),但没有编译。编译错误是'Mobile' is not defined no-undef:
import * as React from "react";
import {
Button,
} from "components";
class Login extends React.PureComponent {
public render() {
return (
<Fullscreen>
<Content>
<Button onClick={this.handleRedirect} fullWidth>
</Content>
</Fullscreen>
);
}
private handleRedirect = () => {
//Here I wanted to call JS call for Android JavascriptInterface interrogation
Mobile.showToast("Test");
};
}
export default Login;
Run Code Online (Sandbox Code Playgroud)
这是用于追加javascriptInterface + JS调用的源代码(在此示例中,仅调用是showToast):
webView.addJavascriptInterface(new …Run Code Online (Sandbox Code Playgroud)