Feature
Expose a currentWindow feature for a tab so that developers can access the visible window on the tab's stack.
Expected Behavior
Whenever a window is opened on the tab, currentWindow would point to the newly opened window. The same applies to whenever you close a window: through clicking a back button, programmatically calling tab.close(someWindow), or tapping the tab's button.
Why This Is Necessary
The end goal of this is to be able to pop back to the root window of a tab group, cleaning up and closing each window along the way. By exposing currentWindow, we give developers access to data we have internally already.
Why Name It "currentWindow"?
For parity with Ti.UI.currentWindow.
Sample Implementation
-(id)currentWindow
{
return [current window];
}
Sample Documentation
...
- name: window
description: the root level tab window. all tabs must have at least one root level tab window.
type: Titanium.UI.Window
- name: currentWindow
description: The currently visible window in the tab; the window that was last opened in this tab.
type: Titanium.UI.Window
permission: read-only
...
Sample Consuming Code
Drop the following in an app.js. Touch "S1: Touch Me" and a series of windows will be popped on to the tab's stack. Then hit "S2: Touch Me", and the code will utilize the new currentWindow property to cascade back to the root window.
function openWindowOnStack(i) {
var win = Ti.UI.createWindow({
title: 'Window ' + i,
rightNavButton: Ti.UI.createButton({ title: 'S2: Touch Me' })
});
win.rightNavButton.addEventListener('click', function() {
popToRoot();
});
win.addEventListener('open', function() {
Ti.API.info('Opened: ' + tab.currentWindow.title);
if (i < 4) {
openWindowOnStack(i + 1);
}
});
win.addEventListener('close', function(evt) {
Ti.API.info('Closed: ' + evt.source.title);
if (evt.source.cascadeClose && !tab.currentWindow.rootWindow) {
tab.currentWindow.cascadeClose = true;
tab.close(tab.currentWindow, { animated: false });
}
});
tab.open(win);
}
function popToRoot() {
tab.currentWindow.cascadeClose = true;
tab.close(tab.currentWindow, { animated: false });
}
var outer = Ti.UI.createWindow({
title: 'Root Window',
rightNavButton: Ti.UI.createButton({ title: 'S1: Touch Me' }),
rootWindow: true
});
outer.rightNavButton.addEventListener('click', function() {
openWindowOnStack(0);
});
var tabGroup = Ti.UI.createTabGroup();
var tab = Ti.UI.createTab({
window: outer
});
tabGroup.addTab(tab);
tabGroup.open();
Ti.UI.currentWindow is immutable. It is injected into the JS context that the window was opened with.
I'm not asking for Ti.UI.currentWindow, but a new property on the tab itself. Ti.UI.createTab({}).currentWindow. Make sense?
At best, this is only going to add to confusion. CurrentWindow refers to the window which owns the context that is executing the javascript, NOT the visible window. At this late in the game, I feel very uncomfortable adding an API without giving it deep thought, especially if we have to support it in later versions. If this functionality is needed, it should be with a better and more consistent metaphor in 1.9.
I trust your judgement. I've updated the example with a full JavaScript workaround that will hold the tab group in a consistent state, so long as the three guidelines at the top of the JavaScript are followed:
While I agree that there is a need, I do want to think about this, especially for parity's sake. We have the opportunity to have multiple classes to have the same design pattern. For iOS, the Root view, tab group, navGroup, and individual tabs (while they have navGroups built in on iOS) all have the same concept of having many windows, with only one visible at a time. On Android, there are some differences, so this should be addressed in planning.
Resolving as
Won't Fix
, since theTi.UI.currentWindow
went away in 6.0.0 as well when removing theTi.UI.Window.url
property.Closing old "Won't fix" tickets. If you disagree, please reopen.