Project: titanium
Issue TIMOB-8314: iOS: Close event is not firing when closing a window
h4. Problem description I have a NavigationGroup, and two windows. Intermittently, when the second window is closed, the first window goes comatose (won't respond to any clicks). h4. Actual results the window is not throwing the close event when closing. h4. Expected results the window should throw the close event when closing h4. Test case 1. Create a mobile project 2. Add this three files {code:title=app.js|borderStyle=solid} var FirstWindow=Ti.UI.createWindow({ url:'MOMain.js', layout:'vertical', navBarHidden:false }); Ti.App.NavGroup=Ti.UI.iPhone.createNavigationGroup({window:FirstWindow}); var NavBase=Ti.UI.createWindow(); NavBase.add(Ti.App.NavGroup); NavBase.open(); // this opens the "root" window, which is FirstWindow, automatically {code} {code:title=MOMain.js|borderStyle=solid} var MainWin=Ti.UI.currentWindow; function OnFocus(evt) { if (evt.source == MainWin) { Ti.App.CurrentWindow=MainWin; } } MainWin.title='Here is something'; Ti.App.CurrentWindow=MainWin; MainWin.addEventListener('focus',OnFocus); function SetupButtonClick() { var SecondWin=Ti.UI.createWindow({ url:'MOSetup.js', layout:'vertical', navBarHidden:false }); Ti.App.NavGroup.open(SecondWin,{animated:true}); } var SetupButton=Ti.UI.createButton({width:200, height:100, title:'Hit Me'}); SetupButton.addEventListener('click',SetupButtonClick); MainWin.add(SetupButton); {code} {code:title=MOMain.js|borderStyle=solid} var Win2=Ti.UI.currentWindow; function HandleiPhoneCloseEvent() { if (Ti.App.DevelopmentMode) Ti.API.info('# Window HandleiPhoneCloseEvent fired'); Win2.removeEventListener('close',HandleiPhoneCloseEvent); Win2=null; // attempt to release the window's memory } Win2.title='Window 2'; Ti.App.CurrentWindow=Win2; Win2.addEventListener('close',HandleiPhoneCloseEvent); // catches the iPhone NavGroup back button close {code} 3. Run the app 4. Click on the "Hit Me" button 5. Click the navgroup's back button 6. Try to click on the "Hit Me" button again h4. Extra info This seems to be timing dependent, so you may have to repeat the 2 clicks several times. I can make it happen in under 30 seconds...usually within 5 seconds. My best reproduction comes by waiting 2.5 seconds before clicking the back button. If you have trouble reproducing this, vary the time between seeing the second window and clicking the back button (faster and then slower). After some investigation, I can see that the 'close' event of the second window never fires when the problem occurs (neither does the focus event of the first window). This seems to point to a serious flaw. In a larger app, the failure occurs 80% of the time. Our app is totally dead in the water because of this, and we need to release it soon. Can you please take a look into this? Please note that I've reduced this down about as far as possible, while still demonstrating the error. Removing any of the references to Ti.App or removing any of the event listeners hides the problem, but all of my apps are dependent on these.
Story points: 3