Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8868] Android: Ti.UI.Window issue with orientation modes in latest SDK

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionCannot Reproduce
Resolution Date2012-06-13T14:28:28.000+0000
Affected Version/sRelease 2.0.0
Fix Version/sn/a
ComponentsAndroid
LabelsRegression, SupportTeam, core
ReporterJunaid Younus
AssigneeBill Dawson
Created2012-04-23T17:26:31.000+0000
Updated2017-03-27T18:24:14.000+0000

Description

*Code*
 
Titanium.UI.setBackgroundColor('white');

var openWinInLandscape = function() 
{
	var win = Titanium.UI.createWindow({  
	    backgroundColor:'yellow',
	    orientationModes: [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT] // works fine
	});
	
	/*win.addEventListener('close', function(e) 
	{
		Ti.App.fireEvent('setOrientationMode');
	});*/
	
	return win;
}

var tabGroup = Titanium.UI.createTabGroup();

var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff',
    fullscreen: false,
    orientationModes: [Ti.UI.PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT] // doesn't work
});

var tab1 = Titanium.UI.createTab({  
    icon:'KS_nav_views.png',
    title:'Tab 1',
    window:win1
});

var button = Ti.UI.createButton({
	title: 'Press me!',
	width: 300,
	height: 40
});
button.addEventListener('click', function(e)
{
	var newWin = openWinInLandscape();
	tab1.open(newWin);
});

/*Ti.App.addEventListener('setOrientationMode', function(e) {
	Ti.API.info('Global event fired: orientation activated');
	win1.orientationModes = [Ti.UI.PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]; // doesn't work
});*/

win1.add(button);
tabGroup.addTab(tab1);  
tabGroup.open();

*Issue* The code above has two separate ways ways to change the orientation of the window. They both dont seem to work, try it the way it currently is, then also try running the code by uncommenting the two other sections. *Expected behavior* No matter which way you decide to use, it should change the orientation of the window. *Actual behavior - 1* If you run the above code the way it is right now, the app doesn't change orientation. When you press the button, it will force open a new window in landscape mode (which works fine). Then when you press the back button, it should reset and be back its orientation, but it doesn't. It will still be stuck in landscape mode. *Actual behavior - 2* Now if you uncomment the two sections in the code, you will see that the same problem still exists. It does fire the global event (output can be seen in DDMS), however the changes are not reflected by the window. *Workaround*
Titanium.UI.setBackgroundColor('white');

var openWinInLandscape = function() 
{
	var win = Titanium.UI.createWindow({  
	    backgroundColor:'yellow',
	    orientationModes: [Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT] // works fine
	});
	
	return win;
}

var tabGroup = Titanium.UI.createTabGroup();

var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff',
    fullscreen: false
});

win1.addEventListener('click', function(e)
{
	Ti.API.info('Orientation activated');
	win1.orientationModes = [Ti.UI.PORTRAIT, Ti.UI.LANDSCAPE_LEFT, Ti.UI.LANDSCAPE_RIGHT]; // workaround
});

var tab1 = Titanium.UI.createTab({  
    icon:'KS_nav_views.png',
    title:'Tab 1',
    window:win1
});

var button = Ti.UI.createButton({
	title: 'Press me!',
	width: 300,
	height: 40
});
button.addEventListener('click', function(e)
{
	var newWin = openWinInLandscape();
	tab1.open(newWin);
});

win1.add(button);
tabGroup.addTab(tab1);  
tabGroup.open();
The above code is a workaround of how it is supposed to work. You first have to tap anywhere on the white window, in order for it to execute the code. Once that is done, you can see that whenever you open the new yellow window, it's forced in landscape mode. If you now press the back button, you will see that the orientation is reset and assigned to the correct window object. It works just as expected and the white window changes orientations correctly! *Issue A in the workaround* If you change the event listener from 'click' to 'open', you will see that the first time the app is run, the window behaves correctly. Then when you open the yellow window and press the back button, you will see that the orientation has been locked into landscape mode and doesn't work as expected. *Issue B in the workaround* If you change the event listener from 'click' to 'focus', you will see the same behavior as in Issue A, with the exception that it doesn't seem to fire the focus event when you press the back button on the yellow window. *Notes* -Only tested on a HTC Sensation 4G. -Some of these issues don't seem to exist prior 2.0 SDK.

Comments

  1. Bill Dawson 2012-06-13

    I believe this was fixed recently via other work. Tested successfully on HTC Desire (2.2), Droid 2 (2.3), G-Slate (3.1). I believe the Sensation 4G is 2.3. Was indeed able to reproduce the fail case with the older version of our SDK from April, but not with current Titanium SDK 2.1.0.
  2. Lee Morris 2017-03-27

    Closing ticket as I am unable to reproduce this issue with the following environment; Pixel (7.1) MacOS 10.11.6 (15G31) Studio 4.8.1.201612050850 Ti SDK 6.0.3 GA Appc NPM 4.2.8 Appc CLI 6.1.0 Ti CLI 5.0.11 Alloy 1.9.5 Arrow 1.10.1 Xcode 8.2 (8C38) Node v4.6.0 Java 1.7.0_80

JSON Source