react-native-orientation-director 2.0.0 → 2.2.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 +21 -0
- package/android/src/main/java/com/orientationdirector/implementation/Orientation.kt +1 -0
- package/android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt +32 -2
- package/android/src/main/java/com/orientationdirector/implementation/Utils.kt +10 -0
- package/android/src/test/java/com/orientationdirector/implementation/OrientationDirectorModuleImplTest.kt +11 -0
- package/ios/implementation/EventManager.swift +7 -7
- package/ios/implementation/Orientation.swift +1 -1
- package/ios/implementation/OrientationDirectorImpl.swift +32 -24
- package/ios/implementation/SensorListener.swift +1 -1
- package/ios/implementation/Utils.swift +9 -37
- package/lib/commonjs/RNOrientationDirector.js +53 -1
- package/lib/commonjs/RNOrientationDirector.js.map +1 -1
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/types/Orientation.enum.js +3 -2
- package/lib/commonjs/types/Orientation.enum.js.map +1 -1
- package/lib/commonjs/types/OrientationType.enum.js +12 -0
- package/lib/commonjs/types/OrientationType.enum.js.map +1 -0
- package/lib/module/RNOrientationDirector.js +53 -1
- package/lib/module/RNOrientationDirector.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/types/Orientation.enum.js +3 -2
- package/lib/module/types/Orientation.enum.js.map +1 -1
- package/lib/module/types/OrientationType.enum.js +6 -0
- package/lib/module/types/OrientationType.enum.js.map +1 -0
- package/lib/typescript/src/RNOrientationDirector.d.ts +36 -1
- package/lib/typescript/src/RNOrientationDirector.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/types/LockableOrientation.type.d.ts +1 -1
- package/lib/typescript/src/types/LockableOrientation.type.d.ts.map +1 -1
- package/lib/typescript/src/types/Orientation.enum.d.ts +3 -2
- package/lib/typescript/src/types/Orientation.enum.d.ts.map +1 -1
- package/lib/typescript/src/types/OrientationType.enum.d.ts +5 -0
- package/lib/typescript/src/types/OrientationType.enum.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/RNOrientationDirector.ts +64 -1
- package/src/index.tsx +1 -0
- package/src/types/LockableOrientation.type.ts +2 -1
- package/src/types/Orientation.enum.ts +3 -2
- package/src/types/OrientationType.enum.ts +4 -0
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
|
|
@@ -82,7 +82,22 @@ class OrientationDirectorModuleImpl internal constructor(private val context: Re
|
|
|
82
82
|
context.currentActivity?.requestedOrientation = screenOrientation
|
|
83
83
|
|
|
84
84
|
updateIsLockedTo(true)
|
|
85
|
-
|
|
85
|
+
|
|
86
|
+
val orientationCanBeUpdatedDirectly = jsOrientation != Orientation.LANDSCAPE;
|
|
87
|
+
if (orientationCanBeUpdatedDirectly) {
|
|
88
|
+
updateLastInterfaceOrientationTo(jsOrientation)
|
|
89
|
+
return
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
val lastInterfaceOrientationIsAlreadyInLandscape = lastInterfaceOrientation == Orientation.LANDSCAPE_RIGHT
|
|
93
|
+
|| lastInterfaceOrientation == Orientation.LANDSCAPE_LEFT
|
|
94
|
+
if (lastInterfaceOrientationIsAlreadyInLandscape) {
|
|
95
|
+
updateLastInterfaceOrientationTo(lastInterfaceOrientation)
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
val systemDefaultLandscapeOrientation = Orientation.LANDSCAPE_RIGHT
|
|
100
|
+
updateLastInterfaceOrientationTo(systemDefaultLandscapeOrientation)
|
|
86
101
|
}
|
|
87
102
|
|
|
88
103
|
fun unlock() {
|
|
@@ -150,7 +165,8 @@ class OrientationDirectorModuleImpl internal constructor(private val context: Re
|
|
|
150
165
|
return
|
|
151
166
|
}
|
|
152
167
|
|
|
153
|
-
|
|
168
|
+
val supportsLandscape = mUtils.getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE;
|
|
169
|
+
if (isLocked && !supportsLandscape) {
|
|
154
170
|
return
|
|
155
171
|
}
|
|
156
172
|
|
|
@@ -167,6 +183,20 @@ class OrientationDirectorModuleImpl internal constructor(private val context: Re
|
|
|
167
183
|
newInterfaceOrientation = mUtils.convertToOrientationFromScreenRotation(rotation)
|
|
168
184
|
}
|
|
169
185
|
|
|
186
|
+
/**
|
|
187
|
+
* This differs from iOS because we can't read the actual orientation of the interface,
|
|
188
|
+
* we read its rotation.
|
|
189
|
+
* This means that even if the requestedOrientation of the currentActivity is locked to landscape
|
|
190
|
+
* it reads every possible orientation and this is not what we want.
|
|
191
|
+
* Instead, we check that its value is either LANDSCAPE_RIGHT or LANDSCAPE_LEFT, otherwise we
|
|
192
|
+
* exit
|
|
193
|
+
*/
|
|
194
|
+
val newInterfaceOrientationIsNotLandscape = newInterfaceOrientation != Orientation.LANDSCAPE_RIGHT
|
|
195
|
+
&& newInterfaceOrientation != Orientation.LANDSCAPE_LEFT;
|
|
196
|
+
if (supportsLandscape && newInterfaceOrientationIsNotLandscape) {
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
|
|
170
200
|
if (newInterfaceOrientation == lastInterfaceOrientation) {
|
|
171
201
|
return
|
|
172
202
|
}
|
|
@@ -53,6 +53,7 @@ class Utils(private val context: ReactContext) {
|
|
|
53
53
|
Orientation.LANDSCAPE_RIGHT -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
|
54
54
|
Orientation.PORTRAIT_UPSIDE_DOWN -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
|
|
55
55
|
Orientation.LANDSCAPE_LEFT -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
|
|
56
|
+
Orientation.LANDSCAPE -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
|
56
57
|
else -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
|
57
58
|
}
|
|
58
59
|
}
|
|
@@ -62,6 +63,7 @@ class Utils(private val context: ReactContext) {
|
|
|
62
63
|
2 -> Orientation.LANDSCAPE_RIGHT
|
|
63
64
|
3 -> Orientation.PORTRAIT_UPSIDE_DOWN
|
|
64
65
|
4 -> Orientation.LANDSCAPE_LEFT
|
|
66
|
+
5 -> Orientation.LANDSCAPE
|
|
65
67
|
else -> Orientation.PORTRAIT
|
|
66
68
|
}
|
|
67
69
|
}
|
|
@@ -84,4 +86,12 @@ class Utils(private val context: ReactContext) {
|
|
|
84
86
|
else -> Orientation.UNKNOWN
|
|
85
87
|
}
|
|
86
88
|
}
|
|
89
|
+
|
|
90
|
+
fun getRequestedOrientation(): Int {
|
|
91
|
+
if (context.currentActivity?.requestedOrientation == null) {
|
|
92
|
+
return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return context.currentActivity!!.requestedOrientation;
|
|
96
|
+
}
|
|
87
97
|
}
|
|
@@ -144,6 +144,17 @@ class OrientationDirectorModuleImplTest {
|
|
|
144
144
|
)
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
@Test
|
|
148
|
+
fun assert_interface_orientation_matches_locked_to_landscape() {
|
|
149
|
+
mModule.lockTo(5)
|
|
150
|
+
|
|
151
|
+
assertEquals(
|
|
152
|
+
"When the interface is locked to landscape, getInterfaceOrientation should return landscape right",
|
|
153
|
+
Orientation.LANDSCAPE_RIGHT,
|
|
154
|
+
mModule.getInterfaceOrientation()
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
147
158
|
@Test
|
|
148
159
|
fun assert_is_locked_reset_when_unlock_is_executed() {
|
|
149
160
|
mModule.lockTo(1)
|
|
@@ -7,15 +7,15 @@
|
|
|
7
7
|
|
|
8
8
|
import Foundation
|
|
9
9
|
|
|
10
|
-
@objc public class EventManager
|
|
11
|
-
@objc public weak var delegate: OrientationEventEmitterDelegate?
|
|
10
|
+
@objc public class EventManager: NSObject {
|
|
11
|
+
@objc public weak var delegate: OrientationEventEmitterDelegate?
|
|
12
12
|
|
|
13
13
|
func sendDeviceOrientationDidChange(orientationValue: Int) {
|
|
14
14
|
guard let delegate = delegate else {
|
|
15
15
|
return
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
if
|
|
18
|
+
if !delegate.isJsListening {
|
|
19
19
|
return
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -28,20 +28,20 @@ import Foundation
|
|
|
28
28
|
return
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
if
|
|
31
|
+
if !delegate.isJsListening {
|
|
32
32
|
return
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
let params = Dictionary(dictionaryLiteral: ("orientation", orientationValue))
|
|
36
36
|
delegate.sendEvent(name: Event.InterfaceOrientationDidChange.rawValue, params: params as NSDictionary)
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
func sendLockDidChange(value: Bool) {
|
|
40
40
|
guard let delegate = delegate else {
|
|
41
41
|
return
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
if
|
|
44
|
+
if !delegate.isJsListening {
|
|
45
45
|
return
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -65,6 +65,6 @@ public extension EventManager {
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
@objc static var supportedEvents: [String] {
|
|
68
|
-
return Event.allCases.map(\.rawValue)
|
|
68
|
+
return Event.allCases.map(\.rawValue)
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
import Foundation
|
|
9
9
|
|
|
10
10
|
@objc public enum Orientation: Int {
|
|
11
|
-
case UNKNOWN, PORTRAIT, LANDSCAPE_RIGHT, PORTRAIT_UPSIDE_DOWN, LANDSCAPE_LEFT, FACE_UP, FACE_DOWN
|
|
11
|
+
case UNKNOWN, PORTRAIT, LANDSCAPE_RIGHT, PORTRAIT_UPSIDE_DOWN, LANDSCAPE_LEFT, LANDSCAPE, FACE_UP, FACE_DOWN
|
|
12
12
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import Foundation
|
|
9
9
|
import UIKit
|
|
10
10
|
|
|
11
|
-
@objc public class OrientationDirectorImpl
|
|
11
|
+
@objc public class OrientationDirectorImpl: NSObject {
|
|
12
12
|
private static let TAG = "OrientationDirectorImpl"
|
|
13
13
|
|
|
14
14
|
private let bundleManager: BundleManager = BundleManager()
|
|
@@ -50,7 +50,7 @@ import UIKit
|
|
|
50
50
|
@objc public func getDeviceOrientation() -> Orientation {
|
|
51
51
|
return lastDeviceOrientation
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
@objc public func getIsLocked() -> Bool {
|
|
55
55
|
return isLocked
|
|
56
56
|
}
|
|
@@ -61,7 +61,21 @@ import UIKit
|
|
|
61
61
|
self.requestInterfaceUpdateTo(mask: mask)
|
|
62
62
|
|
|
63
63
|
updateIsLockedTo(value: true)
|
|
64
|
-
|
|
64
|
+
|
|
65
|
+
let orientationCanBeUpdatedDirectly = jsOrientation != Orientation.LANDSCAPE
|
|
66
|
+
if orientationCanBeUpdatedDirectly {
|
|
67
|
+
updateLastInterfaceOrientationTo(value: jsOrientation)
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let lastInterfaceOrientationIsAlreadyInLandscape = lastInterfaceOrientation == Orientation.LANDSCAPE_RIGHT || lastInterfaceOrientation == Orientation.LANDSCAPE_LEFT
|
|
72
|
+
if lastInterfaceOrientationIsAlreadyInLandscape {
|
|
73
|
+
updateLastInterfaceOrientationTo(value: lastInterfaceOrientation)
|
|
74
|
+
return
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let systemDefaultLandscapeOrientation = Orientation.LANDSCAPE_RIGHT
|
|
78
|
+
updateLastInterfaceOrientationTo(value: systemDefaultLandscapeOrientation)
|
|
65
79
|
}
|
|
66
80
|
|
|
67
81
|
@objc public func unlock() {
|
|
@@ -78,20 +92,20 @@ import UIKit
|
|
|
78
92
|
|
|
79
93
|
let lastMask = utils.convertToMaskFrom(jsOrientation: lastInterfaceOrientation)
|
|
80
94
|
let isLastMaskSupported = self.supportedInterfaceOrientations.contains(lastMask)
|
|
81
|
-
if
|
|
95
|
+
if isLastMaskSupported {
|
|
82
96
|
return
|
|
83
97
|
}
|
|
84
98
|
|
|
85
99
|
let supportedInterfaceOrientations = bundleManager.getSupportedInterfaceOrientations()
|
|
86
|
-
if
|
|
100
|
+
if supportedInterfaceOrientations.contains(UIInterfaceOrientationMask.portrait) {
|
|
87
101
|
self.updateLastInterfaceOrientationTo(value: Orientation.PORTRAIT)
|
|
88
102
|
return
|
|
89
103
|
}
|
|
90
|
-
if
|
|
104
|
+
if supportedInterfaceOrientations.contains(UIInterfaceOrientationMask.landscapeRight) {
|
|
91
105
|
self.updateLastInterfaceOrientationTo(value: Orientation.LANDSCAPE_RIGHT)
|
|
92
106
|
return
|
|
93
107
|
}
|
|
94
|
-
if
|
|
108
|
+
if supportedInterfaceOrientations.contains(UIInterfaceOrientationMask.landscapeLeft) {
|
|
95
109
|
self.updateLastInterfaceOrientationTo(value: Orientation.LANDSCAPE_LEFT)
|
|
96
110
|
return
|
|
97
111
|
}
|
|
@@ -104,10 +118,8 @@ import UIKit
|
|
|
104
118
|
return supportedInterfaceOrientations.reduce(UIInterfaceOrientationMask()) { $0.union($1) }
|
|
105
119
|
}
|
|
106
120
|
|
|
107
|
-
// TODO: FIX BECAUSE IT ALWAYS RETURNS PORTRAIT AND ITS BROKEN
|
|
108
121
|
private func initInterfaceOrientation() -> Orientation {
|
|
109
|
-
|
|
110
|
-
return utils.convertToOrientationFrom(uiInterfaceOrientation: interfaceOrientation)
|
|
122
|
+
return self.getOrientationFromInterface()
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
private func initDeviceOrientation() -> Orientation {
|
|
@@ -116,7 +128,7 @@ import UIKit
|
|
|
116
128
|
|
|
117
129
|
private func initIsLocked() -> Bool {
|
|
118
130
|
let supportedOrientations = bundleManager.getSupportedInterfaceOrientations()
|
|
119
|
-
if
|
|
131
|
+
if supportedOrientations.count > 1 {
|
|
120
132
|
return false
|
|
121
133
|
}
|
|
122
134
|
|
|
@@ -156,25 +168,16 @@ import UIKit
|
|
|
156
168
|
}
|
|
157
169
|
|
|
158
170
|
private func adaptInterfaceTo(deviceOrientation: Orientation) {
|
|
159
|
-
|
|
171
|
+
let supportsLandscape = self.supportedInterfaceOrientations.contains(.landscape)
|
|
172
|
+
if isLocked && !supportsLandscape {
|
|
160
173
|
return
|
|
161
174
|
}
|
|
162
175
|
|
|
163
|
-
if
|
|
164
|
-
return
|
|
165
|
-
}
|
|
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) {
|
|
176
|
+
if deviceOrientation == Orientation.FACE_UP || deviceOrientation == Orientation.FACE_DOWN {
|
|
175
177
|
return
|
|
176
178
|
}
|
|
177
179
|
|
|
180
|
+
let newInterfaceOrientation = self.getOrientationFromInterface()
|
|
178
181
|
updateLastInterfaceOrientationTo(value: newInterfaceOrientation)
|
|
179
182
|
}
|
|
180
183
|
|
|
@@ -187,4 +190,9 @@ import UIKit
|
|
|
187
190
|
self.eventManager.sendInterfaceOrientationDidChange(orientationValue: value.rawValue)
|
|
188
191
|
lastInterfaceOrientation = value
|
|
189
192
|
}
|
|
193
|
+
|
|
194
|
+
private func getOrientationFromInterface() -> Orientation {
|
|
195
|
+
let interfaceOrientation = utils.getInterfaceOrientation()
|
|
196
|
+
return utils.convertToOrientationFrom(uiInterfaceOrientation: interfaceOrientation)
|
|
197
|
+
}
|
|
190
198
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import Foundation
|
|
9
9
|
|
|
10
10
|
public class SensorListener {
|
|
11
|
-
private var onOrientationDidChangeCallback: ((_ deviceOrientation: UIDeviceOrientation) -> Void)?
|
|
11
|
+
private var onOrientationDidChangeCallback: ((_ deviceOrientation: UIDeviceOrientation) -> Void)?
|
|
12
12
|
|
|
13
13
|
init() {
|
|
14
14
|
NotificationCenter.default.addObserver(
|
|
@@ -13,7 +13,7 @@ class Utils {
|
|
|
13
13
|
|
|
14
14
|
// TODO: Add .unknown
|
|
15
15
|
public func convertToOrientationFrom(uiInterfaceOrientation: UIInterfaceOrientation) -> Orientation {
|
|
16
|
-
switch
|
|
16
|
+
switch uiInterfaceOrientation {
|
|
17
17
|
case .landscapeRight:
|
|
18
18
|
return .LANDSCAPE_RIGHT
|
|
19
19
|
case .portraitUpsideDown:
|
|
@@ -26,7 +26,7 @@ class Utils {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
public func convertToOrientationFrom(deviceOrientation: UIDeviceOrientation) -> Orientation {
|
|
29
|
-
switch
|
|
29
|
+
switch deviceOrientation {
|
|
30
30
|
case .landscapeRight:
|
|
31
31
|
return .LANDSCAPE_RIGHT
|
|
32
32
|
case .portraitUpsideDown:
|
|
@@ -43,26 +43,15 @@ class Utils {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
public func convertToOrientationFrom(jsValue: NSNumber) -> Orientation {
|
|
46
|
-
switch
|
|
46
|
+
switch jsValue {
|
|
47
47
|
case 2:
|
|
48
48
|
return .LANDSCAPE_RIGHT
|
|
49
49
|
case 3:
|
|
50
50
|
return .PORTRAIT_UPSIDE_DOWN
|
|
51
51
|
case 4:
|
|
52
52
|
return .LANDSCAPE_LEFT
|
|
53
|
-
|
|
54
|
-
return .
|
|
55
|
-
}
|
|
56
|
-
}
|
|
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
|
|
53
|
+
case 5:
|
|
54
|
+
return .LANDSCAPE
|
|
66
55
|
default:
|
|
67
56
|
return .PORTRAIT
|
|
68
57
|
}
|
|
@@ -73,7 +62,7 @@ class Utils {
|
|
|
73
62
|
https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations
|
|
74
63
|
*/
|
|
75
64
|
public func convertToMaskFrom(jsOrientation: Orientation) -> UIInterfaceOrientationMask {
|
|
76
|
-
switch
|
|
65
|
+
switch jsOrientation {
|
|
77
66
|
case .PORTRAIT:
|
|
78
67
|
return .portrait
|
|
79
68
|
case .LANDSCAPE_RIGHT:
|
|
@@ -82,25 +71,8 @@ class Utils {
|
|
|
82
71
|
return .portraitUpsideDown
|
|
83
72
|
case .LANDSCAPE_LEFT:
|
|
84
73
|
return .landscapeLeft
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
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
|
|
74
|
+
case .LANDSCAPE:
|
|
75
|
+
return .landscape
|
|
104
76
|
default:
|
|
105
77
|
return .all
|
|
106
78
|
}
|
|
@@ -111,7 +83,7 @@ class Utils {
|
|
|
111
83
|
return UIInterfaceOrientation.unknown
|
|
112
84
|
}
|
|
113
85
|
|
|
114
|
-
return windowScene.interfaceOrientation
|
|
86
|
+
return windowScene.interfaceOrientation
|
|
115
87
|
}
|
|
116
88
|
|
|
117
89
|
/* This function is needed to get the current available window.
|
|
@@ -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 {
|
|
@@ -17,6 +18,7 @@ class RNOrientationDirector {
|
|
|
17
18
|
[_Orientation.Orientation.portraitUpsideDown]: 'Portrait Upside Down',
|
|
18
19
|
[_Orientation.Orientation.landscapeLeft]: 'Landscape Left',
|
|
19
20
|
[_Orientation.Orientation.landscapeRight]: 'Landscape Right',
|
|
21
|
+
[_Orientation.Orientation.landscape]: 'Landscape',
|
|
20
22
|
[_Orientation.Orientation.faceUp]: 'Face Up',
|
|
21
23
|
[_Orientation.Orientation.faceDown]: 'Face Down'
|
|
22
24
|
};
|
|
@@ -37,7 +39,38 @@ class RNOrientationDirector {
|
|
|
37
39
|
static getDeviceOrientation() {
|
|
38
40
|
return _module.default.getDeviceOrientation();
|
|
39
41
|
}
|
|
40
|
-
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Please be aware that device orientation is not the
|
|
45
|
+
* same as interface orientation.
|
|
46
|
+
*
|
|
47
|
+
* Specifically, landscape left and right are inverted:
|
|
48
|
+
*
|
|
49
|
+
* - landscapeLeft in device orientation is landscapeRight in interface orientation
|
|
50
|
+
* - landscapeRight in device orientation is landscapeLeft in interface orientation
|
|
51
|
+
*
|
|
52
|
+
* This is a behavior of the native API.
|
|
53
|
+
*
|
|
54
|
+
* When you pass an orientation value, do provide orientationType
|
|
55
|
+
* as well if the orientation value is not an interface orientation.
|
|
56
|
+
* Example: when using listenForDeviceOrientationChanges.
|
|
57
|
+
*
|
|
58
|
+
* @param orientation any lockable orientation enum value
|
|
59
|
+
* @param orientationType any orientation type enum value
|
|
60
|
+
*/
|
|
61
|
+
static lockTo(orientation, orientationType = _OrientationType.OrientationType.interface) {
|
|
62
|
+
if (orientationType === _OrientationType.OrientationType.interface) {
|
|
63
|
+
_module.default.lockTo(orientation);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (orientation === _Orientation.Orientation.landscapeLeft) {
|
|
67
|
+
_module.default.lockTo(_Orientation.Orientation.landscapeRight);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (orientation === _Orientation.Orientation.landscapeRight) {
|
|
71
|
+
_module.default.lockTo(_Orientation.Orientation.landscapeLeft);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
41
74
|
_module.default.lockTo(orientation);
|
|
42
75
|
}
|
|
43
76
|
static unlock() {
|
|
@@ -70,6 +103,25 @@ class RNOrientationDirector {
|
|
|
70
103
|
static convertAutoRotationToHumanReadableString(autoRotation) {
|
|
71
104
|
return RNOrientationDirector._humanReadableAutoRotationsResource[autoRotation];
|
|
72
105
|
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* This method checks if the given orientation is lockable
|
|
109
|
+
* by interface perspective.
|
|
110
|
+
*
|
|
111
|
+
* All orientations are lockable except for unknown, faceUp
|
|
112
|
+
* and faceDown.
|
|
113
|
+
*
|
|
114
|
+
* This method is useful when you want to lock the interface
|
|
115
|
+
* orientation from a given device orientation.
|
|
116
|
+
*
|
|
117
|
+
* Example: with listenForDeviceOrientationChanges
|
|
118
|
+
*
|
|
119
|
+
* @param orientation any orientation enum value
|
|
120
|
+
* @returns true if the orientation is lockable
|
|
121
|
+
*/
|
|
122
|
+
static isLockableOrientation(orientation) {
|
|
123
|
+
return !(orientation === _Orientation.Orientation.unknown || orientation === _Orientation.Orientation.faceUp || orientation === _Orientation.Orientation.faceDown);
|
|
124
|
+
}
|
|
73
125
|
}
|
|
74
126
|
var _default = exports.default = RNOrientationDirector;
|
|
75
127
|
//# 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;
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_module","_interopRequireDefault","_Orientation","_AutoRotation","_OrientationType","_EventEmitter","e","__esModule","default","RNOrientationDirector","_humanReadableOrientationsResource","Orientation","unknown","portrait","portraitUpsideDown","landscapeLeft","landscapeRight","landscape","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;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,SAAS,GAAG,WAAW;IACpC,CAACN,wBAAW,CAACO,MAAM,GAAG,SAAS;IAC/B,CAACP,wBAAW,CAACQ,QAAQ,GAAG;EAC1B,CAAC;EAEH,OAAeC,mCAAmC,GAChD;IACE,CAACC,0BAAY,CAACT,OAAO,GAAG,SAAS;IACjC,CAACS,0BAAY,CAACC,OAAO,GAAG,SAAS;IACjC,CAACD,0BAAY,CAACE,QAAQ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C7B;IACA,OAAOgB,eAAM,CAACS,qBAAqB,CAAC,CAAC,GACjChB,0BAAY,CAACC,OAAO,GACpBD,0BAAY,CAACE,QAAQ;EAC3B;EAEA,OAAOiB,mCAAmCA,CAAA,EAAG;IAC3CZ,eAAM,CAACY,mCAAmC,CAAC,CAAC;EAC9C;EAEA,OAAOC,iCAAiCA,CACtCC,QAAiD,EACjD;IACA,OAAOC,qBAAY,CAACC,qCAAqC,CAACF,QAAQ,CAAC;EACrE;EAEA,OAAOG,oCAAoCA,CACzCH,QAAiD,EACjD;IACA,OAAOC,qBAAY,CAACG,wCAAwC,CAACJ,QAAQ,CAAC;EACxE;EAEA,OAAOK,oBAAoBA,CAACL,QAAsC,EAAE;IAClE,OAAOC,qBAAY,CAACK,wBAAwB,CAACN,QAAQ,CAAC;EACxD;EAEA,OAAOO,uCAAuCA,CAAClB,WAAwB,EAAE;IACvE,OAAOtB,qBAAqB,CAACC,kCAAkC,CAC7DqB,WAAW,CACZ;EACH;EAEA,OAAOmB,wCAAwCA,CAACC,YAA0B,EAAE;IAC1E,OAAO1C,qBAAqB,CAACW,mCAAmC,CAC9D+B,YAAY,CACb;EACH;;EAEA;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACE,OAAOC,qBAAqBA,CAC1BrB,WAAwB,EACY;IACpC,OAAO,EACLA,WAAW,KAAKpB,wBAAW,CAACC,OAAO,IACnCmB,WAAW,KAAKpB,wBAAW,CAACO,MAAM,IAClCa,WAAW,KAAKpB,wBAAW,CAACQ,QAAQ,CACrC;EACH;AACF;AAAC,IAAAkC,QAAA,GAAAC,OAAA,CAAA9C,OAAA,GAEcC,qBAAqB","ignoreList":[]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -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":"
|
|
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":[]}
|
|
@@ -10,8 +10,9 @@ let Orientation = exports.Orientation = /*#__PURE__*/function (Orientation) {
|
|
|
10
10
|
Orientation[Orientation["landscapeRight"] = 2] = "landscapeRight";
|
|
11
11
|
Orientation[Orientation["portraitUpsideDown"] = 3] = "portraitUpsideDown";
|
|
12
12
|
Orientation[Orientation["landscapeLeft"] = 4] = "landscapeLeft";
|
|
13
|
-
Orientation[Orientation["
|
|
14
|
-
Orientation[Orientation["
|
|
13
|
+
Orientation[Orientation["landscape"] = 5] = "landscape";
|
|
14
|
+
Orientation[Orientation["faceUp"] = 6] = "faceUp";
|
|
15
|
+
Orientation[Orientation["faceDown"] = 7] = "faceDown";
|
|
15
16
|
return Orientation;
|
|
16
17
|
}({});
|
|
17
18
|
//# sourceMappingURL=Orientation.enum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Orientation","exports"],"sourceRoot":"../../../src","sources":["types/Orientation.enum.ts"],"mappings":";;;;;;IAAYA,WAAW,GAAAC,OAAA,CAAAD,WAAA,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["Orientation","exports"],"sourceRoot":"../../../src","sources":["types/Orientation.enum.ts"],"mappings":";;;;;;IAAYA,WAAW,GAAAC,OAAA,CAAAD,WAAA,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA","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 = {
|
|
@@ -10,6 +11,7 @@ class RNOrientationDirector {
|
|
|
10
11
|
[Orientation.portraitUpsideDown]: 'Portrait Upside Down',
|
|
11
12
|
[Orientation.landscapeLeft]: 'Landscape Left',
|
|
12
13
|
[Orientation.landscapeRight]: 'Landscape Right',
|
|
14
|
+
[Orientation.landscape]: 'Landscape',
|
|
13
15
|
[Orientation.faceUp]: 'Face Up',
|
|
14
16
|
[Orientation.faceDown]: 'Face Down'
|
|
15
17
|
};
|
|
@@ -30,7 +32,38 @@ class RNOrientationDirector {
|
|
|
30
32
|
static getDeviceOrientation() {
|
|
31
33
|
return Module.getDeviceOrientation();
|
|
32
34
|
}
|
|
33
|
-
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Please be aware that device orientation is not the
|
|
38
|
+
* same as interface orientation.
|
|
39
|
+
*
|
|
40
|
+
* Specifically, landscape left and right are inverted:
|
|
41
|
+
*
|
|
42
|
+
* - landscapeLeft in device orientation is landscapeRight in interface orientation
|
|
43
|
+
* - landscapeRight in device orientation is landscapeLeft in interface orientation
|
|
44
|
+
*
|
|
45
|
+
* This is a behavior of the native API.
|
|
46
|
+
*
|
|
47
|
+
* When you pass an orientation value, do provide orientationType
|
|
48
|
+
* as well if the orientation value is not an interface orientation.
|
|
49
|
+
* Example: when using listenForDeviceOrientationChanges.
|
|
50
|
+
*
|
|
51
|
+
* @param orientation any lockable orientation enum value
|
|
52
|
+
* @param orientationType any orientation type enum value
|
|
53
|
+
*/
|
|
54
|
+
static lockTo(orientation, orientationType = OrientationType.interface) {
|
|
55
|
+
if (orientationType === OrientationType.interface) {
|
|
56
|
+
Module.lockTo(orientation);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (orientation === Orientation.landscapeLeft) {
|
|
60
|
+
Module.lockTo(Orientation.landscapeRight);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (orientation === Orientation.landscapeRight) {
|
|
64
|
+
Module.lockTo(Orientation.landscapeLeft);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
34
67
|
Module.lockTo(orientation);
|
|
35
68
|
}
|
|
36
69
|
static unlock() {
|
|
@@ -63,6 +96,25 @@ class RNOrientationDirector {
|
|
|
63
96
|
static convertAutoRotationToHumanReadableString(autoRotation) {
|
|
64
97
|
return RNOrientationDirector._humanReadableAutoRotationsResource[autoRotation];
|
|
65
98
|
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* This method checks if the given orientation is lockable
|
|
102
|
+
* by interface perspective.
|
|
103
|
+
*
|
|
104
|
+
* All orientations are lockable except for unknown, faceUp
|
|
105
|
+
* and faceDown.
|
|
106
|
+
*
|
|
107
|
+
* This method is useful when you want to lock the interface
|
|
108
|
+
* orientation from a given device orientation.
|
|
109
|
+
*
|
|
110
|
+
* Example: with listenForDeviceOrientationChanges
|
|
111
|
+
*
|
|
112
|
+
* @param orientation any orientation enum value
|
|
113
|
+
* @returns true if the orientation is lockable
|
|
114
|
+
*/
|
|
115
|
+
static isLockableOrientation(orientation) {
|
|
116
|
+
return !(orientation === Orientation.unknown || orientation === Orientation.faceUp || orientation === Orientation.faceDown);
|
|
117
|
+
}
|
|
66
118
|
}
|
|
67
119
|
export default RNOrientationDirector;
|
|
68
120
|
//# 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;
|
|
1
|
+
{"version":3,"names":["Platform","Module","Orientation","AutoRotation","OrientationType","EventEmitter","RNOrientationDirector","_humanReadableOrientationsResource","unknown","portrait","portraitUpsideDown","landscapeLeft","landscapeRight","landscape","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,SAASA,QAAQ,QAAQ,cAAc;AACvC,OAAOC,MAAM,MAAM,UAAU;AAE7B,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,YAAY,QAAQ,2BAA2B;AACxD,SAASC,eAAe,QAAQ,8BAA8B;AAK9D,OAAOC,YAAY,MAAM,gBAAgB;AAEzC,MAAMC,qBAAqB,CAAC;EAC1B,OAAeC,kCAAkC,GAC/C;IACE,CAACL,WAAW,CAACM,OAAO,GAAG,SAAS;IAChC,CAACN,WAAW,CAACO,QAAQ,GAAG,UAAU;IAClC,CAACP,WAAW,CAACQ,kBAAkB,GAAG,sBAAsB;IACxD,CAACR,WAAW,CAACS,aAAa,GAAG,gBAAgB;IAC7C,CAACT,WAAW,CAACU,cAAc,GAAG,iBAAiB;IAC/C,CAACV,WAAW,CAACW,SAAS,GAAG,WAAW;IACpC,CAACX,WAAW,CAACY,MAAM,GAAG,SAA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
package/lib/module/index.js
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
|
import useDeviceOrientation from './hooks/useDeviceOrientation.hook';
|
|
4
5
|
export { useDeviceOrientation };
|
|
5
6
|
import useInterfaceOrientation from './hooks/useInterfaceOrientation.hook';
|
package/lib/module/index.js.map
CHANGED
|
@@ -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;
|
|
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":[]}
|
|
@@ -4,8 +4,9 @@ export let Orientation = /*#__PURE__*/function (Orientation) {
|
|
|
4
4
|
Orientation[Orientation["landscapeRight"] = 2] = "landscapeRight";
|
|
5
5
|
Orientation[Orientation["portraitUpsideDown"] = 3] = "portraitUpsideDown";
|
|
6
6
|
Orientation[Orientation["landscapeLeft"] = 4] = "landscapeLeft";
|
|
7
|
-
Orientation[Orientation["
|
|
8
|
-
Orientation[Orientation["
|
|
7
|
+
Orientation[Orientation["landscape"] = 5] = "landscape";
|
|
8
|
+
Orientation[Orientation["faceUp"] = 6] = "faceUp";
|
|
9
|
+
Orientation[Orientation["faceDown"] = 7] = "faceDown";
|
|
9
10
|
return Orientation;
|
|
10
11
|
}({});
|
|
11
12
|
//# sourceMappingURL=Orientation.enum.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Orientation"],"sourceRoot":"../../../src","sources":["types/Orientation.enum.ts"],"mappings":"AAAA,WAAYA,WAAW,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["Orientation"],"sourceRoot":"../../../src","sources":["types/Orientation.enum.ts"],"mappings":"AAAA,WAAYA,WAAW,0BAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAXA,WAAW,CAAXA,WAAW;EAAA,OAAXA,WAAW;AAAA","ignoreList":[]}
|
|
@@ -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
|
-
|
|
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,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,iDAAiD,CAAC;AAG1G,cAAM,qBAAqB;IACzB,OAAO,CAAC,MAAM,CAAC,kCAAkC,
|
|
1
|
+
{"version":3,"file":"RNOrientationDirector.d.ts","sourceRoot":"","sources":["../../../src/RNOrientationDirector.ts"],"names":[],"mappings":"AAE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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;
|
|
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"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Orientation } from './Orientation.enum';
|
|
2
|
-
export type LockableOrientation = Orientation.portrait | Orientation.portraitUpsideDown | Orientation.landscapeLeft | Orientation.landscapeRight;
|
|
2
|
+
export type LockableOrientation = Orientation.portrait | Orientation.portraitUpsideDown | Orientation.landscapeLeft | Orientation.landscapeRight | Orientation.landscape;
|
|
3
3
|
//# sourceMappingURL=LockableOrientation.type.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LockableOrientation.type.d.ts","sourceRoot":"","sources":["../../../../src/types/LockableOrientation.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,mBAAmB,GAC3B,WAAW,CAAC,QAAQ,GACpB,WAAW,CAAC,kBAAkB,GAC9B,WAAW,CAAC,aAAa,GACzB,WAAW,CAAC,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"LockableOrientation.type.d.ts","sourceRoot":"","sources":["../../../../src/types/LockableOrientation.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,MAAM,mBAAmB,GAC3B,WAAW,CAAC,QAAQ,GACpB,WAAW,CAAC,kBAAkB,GAC9B,WAAW,CAAC,aAAa,GACzB,WAAW,CAAC,cAAc,GAC1B,WAAW,CAAC,SAAS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Orientation.enum.d.ts","sourceRoot":"","sources":["../../../../src/types/Orientation.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,OAAO,IAAI;IACX,QAAQ,IAAI;IACZ,cAAc,IAAI;IAClB,kBAAkB,IAAI;IACtB,aAAa,IAAI;IACjB,MAAM,IAAI;IACV,QAAQ,IAAI;CACb"}
|
|
1
|
+
{"version":3,"file":"Orientation.enum.d.ts","sourceRoot":"","sources":["../../../../src/types/Orientation.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACrB,OAAO,IAAI;IACX,QAAQ,IAAI;IACZ,cAAc,IAAI;IAClB,kBAAkB,IAAI;IACtB,aAAa,IAAI;IACjB,SAAS,IAAI;IACb,MAAM,IAAI;IACV,QAAQ,IAAI;CACb"}
|
|
@@ -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
|
@@ -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';
|
|
@@ -17,6 +18,7 @@ class RNOrientationDirector {
|
|
|
17
18
|
[Orientation.portraitUpsideDown]: 'Portrait Upside Down',
|
|
18
19
|
[Orientation.landscapeLeft]: 'Landscape Left',
|
|
19
20
|
[Orientation.landscapeRight]: 'Landscape Right',
|
|
21
|
+
[Orientation.landscape]: 'Landscape',
|
|
20
22
|
[Orientation.faceUp]: 'Face Up',
|
|
21
23
|
[Orientation.faceDown]: 'Face Down',
|
|
22
24
|
};
|
|
@@ -44,7 +46,43 @@ class RNOrientationDirector {
|
|
|
44
46
|
return Module.getDeviceOrientation();
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Please be aware that device orientation is not the
|
|
51
|
+
* same as interface orientation.
|
|
52
|
+
*
|
|
53
|
+
* Specifically, landscape left and right are inverted:
|
|
54
|
+
*
|
|
55
|
+
* - landscapeLeft in device orientation is landscapeRight in interface orientation
|
|
56
|
+
* - landscapeRight in device orientation is landscapeLeft in interface orientation
|
|
57
|
+
*
|
|
58
|
+
* This is a behavior of the native API.
|
|
59
|
+
*
|
|
60
|
+
* When you pass an orientation value, do provide orientationType
|
|
61
|
+
* as well if the orientation value is not an interface orientation.
|
|
62
|
+
* Example: when using listenForDeviceOrientationChanges.
|
|
63
|
+
*
|
|
64
|
+
* @param orientation any lockable orientation enum value
|
|
65
|
+
* @param orientationType any orientation type enum value
|
|
66
|
+
*/
|
|
67
|
+
static lockTo(
|
|
68
|
+
orientation: LockableOrientation,
|
|
69
|
+
orientationType: OrientationType = OrientationType.interface
|
|
70
|
+
) {
|
|
71
|
+
if (orientationType === OrientationType.interface) {
|
|
72
|
+
Module.lockTo(orientation);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (orientation === Orientation.landscapeLeft) {
|
|
77
|
+
Module.lockTo(Orientation.landscapeRight);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (orientation === Orientation.landscapeRight) {
|
|
82
|
+
Module.lockTo(Orientation.landscapeLeft);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
48
86
|
Module.lockTo(orientation);
|
|
49
87
|
}
|
|
50
88
|
|
|
@@ -96,6 +134,31 @@ class RNOrientationDirector {
|
|
|
96
134
|
autoRotation
|
|
97
135
|
];
|
|
98
136
|
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* This method checks if the given orientation is lockable
|
|
140
|
+
* by interface perspective.
|
|
141
|
+
*
|
|
142
|
+
* All orientations are lockable except for unknown, faceUp
|
|
143
|
+
* and faceDown.
|
|
144
|
+
*
|
|
145
|
+
* This method is useful when you want to lock the interface
|
|
146
|
+
* orientation from a given device orientation.
|
|
147
|
+
*
|
|
148
|
+
* Example: with listenForDeviceOrientationChanges
|
|
149
|
+
*
|
|
150
|
+
* @param orientation any orientation enum value
|
|
151
|
+
* @returns true if the orientation is lockable
|
|
152
|
+
*/
|
|
153
|
+
static isLockableOrientation(
|
|
154
|
+
orientation: Orientation
|
|
155
|
+
): orientation is LockableOrientation {
|
|
156
|
+
return !(
|
|
157
|
+
orientation === Orientation.unknown ||
|
|
158
|
+
orientation === Orientation.faceUp ||
|
|
159
|
+
orientation === Orientation.faceDown
|
|
160
|
+
);
|
|
161
|
+
}
|
|
99
162
|
}
|
|
100
163
|
|
|
101
164
|
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 };
|