Problem
Executing code against views in mobileweb from the view's containing window's
open
event does not ensure that the view has completely loaded. I would expect for mobileweb that the
Window.open
event would be much like jQuery's
ready
, meaning that you are free to start manipulating the elements contained within it. This is not the case.
Test Case
All of the properties of
view
in this test case will animate from zero. I assume this is because the view's properties are not fully loaded when the
window.open
event fires. The comments portion with the
setTimeout
call will execute as expected, albeit with a 2 second delay.
var win = Ti.UI.createWindow({
backgroundColor: '#fff',
fullscreen: false,
exitOnClose: true
});
var view = Ti.UI.createView({
backgroundColor: '#a00',
height: 100,
width: 100,
top: 500,
left: 500
});
var anim = Ti.UI.createAnimation({
duration: 5000,
top: 10,
left: 10
});
win.add(view);
win.addEventListener('open', function(e) {
// All of the view's properties will animate from zero, not the
// values specified above in its creation
view.animate(anim);
// This code will work
// setTimeout(function() {
// view.animate(anim);
// }, 2000);
});
win.open();
Proposed Solution
Have
Window.open
fire only when it and all of its child components have also loaded. This way developers can be assured that all necessary manipulations are safe in the
open
event.
After some discussion, the behavior for the window.open event is actually correct, however animation need to deal with this situation. In short, the bug is in animation, not window.open.
Pull Request: https://github.com/appcelerator/titanium_mobile/pull/1832
Closing ticket as MobileWeb is no longer supported.