小编jan*_*sky的帖子

ReactJS与本机Android中的Webview通信(未定义'Android'no-undef)

我已经在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)

android reactjs react-native

5
推荐指数
1
解决办法
711
查看次数

标签 统计

android ×1

react-native ×1

reactjs ×1