UNPKG

3.84 kBMarkdownView Raw
1# Cordova Screen Orientation Plugin
2
3Cordova plugin to set/lock the screen orientation in a common way for iOS, Android, WP8 and Blackberry 10. This plugin is based on an early version of [Screen Orientation API](http://www.w3.org/TR/screen-orientation/) so the api does not currently match the current spec.
4
5The plugin adds the following to the screen object:
6
7__lockOrientation(ORIENTATION_STRING)__
8lock the device orientation
9
10__unlockOrientation()__
11unlock the orientation
12
13__orientation__
14current orientation (ORIENTATION_STRING)
15
16## Install
17
18cordova < 4
19
20cordova plugin add net.yoik.cordova.plugins.screenorientation
21
22cordova > 4
23
24cordova plugin add cordova-plugin-screen-orientation
25
26## Supported Orientations
27
28__portrait-primary__
29The orientation is in the primary portrait mode.
30
31__portrait-secondary__
32The orientation is in the secondary portrait mode.
33
34__landscape-primary__
35The orientation is in the primary landscape mode.
36
37__landscape-secondary__
38The orientation is in the secondary landscape mode.
39
40__portrait__
41The orientation is either portrait-primary or portrait-secondary (sensor).
42
43__landscape__
44The orientation is either landscape-primary or landscape-secondary (sensor).
45
46## Usage
47
48 // set to either landscape
49 screen.lockOrientation('landscape');
50
51 // allow user rotate
52 screen.unlockOrientation();
53
54 // access current orientation
55 console.log('Orientation is ' + screen.orientation);
56
57## Events
58
59Both android and iOS will fire the orientationchange event on the window object.
60For this version of the plugin use the window object if you require notification.
61
62
63For this plugin to follow the full API events should be fired on the screen object.
64iOS and BB10 do not currently support events on the _screen_ object so custom event
65handling will need to be added (Suggestions welcome!).
66
67## Android Notes
68
69The __screen.orientation__ property will not update when the phone is [rotated 180 degrees](http://www.quirksmode.org/dom/events/orientationchange.html).
70
71## iOS Notes
72
73The iOS version is a combination of the cordova JS callback _window.shouldRotateToOrientation_ and the workaround to recheck the orientation as implemented in https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation.
74
75__If you have a custom implementation of the _window.shouldRotateToOrientation_ it will have to be removed for the plugin to function as expected.__
76
77#### iOS6
78
79There has been a few cases where the rotation does not change the width of the viewport
80
81Issue [#1](https://github.com/gbenvenuti/cordova-plugin-screen-orientation/issues/1) @dokterbob
82
83>It seems to be related to having width=device-width, height=device-height in the meta viewport (which is part of the boilerplate phonegap/cordova app). It can be solved by updating the viewport with width=device-height, height=device-width or simply removing width and height altogether.
84
85#### iOS8
86
87Versions prior to 1.2.0 will cause an application crash in iOS8 due to a change in presentViewController timing.
88
89## BB10 Notes
90
91Wraps the com.blackberry.app plugin functions, auto installed as a dependancy.
92
93## WP8 Notes
94
95Windows phone does not support specification or primary and secondary orientations. If called with a specific orientation the plugin will just apply the landscape or portait orientation.
96
97# Changelog
98
99## 1.3.5-6
100* Plugin added to npm
101
102## 1.3.4
103* Readme update
104
105## 1.3.3
106* [#53](https://github.com/gbenvenuti/cordova-plugin-screen-orientation/pull/53) WP8 Support
107
108## 1.3.2
109
110* [#33](https://github.com/gbenvenuti/cordova-plugin-screen-orientation/issues/33) iOS8 Delay Block
111
112## 1.3.0
113
114* [#23](https://github.com/gbenvenuti/cordova-plugin-screen-orientation/issues/23) iOS8 flicker
115
116## 1.2.0-1.2.1
117
118* [#19](https://github.com/gbenvenuti/cordova-plugin-screen-orientation/issues/19) iOS8 Crash
119
120
121
122Pull requests welcome.