react-native-orientation-director 1.2.0 → 1.2.2
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/android/src/main/java/com/orientationdirector/implementation/OrientationDirectorImpl.kt +10 -8
- package/android/src/main/java/com/orientationdirector/implementation/OrientationDirectorUtilsImpl.kt +10 -0
- package/ios/OrientationDirector.mm +2 -2
- package/ios/implementation/OrientationDirectorImpl.swift +22 -24
- package/ios/implementation/OrientationDirectorUtils.swift +36 -19
- package/package.json +1 -1
package/android/src/main/java/com/orientationdirector/implementation/OrientationDirectorImpl.kt
CHANGED
|
@@ -79,20 +79,21 @@ class OrientationDirectorImpl internal constructor(private val context: ReactApp
|
|
|
79
79
|
return mAutoRotationObserver.getLastAutoRotationStatus()
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
fun lockTo(
|
|
83
|
-
val
|
|
82
|
+
fun lockTo(rawJsOrientation: Int) {
|
|
83
|
+
val jsOrientation = mUtils.getOrientationFromJsOrientation(rawJsOrientation)
|
|
84
84
|
val screenOrientation =
|
|
85
|
-
mUtils.getActivityOrientationFrom(
|
|
85
|
+
mUtils.getActivityOrientationFrom(jsOrientation)
|
|
86
86
|
context.currentActivity?.requestedOrientation = screenOrientation
|
|
87
|
-
|
|
88
|
-
lastInterfaceOrientation = interfaceOrientation
|
|
87
|
+
|
|
89
88
|
updateIsLockedTo(true)
|
|
89
|
+
updateLastInterfaceOrientationTo(jsOrientation)
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
fun unlock() {
|
|
93
93
|
context.currentActivity?.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
|
94
|
+
|
|
94
95
|
updateIsLockedTo(false)
|
|
95
|
-
adaptInterfaceTo(
|
|
96
|
+
adaptInterfaceTo(lastDeviceOrientation)
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
fun resetSupportedInterfaceOrientations() {
|
|
@@ -140,11 +141,12 @@ class OrientationDirectorImpl internal constructor(private val context: ReactApp
|
|
|
140
141
|
return
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
|
|
144
|
+
val newInterfaceOrientation = mUtils.getInterfaceOrientationFromDeviceOrientation(deviceOrientation);
|
|
145
|
+
if (newInterfaceOrientation == lastInterfaceOrientation) {
|
|
144
146
|
return
|
|
145
147
|
}
|
|
146
148
|
|
|
147
|
-
updateLastInterfaceOrientationTo(
|
|
149
|
+
updateLastInterfaceOrientationTo(newInterfaceOrientation)
|
|
148
150
|
}
|
|
149
151
|
|
|
150
152
|
private fun updateIsLockedTo(value: Boolean) {
|
package/android/src/main/java/com/orientationdirector/implementation/OrientationDirectorUtilsImpl.kt
CHANGED
|
@@ -64,4 +64,14 @@ class OrientationDirectorUtilsImpl(val context: ReactContext) {
|
|
|
64
64
|
else -> Orientation.PORTRAIT
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
|
+
|
|
68
|
+
fun getInterfaceOrientationFromDeviceOrientation(deviceOrientation: Orientation): Orientation {
|
|
69
|
+
return when(deviceOrientation) {
|
|
70
|
+
Orientation.PORTRAIT -> Orientation.PORTRAIT
|
|
71
|
+
Orientation.LANDSCAPE_RIGHT -> Orientation.LANDSCAPE_LEFT
|
|
72
|
+
Orientation.PORTRAIT_UPSIDE_DOWN -> Orientation.PORTRAIT_UPSIDE_DOWN
|
|
73
|
+
Orientation.LANDSCAPE_LEFT -> Orientation.LANDSCAPE_RIGHT
|
|
74
|
+
else -> Orientation.UNKNOWN
|
|
75
|
+
}
|
|
76
|
+
}
|
|
67
77
|
}
|
|
@@ -99,7 +99,7 @@ RCT_EXPORT_METHOD(lockTo:(double)jsOrientation)
|
|
|
99
99
|
{
|
|
100
100
|
NSNumber *jsOrientationNumber = @(jsOrientation);
|
|
101
101
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
102
|
-
[_director
|
|
102
|
+
[_director lockToRawJsOrientation:jsOrientationNumber];
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
|
|
@@ -126,7 +126,7 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(isLocked)
|
|
|
126
126
|
#ifdef RCT_NEW_ARCH_ENABLED
|
|
127
127
|
- (void)resetSupportedInterfaceOrientations
|
|
128
128
|
#else
|
|
129
|
-
|
|
129
|
+
RCT_EXPORT_METHOD(resetSupportedInterfaceOrientations)
|
|
130
130
|
#endif
|
|
131
131
|
{
|
|
132
132
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
@@ -48,23 +48,20 @@ import UIKit
|
|
|
48
48
|
return lastDeviceOrientation
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
@objc public func lockTo(
|
|
52
|
-
let
|
|
53
|
-
let mask = OrientationDirectorUtils.getMaskFrom(
|
|
54
|
-
|
|
51
|
+
@objc public func lockTo(rawJsOrientation: NSNumber) {
|
|
52
|
+
let jsOrientation = OrientationDirectorUtils.getOrientationFrom(jsOrientation: rawJsOrientation)
|
|
53
|
+
let mask = OrientationDirectorUtils.getMaskFrom(jsOrientation: jsOrientation)
|
|
55
54
|
self.requestInterfaceUpdateTo(mask: mask)
|
|
56
55
|
|
|
57
|
-
eventManager.sendInterfaceOrientationDidChange(orientationValue: orientation.rawValue)
|
|
58
|
-
lastInterfaceOrientation = orientation
|
|
59
56
|
updateIsLockedTo(value: true)
|
|
57
|
+
updateLastInterfaceOrientationTo(value: jsOrientation)
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
@objc public func unlock() {
|
|
63
61
|
self.requestInterfaceUpdateTo(mask: UIInterfaceOrientationMask.all)
|
|
64
62
|
|
|
65
|
-
let deviceOrientation = OrientationDirectorUtils.getOrientationFrom(deviceOrientation: UIDevice.current.orientation)
|
|
66
63
|
updateIsLockedTo(value: false)
|
|
67
|
-
self.adaptInterfaceTo(deviceOrientation:
|
|
64
|
+
self.adaptInterfaceTo(deviceOrientation: lastDeviceOrientation)
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
@objc public func resetSupportedInterfaceOrientations() {
|
|
@@ -72,27 +69,27 @@ import UIKit
|
|
|
72
69
|
self.requestInterfaceUpdateTo(mask: self.supportedInterfaceOrientations)
|
|
73
70
|
self.updateIsLockedTo(value: self.initIsLocked())
|
|
74
71
|
|
|
75
|
-
let lastMask = OrientationDirectorUtils.getMaskFrom(
|
|
76
|
-
let
|
|
77
|
-
if (
|
|
72
|
+
let lastMask = OrientationDirectorUtils.getMaskFrom(jsOrientation: lastInterfaceOrientation)
|
|
73
|
+
let isLastMaskSupported = self.supportedInterfaceOrientations.contains(lastMask)
|
|
74
|
+
if (isLastMaskSupported) {
|
|
78
75
|
return
|
|
79
76
|
}
|
|
80
77
|
|
|
81
78
|
let supportedInterfaceOrientations = OrientationDirectorUtils.readSupportedInterfaceOrientationsFromBundle()
|
|
82
79
|
if (supportedInterfaceOrientations.contains(UIInterfaceOrientationMask.portrait)) {
|
|
83
|
-
self.
|
|
80
|
+
self.updateLastInterfaceOrientationTo(value: Orientation.PORTRAIT)
|
|
84
81
|
return
|
|
85
82
|
}
|
|
86
83
|
if (supportedInterfaceOrientations.contains(UIInterfaceOrientationMask.landscapeRight)) {
|
|
87
|
-
self.
|
|
84
|
+
self.updateLastInterfaceOrientationTo(value: Orientation.LANDSCAPE_RIGHT)
|
|
88
85
|
return
|
|
89
86
|
}
|
|
90
87
|
if (supportedInterfaceOrientations.contains(UIInterfaceOrientationMask.landscapeLeft)) {
|
|
91
|
-
self.
|
|
88
|
+
self.updateLastInterfaceOrientationTo(value: Orientation.LANDSCAPE_LEFT)
|
|
92
89
|
return
|
|
93
90
|
}
|
|
94
91
|
|
|
95
|
-
self.
|
|
92
|
+
self.updateLastInterfaceOrientationTo(value: Orientation.PORTRAIT_UPSIDE_DOWN)
|
|
96
93
|
}
|
|
97
94
|
|
|
98
95
|
private func initInitialSupportedInterfaceOrientations() -> UIInterfaceOrientationMask {
|
|
@@ -154,22 +151,23 @@ import UIKit
|
|
|
154
151
|
if (isLocked) {
|
|
155
152
|
return
|
|
156
153
|
}
|
|
157
|
-
|
|
158
|
-
if (lastInterfaceOrientation == deviceOrientation) {
|
|
159
|
-
return
|
|
160
|
-
}
|
|
161
154
|
|
|
162
155
|
if (deviceOrientation == Orientation.FACE_UP || deviceOrientation == Orientation.FACE_DOWN) {
|
|
163
156
|
return
|
|
164
157
|
}
|
|
165
158
|
|
|
166
|
-
let
|
|
167
|
-
let
|
|
168
|
-
if (!
|
|
159
|
+
let newInterfaceOrientationMask = OrientationDirectorUtils.getMaskFrom(deviceOrientation: deviceOrientation)
|
|
160
|
+
let isSupported = self.supportedInterfaceOrientations.contains(newInterfaceOrientationMask)
|
|
161
|
+
if (!isSupported) {
|
|
169
162
|
return
|
|
170
163
|
}
|
|
171
164
|
|
|
172
|
-
|
|
165
|
+
let newInterfaceOrientation = OrientationDirectorUtils.getOrientationFrom(mask: newInterfaceOrientationMask)
|
|
166
|
+
if (newInterfaceOrientation == lastInterfaceOrientation) {
|
|
167
|
+
return
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
updateLastInterfaceOrientationTo(value: newInterfaceOrientation)
|
|
173
171
|
}
|
|
174
172
|
|
|
175
173
|
private func updateIsLockedTo(value: Bool) {
|
|
@@ -177,7 +175,7 @@ import UIKit
|
|
|
177
175
|
isLocked = value
|
|
178
176
|
}
|
|
179
177
|
|
|
180
|
-
private func
|
|
178
|
+
private func updateLastInterfaceOrientationTo(value: Orientation) {
|
|
181
179
|
self.eventManager.sendInterfaceOrientationDidChange(orientationValue: value.rawValue)
|
|
182
180
|
lastInterfaceOrientation = value
|
|
183
181
|
}
|
|
@@ -15,12 +15,12 @@ class OrientationDirectorUtils {
|
|
|
15
15
|
var orientation = Orientation.UNKNOWN
|
|
16
16
|
|
|
17
17
|
switch(uiInterfaceOrientation) {
|
|
18
|
-
case UIInterfaceOrientation.landscapeRight:
|
|
19
|
-
orientation = Orientation.
|
|
18
|
+
case UIInterfaceOrientation.landscapeRight:
|
|
19
|
+
orientation = Orientation.LANDSCAPE_RIGHT
|
|
20
20
|
case UIInterfaceOrientation.portraitUpsideDown:
|
|
21
21
|
orientation = Orientation.PORTRAIT_UPSIDE_DOWN
|
|
22
|
-
case UIInterfaceOrientation.landscapeLeft:
|
|
23
|
-
orientation = Orientation.
|
|
22
|
+
case UIInterfaceOrientation.landscapeLeft:
|
|
23
|
+
orientation = Orientation.LANDSCAPE_LEFT
|
|
24
24
|
default:
|
|
25
25
|
orientation = Orientation.PORTRAIT
|
|
26
26
|
}
|
|
@@ -73,9 +73,9 @@ class OrientationDirectorUtils {
|
|
|
73
73
|
case UIInterfaceOrientationMask.portraitUpsideDown:
|
|
74
74
|
orientation = Orientation.PORTRAIT_UPSIDE_DOWN
|
|
75
75
|
case UIInterfaceOrientationMask.landscapeRight:
|
|
76
|
-
orientation = Orientation.LANDSCAPE_LEFT
|
|
77
|
-
case UIInterfaceOrientationMask.landscapeLeft:
|
|
78
76
|
orientation = Orientation.LANDSCAPE_RIGHT
|
|
77
|
+
case UIInterfaceOrientationMask.landscapeLeft:
|
|
78
|
+
orientation = Orientation.LANDSCAPE_LEFT
|
|
79
79
|
default:
|
|
80
80
|
orientation = Orientation.PORTRAIT
|
|
81
81
|
}
|
|
@@ -83,25 +83,42 @@ class OrientationDirectorUtils {
|
|
|
83
83
|
return orientation
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
/**
|
|
87
|
+
Note: .portraitUpsideDown only works for devices with home button and iPads
|
|
88
|
+
https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations
|
|
89
89
|
*/
|
|
90
|
-
public static func getMaskFrom(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
public static func getMaskFrom(jsOrientation: Orientation) -> UIInterfaceOrientationMask {
|
|
91
|
+
switch(jsOrientation) {
|
|
92
|
+
case Orientation.PORTRAIT:
|
|
93
|
+
return UIInterfaceOrientationMask.portrait
|
|
94
94
|
case Orientation.LANDSCAPE_RIGHT:
|
|
95
|
-
|
|
95
|
+
return UIInterfaceOrientationMask.landscapeRight
|
|
96
96
|
case Orientation.PORTRAIT_UPSIDE_DOWN:
|
|
97
|
-
|
|
97
|
+
return UIInterfaceOrientationMask.portraitUpsideDown
|
|
98
98
|
case Orientation.LANDSCAPE_LEFT:
|
|
99
|
-
|
|
99
|
+
return UIInterfaceOrientationMask.landscapeLeft
|
|
100
100
|
default:
|
|
101
|
-
|
|
101
|
+
return UIInterfaceOrientationMask.all
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
Note: .portraitUpsideDown only works for devices with home button and iPads
|
|
107
|
+
https://developer.apple.com/documentation/uikit/uiviewcontroller/1621435-supportedinterfaceorientations
|
|
108
|
+
*/
|
|
109
|
+
public static func getMaskFrom(deviceOrientation: Orientation) -> UIInterfaceOrientationMask {
|
|
110
|
+
switch(deviceOrientation) {
|
|
111
|
+
case Orientation.PORTRAIT:
|
|
112
|
+
return UIInterfaceOrientationMask.portrait
|
|
113
|
+
case Orientation.LANDSCAPE_RIGHT:
|
|
114
|
+
return UIInterfaceOrientationMask.landscapeLeft
|
|
115
|
+
case Orientation.PORTRAIT_UPSIDE_DOWN:
|
|
116
|
+
return UIInterfaceOrientationMask.portraitUpsideDown
|
|
117
|
+
case Orientation.LANDSCAPE_LEFT:
|
|
118
|
+
return UIInterfaceOrientationMask.landscapeRight
|
|
119
|
+
default:
|
|
120
|
+
return UIInterfaceOrientationMask.all
|
|
102
121
|
}
|
|
103
|
-
|
|
104
|
-
return mask
|
|
105
122
|
}
|
|
106
123
|
|
|
107
124
|
public static func getInterfaceOrientation() -> UIInterfaceOrientation {
|
package/package.json
CHANGED