Problem
The "open" event of a window fires 3 times when first opened, then whenever the window re-receives focus (when navigating back to it using a NavigationGroup), the "open" event fires again.
Expected Result
The "open" event should only fire once...when it is first opened, period. And it should not fire when the window re-receives focus.
Steps to Reproduce
drop the following app.js code into a new project
build with SDK 1.8.1
run in the iPhone simulator. You will see:
[INFO] One moment, building ...
[INFO] Titanium SDK version: 1.8.1 (01/27/12 17:31 a24502a)
[INFO] iPhone Device family: iphone
[INFO] iPhone SDK version: 5.0
[INFO] iPhone simulated device: iphone
[INFO] Launching application in Simulator
[INFO] Launched application in Simulator (3.78 seconds)
[INFO] Found 5.0 patch installed
[INFO] Application started
[INFO] NavGroupFocusTest/1.0 (1.8.1.a24502a)
[INFO] rootWin OPEN fired
[INFO] rootWin OPEN fired
[INFO] rootWin OPEN fired
Say to yourself: "Why did OPEN fire 3 times?!?!?!?!?!"
click the "open new window" button and watch the console log. You will see:
[INFO] 2nd wind
click the "back" button and watch the console log. You will see:
[INFO] rootWin FOCUSED
[INFO] rootWin OPEN fired
Say to yourself: "Why did OPEN fire again?!?!?!?!?!"
Repeat steps 5, 6, and 7 and continue to get the same result until you're bored with this game.
Testcase
var rootWin = Ti.UI.createWindow();
rootWin.addEventListener('focus', function()
{
Ti.API.info("rootWin FOCUSED");
});
rootWin.addEventListener('open', function()
{
Ti.API.info("rootWin OPEN fired");
});
var btnOpenWin = Ti.UI.createButton({
title : "open new window",
width : 200,
height : 35
});
btnOpenWin.addEventListener('click', function()
{
var win2 = Ti.UI.createWindow();
ng.open(win2, {animated:true});
Ti.API.info("2nd wind");
});
rootWin.add(btnOpenWin);
ng = Ti.UI.iPhone.createNavigationGroup({window:rootWin});
var NavBase = Ti.UI.createWindow();
NavBase.add(ng);
NavBase.open(); // this opens the "root" window, automatically
In a larger project, sometimes when you go "back" to the main window, no events fire at all (no focus, no open). I would expect the focus event to fire each time. Just something to keep in mind while you're looking into the code, as I haven't been successful in reproducing this in a small testcase.
I can confirm that the issue related to step 6 still exists. I have moved this ticket to the appropriate section.
Pull pending https://github.com/appcelerator/titanium_mobile/pull/2004
Verified fixed in SDK 2.1.0.v20120416160358. Thanks!
Closing issue Tested with Ti Studio build 2.1.0.201206172244 Ti Mobile SDK 2.1.0.v20120618154152 hash r7830c03d OSX Lion 10.7.3 iPhone 4S OS 5.1 The expected behavior is shown
Re-opening to edit label
Anvil test case added. PR link: https://github.com/appcelerator/titanium_mobile/pull/5038