Closed jibon57 closed 4 years ago
At present I am reloading the view on navigatingFromEvent
like this:
let t = this;
this.page.on(Page.navigatingFromEvent, function (data) {
t.page.off(Page.navigatingFromEvent);
t.webViewExt.reload();
})
I think there should be some other good way..
Views/Page are not destroyed in NativeScript when you forward navigate to another page, I guess that's why it keeps playing.
You might be able to solve it like this (not tested):
this.page.on(Page.navigatingFromEvent, function (data) {
if (this.webViewExt) {
this.webViewExt.executeJavascript(`var els = document.querySelectorAll(\"video\"); for (var i = els.length - 1; i >= 0; i--) { els[i].pause(); };`);
}
}, this)
@m-abs thank you. Is there any other way to destroy the page? Or webViewExt
view?
@jibon57
It's beyond the scope of this plugin, but you could try to set visibility=colapsed
on navigating from and reset it to visibility=visible
, that should destroy the native webview, but also the current state and history.
I'm having the same issue. I have a <Page>
with a <WebViewExt>
component (nativescript-vue) where I load an HTML file that plays a sound every fifth second (using setInterval
within the loaded HTML file). When I leave the page by backward navigating, using $navigateBack
, the sound keeps playing every fifth second. If i navigate forward to the Page again, and then back, the sound now plays twice every fifth seconds.
When I add a console.log()
to the beforeDestroy
hook of my Page component, I can see that it gets called. For some reason the WebViewExt
instance is kept alive somewhere.
EDIT: This is on iOS btw.
Thanks to @heyman I've published v7.0.2 with a fix for this problem. Thank you for identifying the cause and providing a fix.
Which platform(s) does your issue occur on?
Please, provide the following version numbers that your issue occurs with:
tns --version
to fetch it) ✔ Getting NativeScript components versions information... ⚠ Update available for component nativescript. Your current version is 6.4.0 and the latest available version is 6.4.1. ✔ Component tns-core-modules has 6.4.1 version and is up to date. ✔ Component tns-android has 6.4.1 version and is up to date. ✔ Component tns-ios has 6.5.0-2020-02-19-163529-01 version and is up to date.Please, tell us how to recreate the issue in as much detail as possible.
I was trying to play audio file from a website which was using HTML5 audio tag. When I navigated to another page of my APP audio was keep playing. How can I destroy it properly?
Thanks