Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16705] iOS: Orientation problem when slightly tilting forward/backward

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.2.2
Fix Version/sn/a
ComponentsiOS
Labelsreprod
ReporterIvan Skugor
AssigneeUnknown
Created2014-03-21T17:16:05.000+0000
Updated2018-02-28T20:04:01.000+0000

Description

There is a problem with "orientationchange", in some cases event is fired when orientation is not changed. To see that run this example code:

var win = Ti.UI.createWindow({
	backgroundColor: '#333'
});

var sidebar = Ti.UI.createView({
	right: 0,
	width: 100,
	backgroundColor: '#fff',
	visible: false
});

Ti.Gesture.addEventListener('orientationchange',function(e) {
	// get current device orientation from
	// Ti.Gesture.orientation
	Ti.API.info('Ti.Gesture.orientation');
	Ti.API.info(Ti.Gesture.orientation);
	// get orientation from event object
	// from e.orientation
	Ti.API.info('e.orientation');
	Ti.API.info(e.orientation);
	// Ti.Gesture.orientation should match e.orientation
	// but iOS and Android will report different values
	
	Ti.API.info('Ti.UI.orientation');
	Ti.API.info(Ti.UI.orientation);

	// two helper methods return a Boolean
	// e.source.isPortrait()
	// e.source.isLandscape()
	Ti.API.info('e.source');
	Ti.API.info(e.source.isPortrait());
	Ti.API.info(e.source.isLandscape());

	if (e.source.isPortrait()) {
		sidebar.visible = false;
	}
	else {
		sidebar.visible = true;
	}
});

win.add(sidebar);

win.open();
You must test it on device. Hold device in hand (in vertical position) and then try to put it on the table :) (so, it goes from 90 degrees in hand to 0 degrees on table). You should be able to see white sidebar on right side - which means event is fired and orientation is wrongly set in event listener argument. My tests have found that "Ti.UI.orientation" works correctly but it's deprecated since 1.7.2 SDK.

Comments

  1. Ritu Agrawal 2014-03-26

    Moving this ticket to engineering as I can reproduce the issue with the provided test case.
  2. Shameer Jan 2014-09-19

    Issue reproduce 3.2.2 and 3.4.0 Appcelerator Studio, build: 3.3.0.201407111535 TiSDK 3.4.0 iOS SDK: 7.1 Titanium Command-Line Interface, CLI version 3.3.0
  3. Lee Morris 2017-05-25

    I have been able to reproduce this issue with the following environment; iPhone 7 (10.2) MacOS 10.11.6 (15G31) Studio 4.9.0.201705021158 Ti SDK 6.1.0.v20170519131839 Appc NPM 4.2.9 Appc CLI 6.2.1 Ti CLI 5.0.13 Alloy 1.9.11 Arrow 2.0.0 Xcode 8.2 (8C38) Node v4.8.2 Java 1.7.0_80

JSON Source