[TIMOB-27241] iOS: WebView html fails to reload local JavaScript after unload
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | n/a |
Labels | n/a |
Reporter | Teun Klijn |
Assignee | Eric Merriman |
Created | 2019-06-20T13:44:53.000+0000 |
Updated | 2019-11-19T15:27:51.000+0000 |
Description
*Describe the bug*
I've a WebView in a ScrollableView. The WebView loads a local html file and a js file. When you scroll to the 3rd or 4th view the WebView will unload its content and it will be reloaded when you go back to the 1st view. This was working fine before 8.0.0.GA. But starting 8.0.0.GA the local JavaScript functions aren't available in the html file after the reload.
*To Reproduce*
Press 'Tab 5'
Press 'Tab 1'
Read the console output
+assets/html/test.html+
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=200">
<script type="application/javascript" src="test.jslocal"></script>
<script>
function talk(args) {
Ti.API.info('talk to me! ' + typeof myFunction);
}
function init() {
Ti.App.addEventListener('app:talk', talk);
window.addEventListener("unload", function () {
Ti.App.removeEventListener('app:talk', talk);
});
}
</script>
</head>
<body onload="init()"> </body>
</html>
assets/html/test.jslocal
function myFunction() {}
+views/index.xml+
<Alloy>
<Window>
<ScrollableView id="scroll" bottom="50" scrollingEnabled="false">
<View>
<WebView id="wv" url="/html/test.html" onLoad="onLoad" />
<Label text="Tab 1" />
</View>
<View>
<Label text="Tab 2" />
</View>
<View>
<Label text="Tab 3" />
</View>
<View>
<Label text="Tab 4" />
</View>
<View>
<Label text="Tab 5" />
</View>
</ScrollableView>
<View height="50" bottom="0" backgroundColor="e1e1e1" layout="horizontal">
<Button title="Tab 1" onClick="onTab1" width="20%" height="Ti.UI.FILL" />
<Button title="Tab 2" onClick="onTab2" width="20%" height="Ti.UI.FILL" />
<Button title="Tab 3" onClick="onTab3" width="20%" height="Ti.UI.FILL" />
<Button title="Tab 4" onClick="onTab4" width="20%" height="Ti.UI.FILL" />
<Button title="Tab 5" onClick="onTab5" width="20%" height="Ti.UI.FILL" />
</View>
</Window>
</Alloy>
+controllers/index.js+
function onTab1() {
$.scroll.currentPage = 0;
$.wv.reload();
// setting the url directly instead of a reload does work, but I don't want to do that
// $.wv.url = '/html/test.html'
}
function onTab2() {
$.scroll.currentPage = 1;
}
function onTab3() {
$.scroll.currentPage = 2;
}
function onTab4() {
$.scroll.currentPage = 3;
}
function onTab5() {
$.scroll.currentPage = 4;
}
function onLoad() {
Ti.App.fireEvent('app:talk');
}
$.index.open();
*Expected behavior*
The console output reads 'talk to me! function'
*Actual behavior*
The console output reads 'talk to me! undefined'
*Environment*
iOS; 8.0.0.GA; 8.0.1.GA; 8.0.2.GA
Hello, Thanks for sharing with us. Can you please share console logs and screenshot of the device which displays the issue?
Hello, I'm not sure what more I can share? I already shared the console output in the ticket. Currently the application doesn't display any error, I could edit the example application to display a color with the JavaScript which stops working after the unload if that helps you?
[~teunklijn@telfort.nl], Thanks for your feedback. Are you able to run this sample code properly? Please check again and share the runnable code. Getting error running that on iOS device using 8.0.2.GA SDK.
@rmitro The code is running without an error for me, the error that you are seeing is probably because the controller (index.js) implementation is incomplete. The view (index.xml) adds a listener to the webview for the load event, the controller should have this function.
Hello, I was able to verify the issue on SDK 8.0.2.GA in iOS following the steps above. The issue regenerated as described. Tested with CLi 7.0.12. Moving to TIMOB. Thanks.
I've noticed that it does work when I put all the files I want to load in the webview, in the root assets directory. This is less then ideal for me, because I'd like use subdirectories to orden my files. But maybe this helps with finding the cause of this problem.