expo-screen-orientation 6.0.0 → 6.0.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/CHANGELOG.md +12 -0
- package/android/build.gradle +2 -2
- package/ios/ScreenOrientationAppDelegate.swift +1 -0
- package/ios/ScreenOrientationModule.swift +8 -23
- package/ios/ScreenOrientationReactDelegateHandler.swift +1 -0
- package/ios/ScreenOrientationRegistry.swift +30 -26
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,18 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 6.0.2 — 2023-07-04
|
|
14
|
+
|
|
15
|
+
### 💡 Others
|
|
16
|
+
|
|
17
|
+
- [iOS] Refactor the singleton class to work properly in versioned code in Expo Go. ([#23228](https://github.com/expo/expo/pull/23228) by [@tsapeta](https://github.com/tsapeta))
|
|
18
|
+
|
|
19
|
+
## 6.0.1 — 2023-06-23
|
|
20
|
+
|
|
21
|
+
### 🐛 Bug fixes
|
|
22
|
+
|
|
23
|
+
- [iOS] Fix crash when reading `rootViewController` value. ([#23039](https://github.com/expo/expo/pull/23039) by [@gabrieldonadel](https://github.com/gabrieldonadel))
|
|
24
|
+
|
|
13
25
|
## 6.0.0 — 2023-06-21
|
|
14
26
|
|
|
15
27
|
_This version does not introduce any user-facing changes._
|
package/android/build.gradle
CHANGED
|
@@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
|
|
|
3
3
|
apply plugin: 'maven-publish'
|
|
4
4
|
|
|
5
5
|
group = 'host.exp.exponent'
|
|
6
|
-
version = '6.0.
|
|
6
|
+
version = '6.0.2'
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
9
9
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
@@ -67,7 +67,7 @@ android {
|
|
|
67
67
|
minSdkVersion safeExtGet("minSdkVersion", 21)
|
|
68
68
|
targetSdkVersion safeExtGet("targetSdkVersion", 33)
|
|
69
69
|
versionCode 7
|
|
70
|
-
versionName '6.0.
|
|
70
|
+
versionName '6.0.2'
|
|
71
71
|
}
|
|
72
72
|
lintOptions {
|
|
73
73
|
abortOnError false
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import ExpoModulesCore
|
|
4
4
|
|
|
5
|
+
@objc(EXScreenOrientationAppDelegate)
|
|
5
6
|
public class ScreenOrientationAppDelegate: ExpoAppDelegateSubscriber {
|
|
6
7
|
public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
|
7
8
|
ScreenOrientationRegistry.shared.updateCurrentScreenOrientation()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import ExpoModulesCore
|
|
2
2
|
|
|
3
|
-
public class ScreenOrientationModule: Module,
|
|
3
|
+
public class ScreenOrientationModule: Module, ScreenOrientationController {
|
|
4
4
|
static let didUpdateDimensionsEvent = "expoDidUpdateDimensions"
|
|
5
5
|
|
|
6
6
|
let screenOrientationRegistry = ScreenOrientationRegistry.shared
|
|
@@ -22,7 +22,7 @@ public class ScreenOrientationModule: Module, OrientationListener, Hashable {
|
|
|
22
22
|
throw UnsupportedOrientationLockException(orientationLock)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
screenOrientationRegistry.setMask(orientationMask,
|
|
25
|
+
screenOrientationRegistry.setMask(orientationMask, forController: self)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
AsyncFunction("lockPlatformAsync") { (allowedOrientations: [ModuleOrientation]) in
|
|
@@ -43,7 +43,7 @@ public class ScreenOrientationModule: Module, OrientationListener, Hashable {
|
|
|
43
43
|
throw UnsupportedOrientationLockException(nil)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
screenOrientationRegistry.setMask(allowedOrientationsMask,
|
|
46
|
+
screenOrientationRegistry.setMask(allowedOrientationsMask, forController: self)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
AsyncFunction("getOrientationLockAsync") {
|
|
@@ -75,23 +75,18 @@ public class ScreenOrientationModule: Module, OrientationListener, Hashable {
|
|
|
75
75
|
return ModuleOrientation.from(orientation: screenOrientationRegistry.currentScreenOrientation).rawValue
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
79
|
-
screenOrientationRegistry.
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
OnStopObserving {
|
|
83
|
-
screenOrientationRegistry.unregisterModuleFromReceivingNotification(self)
|
|
78
|
+
OnCreate {
|
|
79
|
+
screenOrientationRegistry.registerController(self)
|
|
84
80
|
}
|
|
85
81
|
|
|
86
82
|
OnDestroy {
|
|
87
|
-
screenOrientationRegistry.
|
|
88
|
-
screenOrientationRegistry.moduleWillDeallocate(self)
|
|
83
|
+
screenOrientationRegistry.unregisterController(self)
|
|
89
84
|
}
|
|
90
85
|
}
|
|
91
86
|
|
|
92
|
-
// MARK: -
|
|
87
|
+
// MARK: - ScreenOrientationController
|
|
93
88
|
|
|
94
|
-
func screenOrientationDidChange(_ orientation: UIInterfaceOrientation) {
|
|
89
|
+
public func screenOrientationDidChange(_ orientation: UIInterfaceOrientation) {
|
|
95
90
|
guard let currentTraitCollection = screenOrientationRegistry.currentTraitCollection else {
|
|
96
91
|
return
|
|
97
92
|
}
|
|
@@ -105,14 +100,4 @@ public class ScreenOrientationModule: Module, OrientationListener, Hashable {
|
|
|
105
100
|
] as [String: Any]
|
|
106
101
|
])
|
|
107
102
|
}
|
|
108
|
-
|
|
109
|
-
// MARK: - Hashable
|
|
110
|
-
|
|
111
|
-
public func hash(into hasher: inout Hasher) {
|
|
112
|
-
hasher.combine(ObjectIdentifier(self))
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public static func == (lhs: ScreenOrientationModule, rhs: ScreenOrientationModule) -> Bool {
|
|
116
|
-
return ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
|
|
117
|
-
}
|
|
118
103
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import ExpoModulesCore
|
|
4
4
|
|
|
5
|
+
@objc(EXScreenOrientationReactDelegateHandler)
|
|
5
6
|
public class ScreenOrientationReactDelegateHandler: ExpoReactDelegateHandler {
|
|
6
7
|
public override func createRootViewController(reactDelegate: ExpoReactDelegate) -> UIViewController? {
|
|
7
8
|
return ScreenOrientationViewController(defaultScreenOrientationFromPlist: ())
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import ExpoModulesCore
|
|
3
3
|
|
|
4
|
-
protocol
|
|
4
|
+
public protocol ScreenOrientationController: AnyObject {
|
|
5
5
|
func screenOrientationDidChange(_ orientation: UIInterfaceOrientation)
|
|
6
6
|
}
|
|
7
7
|
|
|
@@ -14,16 +14,22 @@ public class ScreenOrientationRegistry: NSObject, UIApplicationDelegate {
|
|
|
14
14
|
@objc
|
|
15
15
|
public static let shared = ScreenOrientationRegistry()
|
|
16
16
|
|
|
17
|
-
var currentScreenOrientation: UIInterfaceOrientation
|
|
18
|
-
var
|
|
19
|
-
var
|
|
20
|
-
weak var currentTraitCollection: UITraitCollection?
|
|
17
|
+
public var currentScreenOrientation: UIInterfaceOrientation
|
|
18
|
+
var orientationControllers: [ScreenOrientationController] = []
|
|
19
|
+
var controllerInterfaceMasks: [ObjectIdentifier: UIInterfaceOrientationMask] = [:]
|
|
20
|
+
public weak var currentTraitCollection: UITraitCollection?
|
|
21
21
|
var lastOrientationMask: UIInterfaceOrientationMask
|
|
22
22
|
var rootViewController: UIViewController? {
|
|
23
|
-
|
|
23
|
+
let keyWindow = UIApplication
|
|
24
|
+
.shared
|
|
25
|
+
.connectedScenes
|
|
26
|
+
.flatMap { ($0 as? UIWindowScene)?.windows ?? [] }
|
|
27
|
+
.last { $0.isKeyWindow }
|
|
28
|
+
|
|
29
|
+
return keyWindow?.rootViewController
|
|
24
30
|
}
|
|
25
31
|
|
|
26
|
-
var currentOrientationMask: UIInterfaceOrientationMask {
|
|
32
|
+
public var currentOrientationMask: UIInterfaceOrientationMask {
|
|
27
33
|
var currentOrientationMask: UIInterfaceOrientationMask = []
|
|
28
34
|
|
|
29
35
|
EXUtilities.performSynchronously {
|
|
@@ -55,7 +61,7 @@ public class ScreenOrientationRegistry: NSObject, UIApplicationDelegate {
|
|
|
55
61
|
/**
|
|
56
62
|
Called by ScreenOrientationAppDelegate in order to set initial interface orientation.
|
|
57
63
|
*/
|
|
58
|
-
func updateCurrentScreenOrientation() {
|
|
64
|
+
public func updateCurrentScreenOrientation() {
|
|
59
65
|
let windows = UIApplication.shared.windows
|
|
60
66
|
if !windows.isEmpty {
|
|
61
67
|
self.currentScreenOrientation = windows[0].windowScene?.interfaceOrientation ?? .unknown
|
|
@@ -106,8 +112,10 @@ public class ScreenOrientationRegistry: NSObject, UIApplicationDelegate {
|
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
114
|
|
|
109
|
-
func setMask(_ mask: UIInterfaceOrientationMask,
|
|
110
|
-
|
|
115
|
+
public func setMask(_ mask: UIInterfaceOrientationMask, forController controller: any ScreenOrientationController) {
|
|
116
|
+
let controllerIdentifier = ObjectIdentifier(controller)
|
|
117
|
+
|
|
118
|
+
controllerInterfaceMasks[controllerIdentifier] = mask
|
|
111
119
|
enforceDesiredDeviceOrientation(withOrientationMask: mask)
|
|
112
120
|
}
|
|
113
121
|
|
|
@@ -118,14 +126,14 @@ public class ScreenOrientationRegistry: NSObject, UIApplicationDelegate {
|
|
|
118
126
|
*/
|
|
119
127
|
@objc
|
|
120
128
|
public func requiredOrientationMask() -> UIInterfaceOrientationMask {
|
|
121
|
-
if
|
|
129
|
+
if controllerInterfaceMasks.isEmpty {
|
|
122
130
|
return []
|
|
123
131
|
}
|
|
124
132
|
|
|
125
133
|
// We want to apply an orientation mask which is an intersection of locks applied by the modules.
|
|
126
134
|
var mask = doesDeviceHaveNotch ? UIInterfaceOrientationMask.allButUpsideDown : UIInterfaceOrientationMask.all
|
|
127
135
|
|
|
128
|
-
for moduleMask in
|
|
136
|
+
for moduleMask in controllerInterfaceMasks {
|
|
129
137
|
mask = mask.intersection(moduleMask.value)
|
|
130
138
|
}
|
|
131
139
|
|
|
@@ -225,28 +233,24 @@ public class ScreenOrientationRegistry: NSObject, UIApplicationDelegate {
|
|
|
225
233
|
}
|
|
226
234
|
|
|
227
235
|
/**
|
|
228
|
-
Called at the end of the screen orientation change. Notifies
|
|
236
|
+
Called at the end of the screen orientation change. Notifies the controllers about the orientation change.
|
|
229
237
|
*/
|
|
230
238
|
func screenOrientationDidChange(_ newScreenOrientation: UIInterfaceOrientation) {
|
|
231
239
|
currentScreenOrientation = newScreenOrientation
|
|
232
|
-
|
|
233
|
-
|
|
240
|
+
|
|
241
|
+
for controller in orientationControllers {
|
|
242
|
+
controller.screenOrientationDidChange(newScreenOrientation)
|
|
234
243
|
}
|
|
235
244
|
}
|
|
236
245
|
|
|
237
|
-
func
|
|
238
|
-
|
|
246
|
+
public func registerController(_ controller: ScreenOrientationController) {
|
|
247
|
+
orientationControllers.append(controller)
|
|
239
248
|
}
|
|
240
249
|
|
|
241
|
-
func
|
|
242
|
-
|
|
243
|
-
}
|
|
250
|
+
public func unregisterController(_ controller: ScreenOrientationController) {
|
|
251
|
+
let controllerIdentifier = ObjectIdentifier(controller)
|
|
244
252
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
if orientationListeners[i] === module || orientationListeners[i] == nil {
|
|
248
|
-
orientationListeners.remove(at: i)
|
|
249
|
-
}
|
|
250
|
-
}
|
|
253
|
+
controllerInterfaceMasks.removeValue(forKey: controllerIdentifier)
|
|
254
|
+
orientationControllers.removeAll(where: { $0 === controller })
|
|
251
255
|
}
|
|
252
256
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-screen-orientation",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.2",
|
|
4
4
|
"description": "Expo universal module for managing device's screen orientation",
|
|
5
5
|
"main": "build/ScreenOrientation.js",
|
|
6
6
|
"types": "build/ScreenOrientation.d.ts",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"expo": "*"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "cf90d5c30c2a08a6493ebfa8aa3791aa70666759"
|
|
45
45
|
}
|