mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-02-23 08:32:51 +08:00
Merge pull request #9 from gbenvenuti/bb10Support
Added bb10 support and orientation property to screen object
This commit is contained in:
commit
4e7899be92
44
README.md
44
README.md
@ -1,7 +1,17 @@
|
||||
#cordova-yoik-screenorientation
|
||||
|
||||
Cordova plugin to set/lock the screen orientation in a common way for both iOS and Android. From version 1.0.0 the
|
||||
interface is based on the [Screen Orientation API](http://www.w3.org/TR/screen-orientation/).
|
||||
Cordova plugin to set/lock the screen orientation in a common way for iOS, Android and Blackberry 10. From version 1.0.0 the interface is based on the [Screen Orientation API](http://www.w3.org/TR/screen-orientation/).
|
||||
|
||||
The plugin adds the following to the screen object:
|
||||
|
||||
__lockOrientation(ORIENTATION_STRING)__
|
||||
lock the device orientation
|
||||
|
||||
__unlockOrientation()__
|
||||
unlock the orientation
|
||||
|
||||
__orientation__
|
||||
current orientation (ORIENTATION_STRING)
|
||||
|
||||
##Install
|
||||
|
||||
@ -11,7 +21,7 @@ cordova plugin add net.yoik.cordova.plugins.screenorientation
|
||||
https://github.com/yoik/cordova-yoik-screenorientation
|
||||
|
||||
|
||||
##Orientations
|
||||
##Supported Orientations
|
||||
|
||||
__portrait-primary__
|
||||
The orientation is in the primary portrait mode.
|
||||
@ -33,31 +43,29 @@ The orientation is either landscape-primary or landscape-secondary (sensor).
|
||||
|
||||
##Usage
|
||||
|
||||
// set to either landscape
|
||||
screen.lockOrientation('landscape');
|
||||
|
||||
// allow user rotate
|
||||
screen.unlockOrientation();
|
||||
|
||||
// access current orientation
|
||||
console.log('Orientation is ' + screen.orientation);
|
||||
|
||||
##Events
|
||||
|
||||
Both android and iOS will fire the orientationchange event on the window object.
|
||||
For this version of the plugin use the window object if you require notification.
|
||||
|
||||
i.e.
|
||||
|
||||
function init() {
|
||||
window.addEventListener("orientationchange", orientationChange, true);
|
||||
}
|
||||
|
||||
function orientationChange(e) {
|
||||
var orientation="portrait";
|
||||
if(window.orientation == -90 || window.orientation == 90) orientation = "landscape";
|
||||
document.getElementById("status").innerHTML+=orientation+"<br>";
|
||||
}
|
||||
|
||||
For this plugin to follow the API events should be fired on the screen object.
|
||||
iOS does not currently support events on the _screen_ object so custom event
|
||||
For this plugin to follow the full API events should be fired on the screen object.
|
||||
iOS and BB10 do not currently support events on the _screen_ object so custom event
|
||||
handling will need to be added (Suggestions welcome!).
|
||||
|
||||
##Android Notes
|
||||
|
||||
The __screen.orientation__ property will not update when the phone is [rotated 180 degrees](http://www.quirksmode.org/dom/events/orientationchange.html).
|
||||
|
||||
##iOS Notes
|
||||
|
||||
The 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.
|
||||
@ -73,4 +81,8 @@ Issue [#1](https://github.com/yoik/cordova-yoik-screenorientation/issues/1) @dok
|
||||
>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.
|
||||
|
||||
|
||||
##BB10 Notes
|
||||
|
||||
Wraps the com.blackberry.app plugin functions, auto installed as a dependancy.
|
||||
|
||||
Pull requests welcome.
|
||||
|
19
plugin.xml
19
plugin.xml
@ -2,10 +2,10 @@
|
||||
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="net.yoik.cordova.plugins.screenorientation"
|
||||
version="1.0.1">
|
||||
version="1.1.0">
|
||||
|
||||
<name>YoikScreenOrientation</name>
|
||||
<description>Yoik Screen Orientation Plugin</description>
|
||||
<name>Yoik Screen Orientation</name>
|
||||
<description>The Yoik Screen Orientation Plugin adds Screen Orientation API lock and unlock functions to the global screen object in android, iOS and BB10.</description>
|
||||
<license>MIT</license>
|
||||
|
||||
<engines>
|
||||
@ -22,6 +22,9 @@
|
||||
<param name="ios-package" value="YoikScreenOrientation" />
|
||||
</feature>
|
||||
</config-file>
|
||||
<js-module src="www/screenorientation.ios.js" name="screenorientation.ios">
|
||||
<merges target="cordova.plugins.screenorientation" />
|
||||
</js-module>
|
||||
<header-file src="src/ios/YoikScreenOrientation.h" />
|
||||
<source-file src="src/ios/YoikScreenOrientation.m" />
|
||||
</platform>
|
||||
@ -36,4 +39,14 @@
|
||||
</config-file>
|
||||
</platform>
|
||||
|
||||
<platform name="blackberry10">
|
||||
<dependency id="com.blackberry.app" />
|
||||
<config-file target="www/config.xml" parent="/widget">
|
||||
<feature name="net.yoik.cordova.plugins.screenorientation" value="net.yoik.cordova.plugins.screenorientation" />
|
||||
</config-file>
|
||||
<js-module src="www/screenorientation.bb10.js" name="screenorientation.bb10">
|
||||
<merges target="cordova.plugins.screenorientation" />
|
||||
</js-module>
|
||||
</platform>
|
||||
|
||||
</plugin>
|
||||
|
37
www/screenorientation.bb10.js
Normal file
37
www/screenorientation.bb10.js
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
var screenOrientation = {};
|
||||
|
||||
screenOrientation.setOrientation = function(orientation) {
|
||||
if (blackberry.app) {
|
||||
if (orientation === 'unlocked') {
|
||||
blackberry.app.unlockOrientation();
|
||||
} else {
|
||||
blackberry.app.lockOrientation(orientation);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = screenOrientation;
|
52
www/screenorientation.ios.js
Normal file
52
www/screenorientation.ios.js
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
// ios orientation callback/hook
|
||||
window.shouldRotateToOrientation = function(orientation) {
|
||||
var currOrientation = cordova.plugins.screenorientation.currOrientation;
|
||||
switch (currOrientation) {
|
||||
case 'portrait':
|
||||
case 'portrait-primary':
|
||||
if (orientation === 0) return true;
|
||||
break;
|
||||
case 'landscape':
|
||||
case 'landscape-primary':
|
||||
if (orientation === -90) return true;
|
||||
break;
|
||||
case 'landscape':
|
||||
case 'landscape-secondary':
|
||||
if (orientation === 90) return true;
|
||||
break;
|
||||
case 'portrait':
|
||||
case 'portrait-secondary':
|
||||
if (orientation === 180) return true;
|
||||
break;
|
||||
default:
|
||||
if (orientation === -90 || orientation === 90 || orientation === 0) return true;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
module.exports = {};
|
@ -23,6 +23,7 @@ SOFTWARE.
|
||||
*/
|
||||
var argscheck = require('cordova/argscheck'),
|
||||
exec = require('cordova/exec'),
|
||||
screenOrientation = {},
|
||||
Orientations = [
|
||||
'portrait-primary',
|
||||
// The orientation is in the primary portrait mode.
|
||||
@ -36,15 +37,14 @@ var argscheck = require('cordova/argscheck'),
|
||||
// The orientation is either portrait-primary or portrait-secondary.
|
||||
'landscape'
|
||||
// The orientation is either landscape-primary or landscape-secondary.
|
||||
],
|
||||
currOrientation = 'unlocked';
|
||||
];
|
||||
|
||||
var orientationExports = {};
|
||||
screenOrientation.Orientations = Orientations;
|
||||
screenOrientation.currOrientation = 'unlocked';
|
||||
|
||||
function setOrientation(orientation) {
|
||||
currOrientation = orientation ? orientation : 'unlocked';
|
||||
exec(null, null, "YoikScreenOrientation", "screenOrientation", ['set', currOrientation]);
|
||||
}
|
||||
screenOrientation.setOrientation = function(orientation) {
|
||||
exec(null, null, "YoikScreenOrientation", "screenOrientation", ['set', orientation]);
|
||||
};
|
||||
|
||||
function addScreenOrientationApi(obj) {
|
||||
if (obj.unlockOrientation || obj.lockOrientation) {
|
||||
@ -56,40 +56,42 @@ function addScreenOrientationApi(obj) {
|
||||
console.log('INVALID ORIENTATION', orientation);
|
||||
return;
|
||||
}
|
||||
setOrientation(orientation);
|
||||
screenOrientation.currOrientation = orientation;
|
||||
screenOrientation.setOrientation(orientation);
|
||||
};
|
||||
|
||||
obj.unlockOrientation = function() {
|
||||
setOrientation('unlocked');
|
||||
screenOrientation.currOrientation = 'unlocked';
|
||||
screenOrientation.setOrientation('unlocked');
|
||||
};
|
||||
}
|
||||
|
||||
addScreenOrientationApi(screen);
|
||||
orientationChange();
|
||||
|
||||
// ios orientation callback/hook
|
||||
window.shouldRotateToOrientation = function(orientation) {
|
||||
switch (currOrientation) {
|
||||
case 'portrait':
|
||||
case 'portrait-primary':
|
||||
if (orientation === 0) return true;
|
||||
break;
|
||||
case 'landscape':
|
||||
case 'landscape-primary':
|
||||
if (orientation === -90) return true;
|
||||
break;
|
||||
case 'landscape':
|
||||
case 'landscape-secondary':
|
||||
if (orientation === 90) return true;
|
||||
break;
|
||||
case 'portrait':
|
||||
case 'portrait-secondary':
|
||||
if (orientation === 180) return true;
|
||||
break;
|
||||
function orientationChange() {
|
||||
var orientation;
|
||||
|
||||
switch (window.orientation) {
|
||||
case 0:
|
||||
orientation = 'portrait-primary';
|
||||
break;
|
||||
case 90:
|
||||
orientation = 'landscape-secondary';
|
||||
break;
|
||||
case 180:
|
||||
orientation = 'portrait-secondary';
|
||||
break;
|
||||
case -90:
|
||||
orientation = 'landscape-primary';
|
||||
break;
|
||||
default:
|
||||
if (orientation === -90 || orientation === 90 || orientation === 0) return true;
|
||||
break;
|
||||
orientation = 'unknown';
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
module.exports = {};
|
||||
screen.orientation = orientation;
|
||||
}
|
||||
|
||||
window.addEventListener("orientationchange", orientationChange, true);
|
||||
|
||||
module.exports = screenOrientation;
|
Loading…
Reference in New Issue
Block a user