react-native-orientation-director 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -89,6 +89,7 @@ This library exports a class called: [RNOrientationDirector](https://github.com/
89
89
  | setHumanReadableOrientations | Sets the mapping needed to convert orientation values to human readable strings |
90
90
  | setHumanReadableAutoRotations | Sets the mapping needed to convert auto rotation values to human readable strings |
91
91
  | resetSupportedInterfaceOrientations | Resets the supported interface orientations to settings |
92
+ | isLockableOrientation | Determines if orientation is lockable |
92
93
 
93
94
  In addition, the library exposes the following hooks:
94
95
 
@@ -100,6 +101,26 @@ In addition, the library exposes the following hooks:
100
101
 
101
102
  Head over to the [example project](example) to see how to use the library.
102
103
 
104
+ ### Warning
105
+
106
+ Please be aware that there is a subtle difference between the device orientation
107
+ and the interface orientation.
108
+
109
+ When you device is either in landscape left or right orientation, your interface
110
+ is inverted, this is why lockTo method needs a second parameter to discriminate
111
+ which type of orientation your are supplying.
112
+
113
+ To match developers expectations, if you supply a device orientation and
114
+ OrientationType.device, lockTo switches landscapeRight with left and vice versa
115
+ to property align the interface orientation.
116
+
117
+ This behavior comes from the native API, you can find more information in their
118
+ documentation:
119
+
120
+ 1. [iOS - UIInterfaceOrientation](https://developer.apple.com/documentation/uikit/uiinterfaceorientation)
121
+ 2. [iOS - UIDeviceOrientation](https://developer.apple.com/documentation/uikit/uideviceorientation)
122
+ 3. [Android - getRotation](<https://developer.android.com/reference/android/view/Display#getRotation()>)
123
+
103
124
  ### Android
104
125
 
105
126
  Since on Android we need to deal with sensors and their usage, it is worth noting that the device orientation computation works
@@ -104,10 +104,8 @@ import UIKit
104
104
  return supportedInterfaceOrientations.reduce(UIInterfaceOrientationMask()) { $0.union($1) }
105
105
  }
106
106
 
107
- // TODO: FIX BECAUSE IT ALWAYS RETURNS PORTRAIT AND ITS BROKEN
108
107
  private func initInterfaceOrientation() -> Orientation {
109
- let interfaceOrientation = utils.getInterfaceOrientation()
110
- return utils.convertToOrientationFrom(uiInterfaceOrientation: interfaceOrientation)
108
+ return self.getOrientationFromInterface()
111
109
  }
112
110
 
113
111
  private func initDeviceOrientation() -> Orientation {
@@ -163,18 +161,8 @@ import UIKit
163
161
  if (deviceOrientation == Orientation.FACE_UP || deviceOrientation == Orientation.FACE_DOWN) {
164
162
  return
165
163
  }
166
-
167
- let newInterfaceOrientationMask = utils.convertToMaskFrom(deviceOrientation: deviceOrientation)
168
- let isSupported = self.supportedInterfaceOrientations.contains(newInterfaceOrientationMask)
169
- if (!isSupported) {
170
- return
171
- }
172
-
173
- let newInterfaceOrientation = utils.convertToOrientationFrom(mask: newInterfaceOrientationMask)
174
- if (newInterfaceOrientation == lastInterfaceOrientation) {
175
- return
176
- }
177
-
164
+
165
+ let newInterfaceOrientation = self.getOrientationFromInterface()
178
166
  updateLastInterfaceOrientationTo(value: newInterfaceOrientation)
179
167
  }
180
168
 
@@ -187,4 +175,9 @@ import UIKit
187
175
  self.eventManager.sendInterfaceOrientationDidChange(orientationValue: value.rawValue)
188
176
  lastInterfaceOrientation = value
189
177
  }
178
+
179
+ private func getOrientationFromInterface() -> Orientation {
180
+ let interfaceOrientation = utils.getInterfaceOrientation()
181
+ return utils.convertToOrientationFrom(uiInterfaceOrientation: interfaceOrientation)
182
+ }
190
183
  }
@@ -55,19 +55,6 @@ class Utils {
55
55
  }
56
56
  }
57
57
 
58
- public func convertToOrientationFrom(mask: UIInterfaceOrientationMask) -> Orientation {
59
- switch(mask) {
60
- case .portraitUpsideDown:
61
- return .PORTRAIT_UPSIDE_DOWN
62
- case .landscapeRight:
63
- return .LANDSCAPE_RIGHT
64
- case .landscapeLeft:
65
- return .LANDSCAPE_LEFT
66
- default:
67
- return .PORTRAIT
68
- }
69
- }
70
-
71
58
  /**
72
59
  Note: .portraitUpsideDown only works for devices with home button and iPads
73
60
  https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations
@@ -87,25 +74,6 @@ class Utils {
87
74
  }
88
75
  }
89
76
 
90
- /**
91
- Note: .portraitUpsideDown only works for devices with home button and iPads
92
- https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations
93
- */
94
- public func convertToMaskFrom(deviceOrientation: Orientation) -> UIInterfaceOrientationMask {
95
- switch(deviceOrientation) {
96
- case .PORTRAIT:
97
- return .portrait
98
- case .LANDSCAPE_RIGHT:
99
- return .landscapeLeft
100
- case .PORTRAIT_UPSIDE_DOWN:
101
- return .portraitUpsideDown
102
- case .LANDSCAPE_LEFT:
103
- return .landscapeRight
104
- default:
105
- return .all
106
- }
107
- }
108
-
109
77
  public func getInterfaceOrientation() -> UIInterfaceOrientation {
110
78
  guard let windowScene = self.getCurrentWindow()?.windowScene else {
111
79
  return UIInterfaceOrientation.unknown
@@ -8,6 +8,7 @@ var _reactNative = require("react-native");
8
8
  var _module = _interopRequireDefault(require("./module"));
9
9
  var _Orientation = require("./types/Orientation.enum");
10
10
  var _AutoRotation = require("./types/AutoRotation.enum");
11
+ var _OrientationType = require("./types/OrientationType.enum");
11
12
  var _EventEmitter = _interopRequireDefault(require("./EventEmitter"));
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  class RNOrientationDirector {
@@ -37,7 +38,38 @@ class RNOrientationDirector {
37
38
  static getDeviceOrientation() {
38
39
  return _module.default.getDeviceOrientation();
39
40
  }
40
- static lockTo(orientation) {
41
+
42
+ /**
43
+ * Please be aware that device orientation is not the
44
+ * same as interface orientation.
45
+ *
46
+ * Specifically, landscape left and right are inverted:
47
+ *
48
+ * - landscapeLeft in device orientation is landscapeRight in interface orientation
49
+ * - landscapeRight in device orientation is landscapeLeft in interface orientation
50
+ *
51
+ * This is a behavior of the native API.
52
+ *
53
+ * When you pass an orientation value, do provide orientationType
54
+ * as well if the orientation value is not an interface orientation.
55
+ * Example: when using listenForDeviceOrientationChanges.
56
+ *
57
+ * @param orientation any lockable orientation enum value
58
+ * @param orientationType any orientation type enum value
59
+ */
60
+ static lockTo(orientation, orientationType = _OrientationType.OrientationType.interface) {
61
+ if (orientationType === _OrientationType.OrientationType.interface) {
62
+ _module.default.lockTo(orientation);
63
+ return;
64
+ }
65
+ if (orientation === _Orientation.Orientation.landscapeLeft) {
66
+ _module.default.lockTo(_Orientation.Orientation.landscapeRight);
67
+ return;
68
+ }
69
+ if (orientation === _Orientation.Orientation.landscapeRight) {
70
+ _module.default.lockTo(_Orientation.Orientation.landscapeLeft);
71
+ return;
72
+ }
41
73
  _module.default.lockTo(orientation);
42
74
  }
43
75
  static unlock() {
@@ -70,6 +102,25 @@ class RNOrientationDirector {
70
102
  static convertAutoRotationToHumanReadableString(autoRotation) {
71
103
  return RNOrientationDirector._humanReadableAutoRotationsResource[autoRotation];
72
104
  }
105
+
106
+ /**
107
+ * This method checks if the given orientation is lockable
108
+ * by interface perspective.
109
+ *
110
+ * All orientations are lockable except for unknown, faceUp
111
+ * and faceDown.
112
+ *
113
+ * This method is useful when you want to lock the interface
114
+ * orientation from a given device orientation.
115
+ *
116
+ * Example: with listenForDeviceOrientationChanges
117
+ *
118
+ * @param orientation any orientation enum value
119
+ * @returns true if the orientation is lockable
120
+ */
121
+ static isLockableOrientation(orientation) {
122
+ return !(orientation === _Orientation.Orientation.unknown || orientation === _Orientation.Orientation.faceUp || orientation === _Orientation.Orientation.faceDown);
123
+ }
73
124
  }
74
125
  var _default = exports.default = RNOrientationDirector;
75
126
  //# sourceMappingURL=RNOrientationDirector.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","_module","_interopRequireDefault","_Orientation","_AutoRotation","_EventEmitter","e","__esModule","default","RNOrientationDirector","_humanReadableOrientationsResource","Orientation","unknown","portrait","portraitUpsideDown","landscapeLeft","landscapeRight","faceUp","faceDown","_humanReadableAutoRotationsResource","AutoRotation","enabled","disabled","setHumanReadableOrientations","resource","setHumanReadableAutoRotations","getInterfaceOrientation","Module","getDeviceOrientation","lockTo","orientation","unlock","isLocked","isAutoRotationEnabled","Platform","OS","resetSupportedInterfaceOrientations","listenForDeviceOrientationChanges","callback","EventEmitter","addDeviceOrientationDidChangeListener","listenForInterfaceOrientationChanges","addInterfaceOrientationDidChangeListener","listenForLockChanges","addLockDidChangeListener","convertOrientationToHumanReadableString","convertAutoRotationToHumanReadableString","autoRotation","_default","exports"],"sourceRoot":"../../src","sources":["RNOrientationDirector.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAKA,IAAAK,aAAA,GAAAH,sBAAA,CAAAF,OAAA;AAA0C,SAAAE,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE1C,MAAMG,qBAAqB,CAAC;EAC1B,OAAeC,kCAAkC,GAC/C;IACE,CAACC,wBAAW,CAACC,OAAO,GAAG,SAAS;IAChC,CAACD,wBAAW,CAACE,QAAQ,GAAG,UAAU;IAClC,CAACF,wBAAW,CAACG,kBAAkB,GAAG,sBAAsB;IACxD,CAACH,wBAAW,CAACI,aAAa,GAAG,gBAAgB;IAC7C,CAACJ,wBAAW,CAACK,cAAc,GAAG,iBAAiB;IAC/C,CAACL,wBAAW,CAACM,MAAM,GAAG,SAAS;IAC/B,CAACN,wBAAW,CAACO,QAAQ,GAAG;EAC1B,CAAC;EAEH,OAAeC,mCAAmC,GAChD;IACE,CAACC,0BAAY,CAACR,OAAO,GAAG,SAAS;IACjC,CAACQ,0BAAY,CAACC,OAAO,GAAG,SAAS;IACjC,CAACD,0BAAY,CAACE,QAAQ,GAAG;EAC3B,CAAC;EAEHC,4BAA4BA,CAACC,QAA2C,EAAE;IACxEf,qBAAqB,CAACC,kCAAkC,GAAGc,QAAQ;EACrE;EAEAC,6BAA6BA,CAACD,QAA4C,EAAE;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CA,CAACC,YAA0B,EAAE;IAC1E,OAAOtC,qBAAqB,CAACU,mCAAmC,CAC9D4B,YAAY,CACb;EACH;AACF;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAzC,OAAA,GAEcC,qBAAqB","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","_module","_interopRequireDefault","_Orientation","_AutoRotation","_OrientationType","_EventEmitter","e","__esModule","default","RNOrientationDirector","_humanReadableOrientationsResource","Orientation","unknown","portrait","portraitUpsideDown","landscapeLeft","landscapeRight","faceUp","faceDown","_humanReadableAutoRotationsResource","AutoRotation","enabled","disabled","setHumanReadableOrientations","resource","setHumanReadableAutoRotations","getInterfaceOrientation","Module","getDeviceOrientation","lockTo","orientation","orientationType","OrientationType","interface","unlock","isLocked","isAutoRotationEnabled","Platform","OS","resetSupportedInterfaceOrientations","listenForDeviceOrientationChanges","callback","EventEmitter","addDeviceOrientationDidChangeListener","listenForInterfaceOrientationChanges","addInterfaceOrientationDidChangeListener","listenForLockChanges","addLockDidChangeListener","convertOrientationToHumanReadableString","convertAutoRotationToHumanReadableString","autoRotation","isLockableOrientation","_default","exports"],"sourceRoot":"../../src","sources":["RNOrientationDirector.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,YAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AAKA,IAAAM,aAAA,GAAAJ,sBAAA,CAAAF,OAAA;AAA0C,SAAAE,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE1C,MAAMG,qBAAqB,CAAC;EAC1B,OAAeC,kCAAkC,GAC/C;IACE,CAACC,wBAAW,CAACC,OAAO,GAAG,SAAS;IAChC,CAACD,wBAAW,CAACE,QAAQ,GAAG,UAAU;I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A,WAAW,KAAKnB,wBAAW,CAACC,OAAO,IACnCkB,WAAW,KAAKnB,wBAAW,CAACM,MAAM,IAClCa,WAAW,KAAKnB,wBAAW,CAACO,QAAQ,CACrC;EACH;AACF;AAAC,IAAAkC,QAAA,GAAAC,OAAA,CAAA7C,OAAA,GAEcC,qBAAqB","ignoreList":[]}
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "Orientation", {
15
15
  return _Orientation.Orientation;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "OrientationType", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _OrientationType.OrientationType;
22
+ }
23
+ });
18
24
  exports.default = void 0;
19
25
  Object.defineProperty(exports, "useDeviceOrientation", {
20
26
  enumerable: true,
@@ -36,6 +42,7 @@ Object.defineProperty(exports, "useIsInterfaceOrientationLocked", {
36
42
  });
37
43
  var _Orientation = require("./types/Orientation.enum");
38
44
  var _AutoRotation = require("./types/AutoRotation.enum");
45
+ var _OrientationType = require("./types/OrientationType.enum");
39
46
  var _useDeviceOrientation = _interopRequireDefault(require("./hooks/useDeviceOrientation.hook"));
40
47
  var _useInterfaceOrientation = _interopRequireDefault(require("./hooks/useInterfaceOrientation.hook"));
41
48
  var _useIsInterfaceOrientationLocked = _interopRequireDefault(require("./hooks/useIsInterfaceOrientationLocked.hook"));
@@ -1 +1 @@
1
- {"version":3,"names":["_Orientation","require","_AutoRotation","_useDeviceOrientation","_interopRequireDefault","_useInterfaceOrientation","_useIsInterfaceOrientationLocked","_RNOrientationDirector","e","__esModule","default","_default","exports","RNOrientationDirector"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AAEA,IAAAE,qBAAA,GAAAC,sBAAA,CAAAH,OAAA;AAGA,IAAAI,wBAAA,GAAAD,sBAAA,CAAAH,OAAA;AAGA,IAAAK,gCAAA,GAAAF,sBAAA,CAAAH,OAAA;AAGA,IAAAM,sBAAA,GAAAH,sBAAA,CAAAH,OAAA;AAA4D,SAAAG,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAC7CG,8BAAqB","ignoreList":[]}
1
+ {"version":3,"names":["_Orientation","require","_AutoRotation","_OrientationType","_useDeviceOrientation","_interopRequireDefault","_useInterfaceOrientation","_useIsInterfaceOrientationLocked","_RNOrientationDirector","e","__esModule","default","_default","exports","RNOrientationDirector"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AAEA,IAAAG,qBAAA,GAAAC,sBAAA,CAAAJ,OAAA;AAGA,IAAAK,wBAAA,GAAAD,sBAAA,CAAAJ,OAAA;AAGA,IAAAM,gCAAA,GAAAF,sBAAA,CAAAJ,OAAA;AAGA,IAAAO,sBAAA,GAAAH,sBAAA,CAAAJ,OAAA;AAA4D,SAAAI,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAAAG,QAAA,GAAAC,OAAA,CAAAF,OAAA,GAC7CG,8BAAqB","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.OrientationType = void 0;
7
+ let OrientationType = exports.OrientationType = /*#__PURE__*/function (OrientationType) {
8
+ OrientationType["device"] = "device";
9
+ OrientationType["interface"] = "interface";
10
+ return OrientationType;
11
+ }({});
12
+ //# sourceMappingURL=OrientationType.enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OrientationType","exports"],"sourceRoot":"../../../src","sources":["types/OrientationType.enum.ts"],"mappings":";;;;;;IAAYA,eAAe,GAAAC,OAAA,CAAAD,eAAA,0BAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA","ignoreList":[]}
@@ -2,6 +2,7 @@ import { Platform } from 'react-native';
2
2
  import Module from './module';
3
3
  import { Orientation } from './types/Orientation.enum';
4
4
  import { AutoRotation } from './types/AutoRotation.enum';
5
+ import { OrientationType } from './types/OrientationType.enum';
5
6
  import EventEmitter from './EventEmitter';
6
7
  class RNOrientationDirector {
7
8
  static _humanReadableOrientationsResource = {
@@ -30,7 +31,38 @@ class RNOrientationDirector {
30
31
  static getDeviceOrientation() {
31
32
  return Module.getDeviceOrientation();
32
33
  }
33
- static lockTo(orientation) {
34
+
35
+ /**
36
+ * Please be aware that device orientation is not the
37
+ * same as interface orientation.
38
+ *
39
+ * Specifically, landscape left and right are inverted:
40
+ *
41
+ * - landscapeLeft in device orientation is landscapeRight in interface orientation
42
+ * - landscapeRight in device orientation is landscapeLeft in interface orientation
43
+ *
44
+ * This is a behavior of the native API.
45
+ *
46
+ * When you pass an orientation value, do provide orientationType
47
+ * as well if the orientation value is not an interface orientation.
48
+ * Example: when using listenForDeviceOrientationChanges.
49
+ *
50
+ * @param orientation any lockable orientation enum value
51
+ * @param orientationType any orientation type enum value
52
+ */
53
+ static lockTo(orientation, orientationType = OrientationType.interface) {
54
+ if (orientationType === OrientationType.interface) {
55
+ Module.lockTo(orientation);
56
+ return;
57
+ }
58
+ if (orientation === Orientation.landscapeLeft) {
59
+ Module.lockTo(Orientation.landscapeRight);
60
+ return;
61
+ }
62
+ if (orientation === Orientation.landscapeRight) {
63
+ Module.lockTo(Orientation.landscapeLeft);
64
+ return;
65
+ }
34
66
  Module.lockTo(orientation);
35
67
  }
36
68
  static unlock() {
@@ -63,6 +95,25 @@ class RNOrientationDirector {
63
95
  static convertAutoRotationToHumanReadableString(autoRotation) {
64
96
  return RNOrientationDirector._humanReadableAutoRotationsResource[autoRotation];
65
97
  }
98
+
99
+ /**
100
+ * This method checks if the given orientation is lockable
101
+ * by interface perspective.
102
+ *
103
+ * All orientations are lockable except for unknown, faceUp
104
+ * and faceDown.
105
+ *
106
+ * This method is useful when you want to lock the interface
107
+ * orientation from a given device orientation.
108
+ *
109
+ * Example: with listenForDeviceOrientationChanges
110
+ *
111
+ * @param orientation any orientation enum value
112
+ * @returns true if the orientation is lockable
113
+ */
114
+ static isLockableOrientation(orientation) {
115
+ return !(orientation === Orientation.unknown || orientation === Orientation.faceUp || orientation === Orientation.faceDown);
116
+ }
66
117
  }
67
118
  export default RNOrientationDirector;
68
119
  //# sourceMappingURL=RNOrientationDirector.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Platform","Module","Orientation","AutoRotation","EventEmitter","RNOrientationDirector","_humanReadableOrientationsResource","unknown","portrait","portraitUpsideDown","landscapeLeft","landscapeRight","faceUp","faceDown","_humanReadableAutoRotationsResource","enabled","disabled","setHumanReadableOrientations","resource","setHumanReadableAutoRotations","getInterfaceOrientation","getDeviceOrientation","lockTo","orientation","unlock","isLocked","isAutoRotationEnabled","OS","resetSupportedInterfaceOrientations","listenForDeviceOrientationChanges","callback","addDeviceOrientationDidChangeListener","listenForInterfaceOrientationChanges","addInterfaceOrientationDidChangeListener","listenForLockChanges","addLockDidChangeListener","convertOrientationToHumanReadableString","convertAutoRotationToHumanReadableString","autoRotation"],"sourceRoot":"../../src","sources":["RNOrientationDirector.ts"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,OAAOC,MAAM,MAAM,UAAU;AAE7B,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,YAAY,QAAQ,2BAA2B;AAKxD,OAAOC,YAAY,MAAM,gBAAgB;AAEzC,MAAMC,qBAAqB,CAAC;EAC1B,OAAeC,kCAAkC,GAC/C;IACE,CAACJ,WAAW,CAACK,OAAO,GAA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CAAC,GACjCvB,YAAY,CAACY,OAAO,GACpBZ,YAAY,CAACa,QAAQ;EAC3B;EAEA,OAAOY,mCAAmCA,CAAA,EAAG;IAC3C3B,MAAM,CAAC2B,mCAAmC,CAAC,CAAC;EAC9C;EAEA,OAAOC,iCAAiCA,CACtCC,QAAiD,EACjD;IACA,OAAO1B,YAAY,CAAC2B,qCAAqC,CAACD,QAAQ,CAAC;EACrE;EAEA,OAAOE,oCAAoCA,CACzCF,QAAiD,EACjD;IACA,OAAO1B,YAAY,CAAC6B,wCAAwC,CAACH,QAAQ,CAAC;EACxE;EAEA,OAAOI,oBAAoBA,CAACJ,QAAsC,EAAE;IAClE,OAAO1B,YAAY,CAAC+B,wBAAwB,CAACL,QAAQ,CAAC;EACxD;EAEA,OAAOM,uCAAuCA,CAACb,WAAwB,EAAE;IACvE,OAAOlB,qBAAqB,CAACC,kCAAkC,CAC7DiB,WAAW,CACZ;EACH;EAEA,OAAOc,wCAAwCA,CAACC,YAA0B,EAAE;IAC1E,OAAOjC,qBAAqB,CAACS,mCAAmC,CAC9DwB,YAAY,CACb;EACH;AACF;AAEA,eAAejC,qBAAqB","ignoreList":[]}
1
+ {"version":3,"names":["Platform","Module","Orientation","AutoRotation","OrientationType","EventEmitter","RNOrientationDirector","_humanReadableOrientationsResource","unknown","portrait","portraitUpsideDown","landscapeLeft","landscapeRight","faceUp","faceDown","_humanReadableAutoRotationsResource","enabled","disabled","setHumanReadableOrientations","resource","setHumanReadableAutoRotations","getInterfaceOrientation","getDeviceOrientation","lockTo","orientation","orientationType","interface","unlock","isLocked","isAutoRotationEnabled","OS","resetSupportedInterfaceOrientations","listenForDeviceOrientationChanges","callback","addDeviceOrientationDidChangeListener","listenForInterfaceOrientationChanges","addInterfaceOrientationDidChangeListener","listenForLockChanges","addLockDidChangeListener","convertOrientationToHumanReadableString","convertAutoRotationToHumanReadableString","autoRotation","isLockableOrientation"],"sourceRoot":"../../src","sources":["RNOrientationDirector.ts"],"mappings":"AAAA,SAAS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;EAEA,OAAOM,uCAAuCA,CAACf,WAAwB,EAAE;IACvE,OAAOlB,qBAAqB,CAACC,kCAAkC,CAC7DiB,WAAW,CACZ;EACH;EAEA,OAAOgB,wCAAwCA,CAACC,YAA0B,EAAE;IAC1E,OAAOnC,qBAAqB,CAACS,mCAAmC,CAC9D0B,YAAY,CACb;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,qBAAqBA,CAC1BlB,WAAwB,EACY;IACpC,OAAO,EACLA,WAAW,KAAKtB,WAAW,CAACM,OAAO,IACnCgB,WAAW,KAAKtB,WAAW,CAACW,MAAM,IAClCW,WAAW,KAAKtB,WAAW,CAACY,QAAQ,CACrC;EACH;AACF;AAEA,eAAeR,qBAAqB","ignoreList":[]}
@@ -1,5 +1,6 @@
1
1
  export { Orientation } from './types/Orientation.enum';
2
2
  export { AutoRotation } from './types/AutoRotation.enum';
3
+ export { OrientationType } from './types/OrientationType.enum';
3
4
  import useDeviceOrientation from './hooks/useDeviceOrientation.hook';
4
5
  export { useDeviceOrientation };
5
6
  import useInterfaceOrientation from './hooks/useInterfaceOrientation.hook';
@@ -1 +1 @@
1
- {"version":3,"names":["Orientation","AutoRotation","useDeviceOrientation","useInterfaceOrientation","useIsInterfaceOrientationLocked","RNOrientationDirector"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,WAAW,QAAQ,0BAA0B;AACtD,SAASC,YAAY,QAAQ,2BAA2B;AAExD,OAAOC,oBAAoB,MAAM,mCAAmC;AACpE,SAASA,oBAAoB;AAE7B,OAAOC,uBAAuB,MAAM,sCAAsC;AAC1E,SAASA,uBAAuB;AAEhC,OAAOC,+BAA+B,MAAM,8CAA8C;AAC1F,SAASA,+BAA+B;AAExC,OAAOC,qBAAqB,MAAM,yBAAyB;AAC3D,eAAeA,qBAAqB","ignoreList":[]}
1
+ {"version":3,"names":["Orientation","AutoRotation","OrientationType","useDeviceOrientation","useInterfaceOrientation","useIsInterfaceOrientationLocked","RNOrientationDirector"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,WAAW,QAAQ,0BAA0B;AACtD,SAASC,YAAY,QAAQ,2BAA2B;AACxD,SAASC,eAAe,QAAQ,8BAA8B;AAE9D,OAAOC,oBAAoB,MAAM,mCAAmC;AACpE,SAASA,oBAAoB;AAE7B,OAAOC,uBAAuB,MAAM,sCAAsC;AAC1E,SAASA,uBAAuB;AAEhC,OAAOC,+BAA+B,MAAM,8CAA8C;AAC1F,SAASA,+BAA+B;AAExC,OAAOC,qBAAqB,MAAM,yBAAyB;AAC3D,eAAeA,qBAAqB","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ export let OrientationType = /*#__PURE__*/function (OrientationType) {
2
+ OrientationType["device"] = "device";
3
+ OrientationType["interface"] = "interface";
4
+ return OrientationType;
5
+ }({});
6
+ //# sourceMappingURL=OrientationType.enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["OrientationType"],"sourceRoot":"../../../src","sources":["types/OrientationType.enum.ts"],"mappings":"AAAA,WAAYA,eAAe,0BAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA","ignoreList":[]}
@@ -1,6 +1,7 @@
1
1
  import type { HumanReadableOrientationsResource } from './types/HumanReadableOrientationsResource.type';
2
2
  import { Orientation } from './types/Orientation.enum';
3
3
  import { AutoRotation } from './types/AutoRotation.enum';
4
+ import { OrientationType } from './types/OrientationType.enum';
4
5
  import type { OrientationEvent } from './types/OrientationEvent.interface';
5
6
  import type { LockableOrientation } from './types/LockableOrientation.type';
6
7
  import type { LockedEvent } from './types/LockedEvent.interface';
@@ -12,7 +13,25 @@ declare class RNOrientationDirector {
12
13
  setHumanReadableAutoRotations(resource: HumanReadableAutoRotationsResource): void;
13
14
  static getInterfaceOrientation(): Promise<Orientation>;
14
15
  static getDeviceOrientation(): Promise<Orientation>;
15
- static lockTo(orientation: LockableOrientation): void;
16
+ /**
17
+ * Please be aware that device orientation is not the
18
+ * same as interface orientation.
19
+ *
20
+ * Specifically, landscape left and right are inverted:
21
+ *
22
+ * - landscapeLeft in device orientation is landscapeRight in interface orientation
23
+ * - landscapeRight in device orientation is landscapeLeft in interface orientation
24
+ *
25
+ * This is a behavior of the native API.
26
+ *
27
+ * When you pass an orientation value, do provide orientationType
28
+ * as well if the orientation value is not an interface orientation.
29
+ * Example: when using listenForDeviceOrientationChanges.
30
+ *
31
+ * @param orientation any lockable orientation enum value
32
+ * @param orientationType any orientation type enum value
33
+ */
34
+ static lockTo(orientation: LockableOrientation, orientationType?: OrientationType): void;
16
35
  static unlock(): void;
17
36
  static isLocked(): boolean;
18
37
  static isAutoRotationEnabled(): AutoRotation;
@@ -22,6 +41,22 @@ declare class RNOrientationDirector {
22
41
  static listenForLockChanges(callback: (event: LockedEvent) => void): import("react-native").EmitterSubscription;
23
42
  static convertOrientationToHumanReadableString(orientation: Orientation): string;
24
43
  static convertAutoRotationToHumanReadableString(autoRotation: AutoRotation): string;
44
+ /**
45
+ * This method checks if the given orientation is lockable
46
+ * by interface perspective.
47
+ *
48
+ * All orientations are lockable except for unknown, faceUp
49
+ * and faceDown.
50
+ *
51
+ * This method is useful when you want to lock the interface
52
+ * orientation from a given device orientation.
53
+ *
54
+ * Example: with listenForDeviceOrientationChanges
55
+ *
56
+ * @param orientation any orientation enum value
57
+ * @returns true if the orientation is lockable
58
+ */
59
+ static isLockableOrientation(orientation: Orientation): orientation is LockableOrientation;
25
60
  }
26
61
  export default RNOrientationDirector;
27
62
  //# sourceMappingURL=RNOrientationDirector.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RNOrientationDirector.d.ts","sourceRoot":"","sources":["../../../src/RNOrientationDirector.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,gDAAgD,CAAC;AACxG,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD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E,MAAM,CAAC,uCAAuC,CAAC,WAAW,EAAE,WAAW;IAMvE,MAAM,CAAC,wCAAwC,CAAC,YAAY,EAAE,YAAY;IAM1E;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,qBAAqB,CAC1B,WAAW,EAAE,WAAW,GACvB,WAAW,IAAI,mBAAmB;CAOtC;AAED,eAAe,qBAAqB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export { Orientation } from './types/Orientation.enum';
2
2
  export { AutoRotation } from './types/AutoRotation.enum';
3
+ export { OrientationType } from './types/OrientationType.enum';
3
4
  import useDeviceOrientation from './hooks/useDeviceOrientation.hook';
4
5
  export { useDeviceOrientation };
5
6
  import useInterfaceOrientation from './hooks/useInterfaceOrientation.hook';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,OAAO,uBAAuB,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC,OAAO,+BAA+B,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EAAE,+BAA+B,EAAE,CAAC;AAE3C,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAE/D,OAAO,oBAAoB,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC,OAAO,uBAAuB,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,uBAAuB,EAAE,CAAC;AAEnC,OAAO,+BAA+B,MAAM,8CAA8C,CAAC;AAC3F,OAAO,EAAE,+BAA+B,EAAE,CAAC;AAE3C,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,eAAe,qBAAqB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare enum OrientationType {
2
+ device = "device",
3
+ interface = "interface"
4
+ }
5
+ //# sourceMappingURL=OrientationType.enum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OrientationType.enum.d.ts","sourceRoot":"","sources":["../../../../src/types/OrientationType.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACzB,MAAM,WAAW;IACjB,SAAS,cAAc;CACxB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-orientation-director",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "A Modern React Native library that allows you to access orientation",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -3,6 +3,7 @@ import Module from './module';
3
3
  import type { HumanReadableOrientationsResource } from './types/HumanReadableOrientationsResource.type';
4
4
  import { Orientation } from './types/Orientation.enum';
5
5
  import { AutoRotation } from './types/AutoRotation.enum';
6
+ import { OrientationType } from './types/OrientationType.enum';
6
7
  import type { OrientationEvent } from './types/OrientationEvent.interface';
7
8
  import type { LockableOrientation } from './types/LockableOrientation.type';
8
9
  import type { LockedEvent } from './types/LockedEvent.interface';
@@ -44,7 +45,43 @@ class RNOrientationDirector {
44
45
  return Module.getDeviceOrientation();
45
46
  }
46
47
 
47
- static lockTo(orientation: LockableOrientation) {
48
+ /**
49
+ * Please be aware that device orientation is not the
50
+ * same as interface orientation.
51
+ *
52
+ * Specifically, landscape left and right are inverted:
53
+ *
54
+ * - landscapeLeft in device orientation is landscapeRight in interface orientation
55
+ * - landscapeRight in device orientation is landscapeLeft in interface orientation
56
+ *
57
+ * This is a behavior of the native API.
58
+ *
59
+ * When you pass an orientation value, do provide orientationType
60
+ * as well if the orientation value is not an interface orientation.
61
+ * Example: when using listenForDeviceOrientationChanges.
62
+ *
63
+ * @param orientation any lockable orientation enum value
64
+ * @param orientationType any orientation type enum value
65
+ */
66
+ static lockTo(
67
+ orientation: LockableOrientation,
68
+ orientationType: OrientationType = OrientationType.interface
69
+ ) {
70
+ if (orientationType === OrientationType.interface) {
71
+ Module.lockTo(orientation);
72
+ return;
73
+ }
74
+
75
+ if (orientation === Orientation.landscapeLeft) {
76
+ Module.lockTo(Orientation.landscapeRight);
77
+ return;
78
+ }
79
+
80
+ if (orientation === Orientation.landscapeRight) {
81
+ Module.lockTo(Orientation.landscapeLeft);
82
+ return;
83
+ }
84
+
48
85
  Module.lockTo(orientation);
49
86
  }
50
87
 
@@ -96,6 +133,31 @@ class RNOrientationDirector {
96
133
  autoRotation
97
134
  ];
98
135
  }
136
+
137
+ /**
138
+ * This method checks if the given orientation is lockable
139
+ * by interface perspective.
140
+ *
141
+ * All orientations are lockable except for unknown, faceUp
142
+ * and faceDown.
143
+ *
144
+ * This method is useful when you want to lock the interface
145
+ * orientation from a given device orientation.
146
+ *
147
+ * Example: with listenForDeviceOrientationChanges
148
+ *
149
+ * @param orientation any orientation enum value
150
+ * @returns true if the orientation is lockable
151
+ */
152
+ static isLockableOrientation(
153
+ orientation: Orientation
154
+ ): orientation is LockableOrientation {
155
+ return !(
156
+ orientation === Orientation.unknown ||
157
+ orientation === Orientation.faceUp ||
158
+ orientation === Orientation.faceDown
159
+ );
160
+ }
99
161
  }
100
162
 
101
163
  export default RNOrientationDirector;
package/src/index.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  export { Orientation } from './types/Orientation.enum';
2
2
  export { AutoRotation } from './types/AutoRotation.enum';
3
+ export { OrientationType } from './types/OrientationType.enum';
3
4
 
4
5
  import useDeviceOrientation from './hooks/useDeviceOrientation.hook';
5
6
  export { useDeviceOrientation };
@@ -0,0 +1,4 @@
1
+ export enum OrientationType {
2
+ device = 'device',
3
+ interface = 'interface',
4
+ }