Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25647] Device width and height value incorrect on first orientation change (Android)

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionInvalid
Resolution Date2018-01-24T19:26:56.000+0000
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsandroid, height, orientation, width
ReporterArjan
AssigneeEric Merriman
Created2018-01-03T12:35:46.000+0000
Updated2018-01-24T19:26:56.000+0000

Description

Just like previous issues related to orientation changes (which seem to be fixed now), there's a problem with device width/height detection now. Initially the device width and height values are correct. But, on the first orientation change it returns the same values. After the second change it returns the values that it should have returned the first time, which results in a reversed width/height value. Workaround: read the properies for a second time, with a delay of +/- 1000 ms. This returns the correct value. URL to test project: https://content.skoften.net/test.zip (can't upload due to 10MB limit)

Comments

  1. Sharif AbuDarda 2018-01-03

    Hello, I can't download the sample app you provide the link to. Can you please send a valid link. Thanks.
  2. Arjan 2018-01-03

    Hi, Weird, the link works just fine here. Try this one: https://ufile.io/r0n3u Or maybe I can email it? Cheers.
  3. Joshua Quick 2018-01-19

    [~arif], this is not a Titanium bug. Let me explain... *How Ti.Gesture orientation works:* The Ti.Gesture orientation properties and event is supposed to provide the device's orientation, not the app window's orientation. There is a big difference between the two. For example, if your app is set up to be portrait-only and you hold the phone landscape-right, then Ti.Gesture will report the orientation as being landscape-right, regardless of the app window's currently rendered upright orientation. This is how it's always worked on iOS and Window... but... there was a parity/portability issue on Android where this module would report the app window's orientation instead and this was a problem for Titanium developers since no other APIs offered device orientation. So, in Titanium 7.0.0, we've changed Ti.Gesture to provide device orientation to match how it works on iOS and Windows. *Why you should NOT use Ti.Gesture:* Using Ti.Gesture orientation events to detect app window width/height changes is not reliable on any platform (Android, iOS, and Windows) for the following reasons...

    You won't get this event in split-screen mode. Nor can you assume device orientation and app orientation matches in this case. (Ex: Device is held landscape and the 2 apps are shown in portrait form in split-screen mode.)

    You won't get this event on Android when the windows switches in-and-out of immersive mode. Meaning the bottom virtual navigation bar is hidden or shown, causing the height of the app window to change, but the orientation doesn't change.

    On iOS, the device orientation event is typically received before the app window is rotated to match by the OS. This is the case in the native Objective-C/Switch level. (It's an order of events issue.)

    *Best Solution:* What you should do instead is listen for the Ti.UI.Window's "postlayout" event. This event gets fired when the app window has been resized and the window's "size" property will be updated with the new width and height when your listener gets called, which is what you're after. http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.Window-event-postlayout I hope this helps!
  4. Arjan 2018-01-24

    Thanks for your comment Joshua, this helps!

JSON Source