openwebf / webf

Build flutter apps with HTML/CSS and JavaScript.
https://openwebf.com/
Apache License 2.0
1.66k stars 122 forks source link

android addJavascriptInterface兼容 #631

Closed Tlanglord closed 4 months ago

Tlanglord commented 4 months ago

Affected version

v0.16.0

No same issues found

Bug type

JavaScript

Which frontend framework you are using.

No response

Steps to reproduce

android中h5通信,android侧调用addJavascriptInterface(xxx, androidObj)注册 ,js侧调用 window.androidObj.func()方式和native通信,在现有的方案上是否能提供更好的方式,不用修改原有的逻辑

Code example

No response

Expected results

不修改h5 js侧原有逻辑,还是基于window.androidObj.func()

Actual results

andycall commented 4 months ago

目前只有 Dart < --> JS 的通信方案,你可以按照下面的思路来:

  1. 用 Flutter 的 methodChannel 实现 Java 与 Dart 的通信
  2. 按照下面的教程实现 Dart 与 JS 的通信 https://openwebf.com/docs/tutorials/guides-for-flutter-developer/dart_js_intercommunication
  3. 将 webf.methodChannel 的 API 再用 JS 封装一下,包装成 window.androidObj.func()