react-native-orientation-director 2.5.0 → 2.5.1
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.
|
@@ -19,6 +19,13 @@ import UIKit
|
|
|
19
19
|
private var lastInterfaceOrientation = Orientation.UNKNOWN
|
|
20
20
|
private var lastDeviceOrientation = Orientation.UNKNOWN
|
|
21
21
|
private var isLocked = false
|
|
22
|
+
|
|
23
|
+
/// # Only on iOS < 16
|
|
24
|
+
/// This variable is needed to prevent a loop where
|
|
25
|
+
/// we lock the interface to a specific orientation
|
|
26
|
+
/// and the sensor picks it up, therefore triggering
|
|
27
|
+
/// the orientation did change event.
|
|
28
|
+
private var isLocking = false
|
|
22
29
|
|
|
23
30
|
@objc public var supportedInterfaceOrientations: UIInterfaceOrientationMask = UIInterfaceOrientationMask.all
|
|
24
31
|
|
|
@@ -56,6 +63,7 @@ import UIKit
|
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
@objc public func lockTo(jsValue: NSNumber) {
|
|
66
|
+
self.isLocking = true;
|
|
59
67
|
let jsOrientation = utils.convertToOrientationFrom(jsValue: jsValue)
|
|
60
68
|
let mask = utils.convertToMaskFrom(jsOrientation: jsOrientation)
|
|
61
69
|
self.requestInterfaceUpdateTo(mask: mask)
|
|
@@ -65,17 +73,20 @@ import UIKit
|
|
|
65
73
|
let orientationCanBeUpdatedDirectly = jsOrientation != Orientation.LANDSCAPE
|
|
66
74
|
if orientationCanBeUpdatedDirectly {
|
|
67
75
|
updateLastInterfaceOrientationTo(value: jsOrientation)
|
|
76
|
+
self.isLocking = false;
|
|
68
77
|
return
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
let lastInterfaceOrientationIsAlreadyInLandscape = lastInterfaceOrientation == Orientation.LANDSCAPE_RIGHT || lastInterfaceOrientation == Orientation.LANDSCAPE_LEFT
|
|
72
81
|
if lastInterfaceOrientationIsAlreadyInLandscape {
|
|
73
82
|
updateLastInterfaceOrientationTo(value: lastInterfaceOrientation)
|
|
83
|
+
self.isLocking = false;
|
|
74
84
|
return
|
|
75
85
|
}
|
|
76
86
|
|
|
77
87
|
let systemDefaultLandscapeOrientation = Orientation.LANDSCAPE_RIGHT
|
|
78
88
|
updateLastInterfaceOrientationTo(value: systemDefaultLandscapeOrientation)
|
|
89
|
+
self.isLocking = false;
|
|
79
90
|
}
|
|
80
91
|
|
|
81
92
|
@objc public func unlock() {
|
|
@@ -155,14 +166,19 @@ import UIKit
|
|
|
155
166
|
print("\(OrientationDirectorImpl.TAG) - requestGeometryUpdate error", error)
|
|
156
167
|
}
|
|
157
168
|
} else {
|
|
158
|
-
|
|
169
|
+
let interfaceOrientation = self.utils.convertToInterfaceOrientationFrom(mask: mask)
|
|
170
|
+
UIDevice.current.setValue(interfaceOrientation.rawValue, forKey: "orientation")
|
|
159
171
|
UIViewController.attemptRotationToDeviceOrientation()
|
|
160
172
|
}
|
|
161
173
|
}
|
|
162
174
|
|
|
163
175
|
private func onOrientationChanged(uiDeviceOrientation: UIDeviceOrientation) {
|
|
164
176
|
let deviceOrientation = utils.convertToOrientationFrom(deviceOrientation: uiDeviceOrientation)
|
|
165
|
-
|
|
177
|
+
|
|
178
|
+
if (!self.isLocking) {
|
|
179
|
+
self.eventManager.sendDeviceOrientationDidChange(orientationValue: deviceOrientation.rawValue)
|
|
180
|
+
}
|
|
181
|
+
|
|
166
182
|
lastDeviceOrientation = deviceOrientation
|
|
167
183
|
adaptInterfaceTo(deviceOrientation: deviceOrientation)
|
|
168
184
|
}
|
|
@@ -78,6 +78,21 @@ class Utils {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
public func convertToInterfaceOrientationFrom(mask: UIInterfaceOrientationMask) -> UIInterfaceOrientation {
|
|
82
|
+
switch mask {
|
|
83
|
+
case .portrait:
|
|
84
|
+
return .portrait
|
|
85
|
+
case .landscapeRight:
|
|
86
|
+
return .landscapeRight
|
|
87
|
+
case .portraitUpsideDown:
|
|
88
|
+
return .portraitUpsideDown
|
|
89
|
+
case .landscapeLeft:
|
|
90
|
+
return .landscapeLeft
|
|
91
|
+
default:
|
|
92
|
+
return .unknown
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
81
96
|
public func getInterfaceOrientation() -> UIInterfaceOrientation {
|
|
82
97
|
guard let windowScene = self.getCurrentWindow()?.windowScene else {
|
|
83
98
|
return UIInterfaceOrientation.unknown
|
package/package.json
CHANGED