Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10554] iOS: orientationchange event fires twice, once with bogus data

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2012-09-05T18:58:19.000+0000
Affected Version/sRelease 2.1.1
Fix Version/sSprint 2012-18 API
ComponentsiOS
Labelsapi
ReporterTim Poulsen
AssigneeBlain Hamon
Created2012-08-22T08:01:58.000+0000
Updated2017-03-29T17:18:22.000+0000

Description

Actual results on device

The 'orientationchange' fires twice, and fires with a small shake or tap on the device once with bogus orientation values and the second time with a valid value. This doesn't happen in the simulator. And it doesn't happen on Android. As a result, you can't use an if/else wrapper for the Ti.Gesture.isPortrait/isLandscape functions as shown below. You must explicitly test with an if/elseif block.

Expected results:

The 'orientationchange' event would fire once, after orientation changes with e.orientation/Ti.Gesture.orientation reporting a non-zero value (which should be reserved for only the face up/down/unknown state). Shaking or tapping the device would not cause 'orientationchange' to fire.
// Drop into a new project, test on device

Titanium.UI.setBackgroundColor('#000');
var win1 = Titanium.UI.createWindow({  
    backgroundColor:'#fff'
});

var label1 = Titanium.UI.createLabel({
    color:'#444',
    text:'Orientation: Rotate/shake to change',
    font:{fontSize:18,fontFamily:'Helvetica Neue', fontWeight: 'bold'},
    textAlign:'center',
    width:Ti.UI.FILL,
    top: 2
});
win1.add(label1);

var ta = Ti.UI.createTextArea({
    left:1, top: 25,
    textAlign: 'left',
    width: Ti.UI.FILL,
    height: Ti.UI.FILL,
    value: ''
});
win1.add(ta);
var taText = '';
function appendTA(txt) {
    ta.value = ta.value + '\n' + txt;
}

Ti.Gesture.addEventListener('orientationchange', function(e) {
    if(Ti.Gesture.isPortrait()) {
        appendTA('e.orientation/Ti.Gesture.orienation = ' + e.orientation + '/' + Ti.Gesture.orientation);
        appendTA('-------------------------')
    } else {
        appendTA('e.orientation/Ti.Gesture.orienation = ' + e.orientation + '/' + Ti.Gesture.orientation);
        appendTA('-------------------------')
    }
});


win1.open();

Attachments

FileDateSize
ipad.png2012-08-22T08:01:58.000+0000108325

Comments

  1. Blain Hamon 2012-08-23

    This is likely invalid. Android treats UI and device orientation as one and the same, but for iOS, Ti.Gesture reports the orientation of the device, NOT the orientation of the UI. By shaking the device slowly, you are telling the device that down is in the opposite direction, then that down is back to where it was. Remember that you can't tell the difference between gravity and any other acceleration. (Blame Einstein for that one) We need to hammer out parity on Ti.UI.orientation or Ti.UI.Window.orientation and possibly create an event to trigger on UI orientation changes, so people use that instead of the accelerometer-triggered event.
  2. Tim Poulsen 2012-08-24

    The main part of this ticket is that the orientationchange event fires twice. One time, the e.orientation/Ti.Gesture.orientation values are 0, the second time they hold valid data. Before marking this invalid, make sure you consider that beyond the part about the shake. A simple solution might be to account for this double firing in the isPortrait/isLandscape functions. With this double-firing, those helpers are of limited utility and reports from the field indicate people are simply writing their own versions instead of using what we supply.
  3. Blain Hamon 2012-09-04

    Interesting, that makes sesne. 0 is Ti.Gesture.UNKNOWN. That is, it knows it's no longer portrait, but the force on the accelerometer is too conflated or too weak to have a 'down'. So the data is valid, just not what's expected, despite being true. Here's the sticky wicket. How far should we deviate from what is actually natively presented? My main point is that the test is checking for a hardware situation when it should be testing for a software situation. Gesture may dictate part of how the display is laid out, but it's neither sufficient nor necessary.
  4. Blain Hamon 2012-09-05

    Ti.Gesture.orientationchange is an event triggered by the hardware accelerometer, and does not reflect the window's orientation. Watch TIMOB-10790 for the new event to listen for.
  5. Lee Morris 2017-03-29

    Closing ticket as invalid.

JSON Source