forked from jim-lake/react-native-orientation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (61 loc) · 1.6 KB
/
index.js
File metadata and controls
63 lines (61 loc) · 1.6 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
var Orientation = require('react-native').NativeModules.Orientation;
var DeviceEventEmitter = require('react-native').DeviceEventEmitter;
var listeners = {};
var orientationDidChangeEvent = "orientationDidChange";
var specificOrientationDidChangeEvent = "specificOrientationDidChange";
module.exports = {
getOrientation(cb) {
Orientation.getOrientation((error,orientation) =>{
cb(error, orientation);
});
},
getSpecificOrientation(cb) {
Orientation.getSpecificOrientation((error,orientation) =>{
cb(error, orientation);
});
},
lockToPortrait() {
Orientation.lockToPortrait();
},
lockToLandscape() {
Orientation.lockToLandscape();
},
lockToLandscapeRight() {
Orientation.lockToLandscapeRight();
},
lockToLandscapeLeft() {
Orientation.lockToLandscapeLeft();
},
unlockAllOrientations() {
Orientation.unlockAllOrientations();
},
addOrientationListener(cb) {
listeners[cb] = DeviceEventEmitter.addListener(orientationDidChangeEvent,
(body) => {
cb(body.orientation);
});
},
removeOrientationListener(cb) {
if (!listeners[cb]) {
return;
}
listeners[cb].remove();
listeners[cb] = null;
},
addSpecificOrientationListener(cb) {
listeners[cb] = DeviceEventEmitter.addListener(specificOrientationDidChangeEvent,
(body) => {
cb(body.specificOrientation);
});
},
removeSpecificOrientationListener(cb) {
if (!listeners[cb]) {
return;
}
listeners[cb].remove();
listeners[cb] = null;
},
getInitialOrientation() {
return Orientation.initialOrientation;
}
}