PDA

View Full Version : How to determine current screen orientation



parky128
18 Jan 2012, 11:32 AM
Hi,

How can I determine on an ad-hoc basis what the screen orientation is of the device being used?

I know I can listen for the orientation change event on the viewport, but what about when the user first loads up the application, how can I determine this through code?

Thanks

dobie_
18 Jan 2012, 3:49 PM
I would look at window.innerWidth and window.innerHeight and infer the orientation from there.

stephen.friedrich
26 Jan 2012, 3:54 AM
Yeah, that's strange to have an event to tell about value changes, but no way to get the current value.

You could call
Ext.Viewport.determineOrientation()
which returns "portrait" or "landscape" but that method is not documented to be public.

You could also look at the code (in viewport/Default.js) and copy it, or request that the method is made public.

rdougan
26 Jan 2012, 8:54 PM
Ext.Viewport.getOrientation();