Description:
A window inside a tab group is present. On swiping to the right or left, this window needs to be replaced with another one. The way this is supposed to be accomplished, is by opening a new window in the same tab stack and close the current window at the same time. Because it cannot happen at the same exact time, the next window is said to open before the current window closes.
The problem:
To make this happen smoothly, the animation of the window open or close is removed by: tab.open( win, { animated: false });
But, if the current window is closed _after_ the next window opens, then nothing happens. If the current window is closed _before_ the it works, but there is a small flicker.
Note: The current window will close and the next will open with the sample test case, but if the current window is the root window, it will not close. It looks like the root window cannot be closed.
The code
// Global Object
var App = {};
function log(a) {
Ti.API.info(a);
}
/**
* Creates a new window with a colored box
* @param {String} color
* @return Ti.UI.Window
*/
function Window(color) {
log('Window created: '+color);
var win = Ti.UI.createWindow({
fullscreen: false,
backButtonTitle: '' // for our workaround, remove the back button
});
var box = Ti.UI.createView({
width: '300dp',
height: '300dp',
backgroundColor: color
});
win.addEventListener('swipe', function(e){
log('swipe');
if(e.direction == 'left') {
log('left');
// work around:
// close the window in the tab with no animation before opening the next
// side effect, root window cannot be closed
App.Tab.close(win, {animated: false});
log('add to tab');
App.Tab.open(Window('green'), {animated: false});
// old code
// uncomment to see the bug
// win.close();
} else {
log('right');
// work around:
// close the window in the tab with no animation before opening the next
// side effect, root window cannot be closed
App.Tab.close(win, {animated: false});
log('add to tab');
App.Tab.open(Window('red'), {animated: false});
// old code
// uncomment to see the bug
// win.close();
}
});
win.add(box);
return win;
}
/**
* Starts the app!
*/
(function(){
App.TabGroup = Ti.UI.createTabGroup();
App.Tab = Ti.UI.createTab({
window: Window('blue')
})
App.TabGroup.addTab(App.Tab);
App.TabGroup.open();
})();
Can not close the root window of a tab. Obviously the developer is trying to open windows in a tab but does not want the nav controller functionality. Can be done by creating a dummy window as root window of tab and then just opening and closing regular windows ( Ideally you should just be swapping out views instead of windows. So replace win.open() with win.add() ) Use this code to accomplish the same
Closing as invalid