forked from Nodonisko/react-native-orientation-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
41 lines (36 loc) · 1.09 KB
/
index.ios.js
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
'use strict';
var React = require('react-native');
var { NativeModules, RCTDeviceEventEmitter, DeviceEventEmitter } = React;
var getRotation = function (rotation) {
if(rotation == 90) {
rotation = 1;
} else if (rotation == 180) {
rotation = 2;
} else if(rotation == 270) {
rotation = 3;
}
return rotation;
};
DeviceEventEmitter = RCTDeviceEventEmitter ? RCTDeviceEventEmitter : DeviceEventEmitter;
module.exports = {
rotate: function (rotation) {
NativeModules.OrientationController.rotate(getRotation(rotation));
},
getOrientation: function(callback) {
NativeModules.OrientationController.getOrientation((orientation, application, deviceType, size)=>{
typeof callback == 'function' && callback(orientation, application, deviceType, size);
});
},
addListener: function(callback) {
return DeviceEventEmitter.addListener(
'orientationDidChange', function () {
callback.apply(this, arguments[0])
}
);
},
removeListener: function(listener) {
DeviceEventEmitter.removeListener(
'orientationDidChange', listener
);
}
}