-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathscreen-orientation.ios.js
More file actions
75 lines (58 loc) · 1.69 KB
/
screen-orientation.ios.js
File metadata and controls
75 lines (58 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* Created by Sumeet on 06/04/17.
*/
var frameModule = require("ui/frame");
/**
* find the exact object by which the property is owned in the prototype chain
* @param object
* @param property
* @returns {*}
*/
function findPrototypeForProperty(object,property){
while(false==object.hasOwnProperty(property)){
object = Object.getPrototypeOf(object);
}
return object;
}
/**
* set should auto rotate
* @param bool
*/
function setShouldAutoRotate(bool){
var prototypeForNavController = findPrototypeForProperty(frameModule.topmost().ios.controller,"shouldAutorotate");
Object.defineProperty(prototypeForNavController,"shouldAutorotate",{
configurable:true,
enumerable:false,
get:function(){
return bool;
}
})
}
/**
* set current orientation and call the callback once the orientation is set
* @param orientationType
* @param callback
*/
function setCurrentOrientation(orientationType,callback){
if("landscape"==orientationType.toLowerCase()){
UIDevice.currentDevice.setValueForKey(UIInterfaceOrientationLandscapeLeft,"orientation");
setShouldAutoRotate(false);
}
else if("portrait"==orientationType.toLowerCase()){
UIDevice.currentDevice.setValueForKey(UIInterfaceOrientationPortrait,"orientation");
setShouldAutoRotate(false);
}else if("all" == orientationType.toLowerCase()){
setShouldAutoRotate(true);
}
if(undefined!==callback){
callback();
}
}
/**
* clean up the orientation
*/
function cleanupOrientation(){
setShouldAutoRotate(true);
}
exports.setCurrentOrientation=setCurrentOrientation;
exports.orientationCleanup=cleanupOrientation;