Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11169] iOS: Opening window in tab with animated false, stops closing the previous window

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2012-10-02T00:35:03.000+0000
Affected Version/sRelease 2.1.2
Fix Version/sSprint 2012-20 API, 2012 Sprint 20
ComponentsiOS
Labelscore
ReporterPedro Enrique
AssigneeVishal Duggal
Created2012-09-26T18:15:04.000+0000
Updated2013-03-13T18:55:34.000+0000

Description

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();
})();

Comments

  1. Vishal Duggal 2012-10-02

    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
       // 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,
           });
            
           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');
        
       			var newWin = Window('green');
                   newWin.open();
       			App.Tab.currentWin.close();
       			App.Tab.currentWin = newWin;
        
               } 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');
        			
       			var newWin = Window('red');
                   newWin.open();
       			App.Tab.currentWin.close();
       			App.Tab.currentWin = newWin;
               }
           });
       	
           win.add(box);
           return win;
       }
        
       /**
        * Starts the app!
        */
       (function(){
           App.TabGroup = Ti.UI.createTabGroup();
       	App.baseWin = Ti.UI.createWindow();
           App.Tab = Ti.UI.createTab({
               window: App.baseWin
           })
           App.TabGroup.addTab(App.Tab);
       
       	App.TabGroup.addEventListener('open',function(){
       		App.Tab.currentWin = Window('blue');
       		App.Tab.currentWin.open();
       	});
       	App.TabGroup.open();
       
       })();
       
  2. Natalie Huynh 2012-12-04

    Closing as invalid

JSON Source