[TIMOB-17027] iOS: The webview reloads on being removed and re-add to a window
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2014-06-06T17:26:36.000+0000 |
Affected Version/s | Release 3.3.0 |
Fix Version/s | n/a |
Components | iOS |
Labels | qe-3.3.0, regression |
Reporter | Satyam Sekhri |
Assignee | Vishal Duggal |
Created | 2014-05-26T09:39:45.000+0000 |
Updated | 2017-03-22T23:04:18.000+0000 |
Description
The webview reloads when re-added to a window after being removed.
This is a regression as the issue does not occur on 3.2.3. Also the issue does not occur on Android.
Steps to Reproduce:
1. Run the application
2. Click on the "remove and add webview" button
3. Click on the "remove and release and add webview" button
Actual Result:
The webview gets loaded at all the three steps. The alert "The webview is loaded" is shown on all the three steps
Expected Result:
The load event of webview should not be called when it is simply removed and re-added.
var win=Ti.UI.createWindow({backgroundColor:'white'});
var webview = Ti.UI.createWebView({
html : '<html><head></head><body><script>var now = Date.now(); document.body.innerHTML = now;</script></body></html>',
top : 0,
height : 200
});
webview.addEventListener('load', function() {
alert('The webview is loaded!');
});
var b = Ti.UI.createButton({
title : "remove and add webview",
top : 210
});
b.addEventListener("click", function() {
win.remove(webview);
win.add(webview);
});
var b2 = Ti.UI.createButton({
title : "remove and release and add webview",
top : 280
});
b2.addEventListener("click", function() {
win.remove(webview);
webview.reload();
win.add(webview);
});
win.add(webview);
win.add(b);
win.add(b2);
win.open();
This is an expected change in behavior on the iOS platform. The old behavior was that when you removed a child from a parent we would mark the JS object ready for GC and the view would be destroyed when the proxy was collected. In 3.3.0 we became more aggressive with the memory cleanup. Essentially when you remove a child from a parent we not only mark the JS object ready for GC but also send the detach message to the proxy so the view is immediately collected. So when you remove and readd, the view object is recreated and hence the load function gets called again. Marking this as Won't Fix.
I understand the aggressive approach. However, if a view is added to a new parent (a currently opened but obscured window) and then removed from the current parent, it is not garbage and so should not be collected. I expected the view to still be available (ie. not reloaded) when the new parent becomes the top window. If this is the expected behaviour in 3.3.0, is there a workaround to get the old behavior?
Closing ticket as "Won't Fix".