shripalsoni04 / nativescript-webview-interface

Plugin for bi-directional communication between webView and android/ios
MIT License
89 stars 35 forks source link

Doesn't work with Android #12

Closed juneil closed 6 years ago

juneil commented 7 years ago

Hi,

I have this error when I use this plugin with Android

TypeError: Cannot read property 'getSettings' of undefined
JS:     at WebViewInterface._initWebView (file:///data/data/.../files/app/tns_modules/nativescript-webview-interface/index.js:47:51)
JS:     at new WebViewInterface (file:///data/data/.../files/app/tns_modules/nativescript-webview-interface/index.js:39:14)
JS:     at AudioService.init (file:///data/data/.../files/app/shared/services/audio.service.js:21:21)

the 'android' property from the webview native element is undefined...

Any idea ? Thanks

mauriciomelo commented 7 years ago

same for me.

armackey commented 7 years ago

same

armackey commented 7 years ago

Weird thing is, if you clone the repo it'll work. I've been trying to find the differences.

juneil commented 7 years ago

Well I guess it s the version of Nativescript

mauriciomelo commented 7 years ago

Seems like a timing issue. Instantiating the interface after the WebView.loadedEvent event seems to fix it. Example:

let webView: WebView = this.webView.nativeElement;
webView.on(WebView.loadedEvent, () => {
  this.oWebViewInterface = new WebViewInterface(webView, 'url');
});
shripalsoni04 commented 7 years ago

Hi,

I am not able to reproduce the issue on my Android phone (version 6.0) and on emulator (version 5.0). But as @mauriciomelo stated, the issue may come if new WebViewInterface(webView, 'url') is getting called before android instance is attached to nativescript webview object.

I have done changes in plugin, so it will initialise android related settings only once android webview is loaded. The patch is released in version 1.4.1

As I am not getting this issue, can anyone please test this issue on latest version of plugin and confirm if it is resolved or not.

Thanks.

juneil commented 7 years ago

Hi,

Works fine with v 1.4.1

Thanks