Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8346] iOS: "open" event fires multiple times at startup, plus whenever focused when using NavigationGroup

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2012-07-12T03:40:34.000+0000
Affected Version/sRelease 1.8.2
Fix Version/sRelease 2.1.0, Sprint 2012-08
ComponentsiOS
Labelsapi, ios, module_navgroup, parity, qe-testadded, regression
ReporterShawn Lipscomb
AssigneeVishal Duggal
Created2012-02-09T13:46:29.000+0000
Updated2013-11-27T12:15:07.000+0000

Description

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.

Comments

  1. Shawn Lipscomb 2012-03-28

  2. Junaid Younus 2012-03-28

    I can confirm that the issue related to step 6 still exists. I have moved this ticket to the appropriate section.
  3. Vishal Duggal 2012-04-13

    Pull pending https://github.com/appcelerator/titanium_mobile/pull/2004
  4. Shawn Lipscomb 2012-04-17

    Verified fixed in SDK 2.1.0.v20120416160358. Thanks!
  5. Michael Pettiford 2012-06-19

    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
  6. Shyam Bhadauria 2012-07-12

    Re-opening to edit label
  7. jithinpv 2013-11-27

    Anvil test case added. PR link: https://github.com/appcelerator/titanium_mobile/pull/5038

JSON Source