Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12981] iOS: Closing subwindows in tabgroup does not close final window right away when selecting other tab

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterCarter Lathrop
AssigneeUnknown
Created2013-03-05T23:09:25.000+0000
Updated2018-02-28T20:03:47.000+0000

Description

*Problem* I've created a sample app with a tabgroup and a number of subwindows in each tab. I want the user to start at the root window of each tab when switching between those tabs. So, the window stack in each tab should not be maintained as is the default. I registered an event listener on each subwindow which closes this window on blur of the (previous) tab. This works, except that the last window (the one on top of the stack) is not closed at that time, but only after the user returns to this same tab again. I've added an example app which demonstrates the problem. *Actual Result* Below is the output with comments added Open app, open tab 1, click button to open subwindow 1/2, click button to open subwindow 1/3: [INFO] :   Focused tabgroup Tab 1 [INFO] :   Opened window Window 1/1 [INFO] :   Focused window Window 1/1 [INFO] :   Blurred window Window 1/1 [INFO] :   Opened window Window 1/2 [INFO] :   Focused window Window 1/2 [INFO] :   Blurred window Window 1/2 [INFO] :   Opened window Window 1/3 [INFO] :   Focused window Window 1/3 Subwindow 1/3 is now on the top of the stack. Click on tab 2: [INFO] :   Blurred window Window 1/3 [DEBUG] :  Firing app event: app:reset [INFO] :   Blurred tabgroup Tab 1 [INFO] :   Focused tabgroup Tab 2 My event listener fires on the two subwindows in tab 1: [INFO] :   Closing window Window 1/2 on app:reset [INFO] :   Closing window Window 1/3 on app:reset The close event arrives at Window 1/2, but not at Window 1/3 [INFO] :   Closed window Window 1/2 Tab 2 / window 2/1 opens [INFO] :   Opened window Window 2/1 [INFO] :   Focused window Window 2/1 Click again on tab 1, tab 2 blurs [INFO] :   Blurred window Window 2/1 [DEBUG] :  Firing app event: app:reset [INFO] :   Blurred tabgroup Tab 2 [INFO] :   Focused tabgroup Tab 1 Hey, why does my last subwindow in tab1 get focus, blur and close now? [INFO] :   Focused window Window 1/3 [INFO] :   Blurred window Window 1/3 [INFO] :   Focused window Window 1/1 [INFO] :   Closed window Window 1/3 Of course, from a user / UI / animation perspective the right things happen, but from a view hierarchy standpoint this is pretty undesirable. *Expected Behavior* would be (AFAICT): [INFO] :   Focused tabgroup Tab 1 [INFO] :   Opened window Window 1/1 [INFO] :   Focused window Window 1/1 [INFO] :   Blurred window Window 1/1 [INFO] :   Opened window Window 1/2 [INFO] :   Focused window Window 1/2 [INFO] :   Blurred window Window 1/2 [INFO] :   Opened window Window 1/3 [INFO] :   Focused window Window 1/3 [INFO] :   Blurred window Window 1/3 [DEBUG] :  Firing app event: app:reset [INFO] :   Blurred tabgroup Tab 1 [INFO] :   Focused tabgroup Tab 2 [INFO] :   Closing window Window 1/2 on app:reset [INFO] :   Closing window Window 1/3 on app:reset [INFO] :   Closed window Window 1/2 [INFO] :   Closed window Window 1/3 <--- Close this window now [INFO] :   Opened window Window 2/1 [INFO] :   Focused window Window 2/1 [INFO] :   Blurred window Window 2/1 [DEBUG] :  Firing app event: app:reset [INFO] :   Blurred tabgroup Tab 2 [INFO] :   Focused tabgroup Tab 1 [INFO] :   Focused window Window 1/1 *Test Case*
var tabGroup = Ti.UI.createTabGroup();

tabGroup.addEventListener("focus", function(event) {
	Ti.API.info("Focused tabgroup " + event.tab.title);
});

tabGroup.addEventListener("blur", function(event) {
	/* When blurring the tab, close all open (sub)windows */
	Ti.App.fireEvent("app:reset");
	Ti.API.info("Blurred tabgroup " + event.previousTab.title);
});

function createWindow(title, count, closeOnReset) {
	var win = Ti.UI.createWindow({
		title: title + "/" + count,
		backgroundColor: '#ffffff',
		backButtonTitle: 'Back',
	});
	
	win.addEventListener("open", function(event) {
		Ti.API.info("Opened window " + event.source.title);
	});
	
	win.addEventListener("focus", function(event) {
		Ti.API.info("Focused window " + event.source.title);
	});
	
	win.addEventListener("blur", function(event) {
		Ti.API.info("Blurred window " + event.source.title);
	});
	
	win.addEventListener("close", function(event) {
		Ti.API.info("Closed window " + event.source.title);
	});
	
	if (closeOnReset) {
		var reset = function (event) {
			Ti.API.info("Closing window " + win.title + " on app:reset");
			win.close({ animated: false });
			Ti.App.removeEventListener("app:reset", reset);
		}
				
		Ti.App.addEventListener("app:reset", reset);
	}
	
	var button = Ti.UI.createButton({
		title: 'Open ' + title + "/" + (count+1)
	});
	button.addEventListener("click", function (event) {
		tabGroup.activeTab.open(createWindow(title, count+1, true));
	});
	win.add(button);	
	
	return win;
};


/* Create three tabs and three root windows */
for (var i = 1; i <= 3; i++) {
	tabGroup.addTab(Ti.UI.createTab({
		title: 'Tab ' + i,
		/* Do not send app:reset on close of root window */
		window: createWindow('Window ' + i, 1, false)  
	}));
}

tabGroup.setActiveTab(0);
tabGroup.open();

Attachments

FileDateSize
app.js2013-03-05T23:09:25.000+00001775

Comments

No comments

JSON Source