shripalsoni04 / nativescript-webview-interface

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

Native listener stop working #7

Closed ghost closed 8 years ago

ghost commented 8 years ago

Hi guys, i was using your webview interface and i have a problem; ive got a native view (view0) with a grid layout, 90% dedicated to a webview an 10% dedicated for various labels and a button which call a function to navigate to another native view (view1). Ive managed to setup the webview interface and ive tried to make a "emit-on" loop between view0 and webview; everything works, i send and WebInterface.emit from native view0, the WebInterface.on method inside the webview catch it and calls a WebInterface.emit which is correctly received from native view0's WebInterface.on method, which automatically call the emit method again (and so on...). The loop works good, ive set it to make complete loop (emit-on-emit-on) every 500 ms. But when i press the button to switch to view1, the WebInterface.on inside the native view0 stop working, even when i navigate back to view0 (which render again the webview and restart all listeners). If i emit something to webview from native view0, the on method inside it works well; but if emit from webview to native view, the native on method doesnt catch the emit. No errors in log.
Also ive noticed this; when im inside the webview (with loop working correctly) if i step back to the main view and then i open again view0 which render webview, the loop works; only when i navigate to view1 (or other native view) from webview, the WebInferface.on native method stop working.

You can find the view0 and webview files attached. Thanks for the help. view0.js.txt view0.xml.txt webview.html.txt webview.js.txt

ghost commented 8 years ago

Ok ive found a workaround to the problem; use frameModule.topmost().android.cachePagesOnNavigate = true; without stopping listeners (.on)

shripalsoni04 commented 8 years ago

Glad to know that you found an alternative.

I tried to replicate your scenario on my sample app.

In my sample app, I have main page with webview in it. I added one button on it and on click of that button, I opened another page. Now when I navigated back to the page with web-view, the bidirectional communication between web-view and nativescript is working fine.

I checked you code, but I am not getting it properly where the issue is, as there are many conditions. It will be great help if you can just fork my sample app and add some basic code which creates the issue you mentioned.

Thanks.

ghost commented 8 years ago

Hi, thanks for answer! I've forked your app and added to main-page (just js, not using ts) a button to navigate to another basic view (test). After you step back to main from test view, the 'on' native method stop working, as in my app.

Thanks for help!

shripalsoni04 commented 8 years ago

Hi,

Thanks for updating the sample app. This helped me to understand what and where is the issue.

I have resolved the issue and you can get the updated code at 1.3.4 version.

I have also updated the sample app to show how it works when using this plugin with navigation.

Thanks.

ghost commented 8 years ago

Thank you! I'll check it out as soon as I can!

ghost commented 8 years ago

Hi, sorry for late answer, I'll tried it, everything works now! Thank you!