@capawesome/capacitor-screen-orientation 2.0.1 → 2.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/CapawesomeCapacitorScreenOrientation.podspec +17 -17
- package/LICENSE +21 -21
- package/README.md +93 -93
- package/android/build.gradle +57 -57
- package/android/src/main/AndroidManifest.xml +3 -3
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenorientation/ScreenOrientation.java +87 -87
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenorientation/ScreenOrientationPlugin.java +56 -56
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenorientation/ScreenOrientationType.java +11 -11
- package/dist/esm/definitions.d.ts +71 -71
- package/dist/esm/definitions.js +27 -27
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +6 -6
- package/dist/esm/web.d.ts +11 -11
- package/dist/esm/web.js +48 -48
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +73 -73
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +73 -73
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Info.plist +24 -24
- package/ios/Plugin/ScreenOrientation.swift +171 -150
- package/ios/Plugin/ScreenOrientationPlugin.h +10 -10
- package/ios/Plugin/ScreenOrientationPlugin.m +11 -11
- package/ios/Plugin/ScreenOrientationPlugin.swift +47 -47
- package/package.json +94 -94
|
@@ -1,150 +1,171 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import UIKit
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
private
|
|
8
|
-
private var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@objc private func
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
case
|
|
129
|
-
return
|
|
130
|
-
case
|
|
131
|
-
return
|
|
132
|
-
|
|
133
|
-
return
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
import Capacitor
|
|
4
|
+
|
|
5
|
+
@objc public class ScreenOrientation: NSObject {
|
|
6
|
+
static var supportedInterfaceOrientations = UIInterfaceOrientationMask.all
|
|
7
|
+
private let plugin: ScreenOrientationPlugin
|
|
8
|
+
private var currentOrientationType: String?
|
|
9
|
+
private var lastOrientationType: String?
|
|
10
|
+
|
|
11
|
+
init(plugin: ScreenOrientationPlugin) {
|
|
12
|
+
self.plugin = plugin
|
|
13
|
+
super.init()
|
|
14
|
+
NotificationCenter.default.addObserver(self, selector: #selector(self.handleOrientationChange), name: UIDevice.orientationDidChangeNotification, object: nil)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@objc public static func getSupportedInterfaceOrientations() -> UIInterfaceOrientationMask {
|
|
18
|
+
return ScreenOrientation.supportedInterfaceOrientations
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@objc public func lock(_ orientationType: String, completion: @escaping () -> Void) {
|
|
22
|
+
DispatchQueue.main.async { [weak self] in
|
|
23
|
+
guard let strongSelf = self else {
|
|
24
|
+
return
|
|
25
|
+
}
|
|
26
|
+
let currentOrientationValue = UIDevice.current.orientation.rawValue
|
|
27
|
+
let currentOrientationMask = strongSelf.convertOrientationValueToMask(currentOrientationValue)
|
|
28
|
+
let nextOrientationMask = strongSelf.convertOrientationTypeToMask(orientationType)
|
|
29
|
+
let nextOrientationValue = strongSelf.convertOrientationTypeToValue(orientationType)
|
|
30
|
+
strongSelf.requestGeometryUpdate(orientationValue: nextOrientationValue, orientationMask: nextOrientationMask)
|
|
31
|
+
ScreenOrientation.supportedInterfaceOrientations = nextOrientationMask
|
|
32
|
+
UINavigationController.attemptRotationToDeviceOrientation()
|
|
33
|
+
strongSelf.requestGeometryUpdate(orientationValue: currentOrientationValue, orientationMask: currentOrientationMask)
|
|
34
|
+
strongSelf.notifyOrientationChangeListeners(orientationType)
|
|
35
|
+
completion()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@objc public func unlock(completion: @escaping () -> Void) {
|
|
40
|
+
DispatchQueue.main.async {
|
|
41
|
+
ScreenOrientation.supportedInterfaceOrientations = UIInterfaceOrientationMask.all
|
|
42
|
+
UINavigationController.attemptRotationToDeviceOrientation()
|
|
43
|
+
guard let orientationType = self.lastOrientationType else {
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
self.notifyOrientationChangeListeners(orientationType)
|
|
47
|
+
completion()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@objc public func getCachedCurrentOrientationType(completion: @escaping (String) -> Void) {
|
|
52
|
+
guard let cachedOrientationType = self.currentOrientationType else {
|
|
53
|
+
self.getUncachedCurrentOrientationType(completion: completion)
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
completion(cachedOrientationType)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@objc private func requestGeometryUpdate(orientationValue: Int, orientationMask: UIInterfaceOrientationMask) {
|
|
60
|
+
if #available(iOS 16, *) {
|
|
61
|
+
let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
|
|
62
|
+
windowScene?.keyWindow?.rootViewController?.setNeedsUpdateOfSupportedInterfaceOrientations()
|
|
63
|
+
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: orientationMask)) { error in
|
|
64
|
+
CAPLog.print("requestGeometryUpdate failed.", error)
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
UIDevice.current.setValue(orientationValue, forKey: "orientation")
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@objc private func getUncachedCurrentOrientationType(completion: @escaping (String) -> Void) {
|
|
72
|
+
DispatchQueue.main.async {
|
|
73
|
+
let orientationValue = UIDevice.current.orientation.rawValue
|
|
74
|
+
let orientationType = self.convertOrientationValueToType(orientationValue)
|
|
75
|
+
completion(orientationType)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@objc private func isCurrentOrientationValid() -> Bool {
|
|
80
|
+
return UIDevice.current.orientation.isValidInterfaceOrientation
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@objc private func handleOrientationChange() {
|
|
84
|
+
let isValid = self.isCurrentOrientationValid()
|
|
85
|
+
guard isValid else {
|
|
86
|
+
return
|
|
87
|
+
}
|
|
88
|
+
self.getUncachedCurrentOrientationType(completion: { orientationType in
|
|
89
|
+
self.lastOrientationType = orientationType
|
|
90
|
+
guard ScreenOrientation.supportedInterfaceOrientations == UIInterfaceOrientationMask.all else {
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
self.notifyOrientationChangeListeners(orientationType)
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@objc private func notifyOrientationChangeListeners(_ orientationType: String) {
|
|
98
|
+
self.currentOrientationType = orientationType
|
|
99
|
+
self.plugin.notifyOrientationChangeListeners(orientationType)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@objc private func convertOrientationValueToMask(_ orientationValue: Int) -> UIInterfaceOrientationMask {
|
|
103
|
+
switch orientationValue {
|
|
104
|
+
case UIInterfaceOrientation.landscapeLeft.rawValue:
|
|
105
|
+
return UIInterfaceOrientationMask.landscapeLeft
|
|
106
|
+
case UIInterfaceOrientation.landscapeRight.rawValue:
|
|
107
|
+
return UIInterfaceOrientationMask.landscapeRight
|
|
108
|
+
case UIInterfaceOrientation.portrait.rawValue:
|
|
109
|
+
return UIInterfaceOrientationMask.portrait
|
|
110
|
+
case UIInterfaceOrientation.portraitUpsideDown.rawValue:
|
|
111
|
+
return UIInterfaceOrientationMask.portraitUpsideDown
|
|
112
|
+
default:
|
|
113
|
+
let isPortrait = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isPortrait ?? false
|
|
114
|
+
return isPortrait ? UIInterfaceOrientationMask.portrait : UIInterfaceOrientationMask.landscapeLeft
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@objc private func convertOrientationTypeToMask(_ orientationType: String) -> UIInterfaceOrientationMask {
|
|
119
|
+
switch orientationType {
|
|
120
|
+
case "landscape":
|
|
121
|
+
return UIInterfaceOrientationMask.landscapeRight
|
|
122
|
+
case "landscape-primary":
|
|
123
|
+
return UIInterfaceOrientationMask.landscapeLeft
|
|
124
|
+
case "landscape-secondary":
|
|
125
|
+
return UIInterfaceOrientationMask.landscapeRight
|
|
126
|
+
case "portrait":
|
|
127
|
+
return UIInterfaceOrientationMask.portrait
|
|
128
|
+
case "portrait-primary":
|
|
129
|
+
return UIInterfaceOrientationMask.portrait
|
|
130
|
+
case "portrait-secondary":
|
|
131
|
+
return UIInterfaceOrientationMask.portraitUpsideDown
|
|
132
|
+
default:
|
|
133
|
+
return UIInterfaceOrientationMask.all
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
@objc private func convertOrientationTypeToValue(_ orientationType: String) -> Int {
|
|
138
|
+
switch orientationType {
|
|
139
|
+
case "landscape":
|
|
140
|
+
return UIInterfaceOrientation.landscapeRight.rawValue
|
|
141
|
+
case "landscape-primary":
|
|
142
|
+
return UIInterfaceOrientation.landscapeLeft.rawValue
|
|
143
|
+
case "landscape-secondary":
|
|
144
|
+
return UIInterfaceOrientation.landscapeRight.rawValue
|
|
145
|
+
case "portrait":
|
|
146
|
+
return UIInterfaceOrientation.portrait.rawValue
|
|
147
|
+
case "portrait-primary":
|
|
148
|
+
return UIInterfaceOrientation.portrait.rawValue
|
|
149
|
+
case "portrait-secondary":
|
|
150
|
+
return UIInterfaceOrientation.portraitUpsideDown.rawValue
|
|
151
|
+
default:
|
|
152
|
+
return UIInterfaceOrientation.unknown.rawValue
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@objc private func convertOrientationValueToType(_ orientationValue: Int) -> String {
|
|
157
|
+
switch orientationValue {
|
|
158
|
+
case UIInterfaceOrientation.landscapeLeft.rawValue:
|
|
159
|
+
return "landscape-primary"
|
|
160
|
+
case UIInterfaceOrientation.landscapeRight.rawValue:
|
|
161
|
+
return "landscape-secondary"
|
|
162
|
+
case UIInterfaceOrientation.portrait.rawValue:
|
|
163
|
+
return "portrait-primary"
|
|
164
|
+
case UIInterfaceOrientation.portraitUpsideDown.rawValue:
|
|
165
|
+
return "portrait-secondary"
|
|
166
|
+
default:
|
|
167
|
+
let isPortrait = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation.isPortrait ?? false
|
|
168
|
+
return isPortrait ? "portrait-primary" : "landscape-primary"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
#import <UIKit/UIKit.h>
|
|
2
|
-
|
|
3
|
-
//! Project version number for Plugin.
|
|
4
|
-
FOUNDATION_EXPORT double PluginVersionNumber;
|
|
5
|
-
|
|
6
|
-
//! Project version string for Plugin.
|
|
7
|
-
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
|
8
|
-
|
|
9
|
-
// In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
|
|
10
|
-
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
//! Project version number for Plugin.
|
|
4
|
+
FOUNDATION_EXPORT double PluginVersionNumber;
|
|
5
|
+
|
|
6
|
+
//! Project version string for Plugin.
|
|
7
|
+
FOUNDATION_EXPORT const unsigned char PluginVersionString[];
|
|
8
|
+
|
|
9
|
+
// In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
|
|
10
|
+
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
#import <Capacitor/Capacitor.h>
|
|
3
|
-
|
|
4
|
-
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
-
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
-
CAP_PLUGIN(ScreenOrientationPlugin, "ScreenOrientation",
|
|
7
|
-
CAP_PLUGIN_METHOD(lock, CAPPluginReturnPromise);
|
|
8
|
-
CAP_PLUGIN_METHOD(unlock, CAPPluginReturnPromise);
|
|
9
|
-
CAP_PLUGIN_METHOD(getCurrentOrientation, CAPPluginReturnPromise);
|
|
10
|
-
CAP_PLUGIN_METHOD(removeAllListeners, CAPPluginReturnNone);
|
|
11
|
-
)
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <Capacitor/Capacitor.h>
|
|
3
|
+
|
|
4
|
+
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
+
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
+
CAP_PLUGIN(ScreenOrientationPlugin, "ScreenOrientation",
|
|
7
|
+
CAP_PLUGIN_METHOD(lock, CAPPluginReturnPromise);
|
|
8
|
+
CAP_PLUGIN_METHOD(unlock, CAPPluginReturnPromise);
|
|
9
|
+
CAP_PLUGIN_METHOD(getCurrentOrientation, CAPPluginReturnPromise);
|
|
10
|
+
CAP_PLUGIN_METHOD(removeAllListeners, CAPPluginReturnNone);
|
|
11
|
+
)
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Capacitor
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
-
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
-
*/
|
|
8
|
-
@objc(ScreenOrientationPlugin)
|
|
9
|
-
public class ScreenOrientationPlugin: CAPPlugin {
|
|
10
|
-
public let screenOrientationChangeEvent = "screenOrientationChange"
|
|
11
|
-
private var implementation: ScreenOrientation?
|
|
12
|
-
|
|
13
|
-
override public func load() {
|
|
14
|
-
self.implementation = ScreenOrientation(plugin: self)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
deinit {
|
|
18
|
-
NotificationCenter.default.removeObserver(self)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
@objc func lock(_ call: CAPPluginCall) {
|
|
22
|
-
let orientationType = call.getString("type") ?? ""
|
|
23
|
-
implementation?.lock(orientationType, completion: {
|
|
24
|
-
call.resolve()
|
|
25
|
-
})
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@objc func unlock(_ call: CAPPluginCall) {
|
|
29
|
-
implementation?.unlock(completion: {
|
|
30
|
-
call.resolve()
|
|
31
|
-
})
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
@objc func getCurrentOrientation(_ call: CAPPluginCall) {
|
|
35
|
-
implementation?.getCachedCurrentOrientationType(completion: { orientationType in
|
|
36
|
-
call.resolve([
|
|
37
|
-
"type": orientationType
|
|
38
|
-
])
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@objc func notifyOrientationChangeListeners(_ orientationType: String) {
|
|
43
|
-
self.notifyListeners(self.screenOrientationChangeEvent, data: [
|
|
44
|
-
"type": orientationType
|
|
45
|
-
])
|
|
46
|
-
}
|
|
47
|
-
}
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
+
*/
|
|
8
|
+
@objc(ScreenOrientationPlugin)
|
|
9
|
+
public class ScreenOrientationPlugin: CAPPlugin {
|
|
10
|
+
public let screenOrientationChangeEvent = "screenOrientationChange"
|
|
11
|
+
private var implementation: ScreenOrientation?
|
|
12
|
+
|
|
13
|
+
override public func load() {
|
|
14
|
+
self.implementation = ScreenOrientation(plugin: self)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
deinit {
|
|
18
|
+
NotificationCenter.default.removeObserver(self)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@objc func lock(_ call: CAPPluginCall) {
|
|
22
|
+
let orientationType = call.getString("type") ?? ""
|
|
23
|
+
implementation?.lock(orientationType, completion: {
|
|
24
|
+
call.resolve()
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@objc func unlock(_ call: CAPPluginCall) {
|
|
29
|
+
implementation?.unlock(completion: {
|
|
30
|
+
call.resolve()
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@objc func getCurrentOrientation(_ call: CAPPluginCall) {
|
|
35
|
+
implementation?.getCachedCurrentOrientationType(completion: { orientationType in
|
|
36
|
+
call.resolve([
|
|
37
|
+
"type": orientationType
|
|
38
|
+
])
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@objc func notifyOrientationChangeListeners(_ orientationType: String) {
|
|
43
|
+
self.notifyListeners(self.screenOrientationChangeEvent, data: [
|
|
44
|
+
"type": orientationType
|
|
45
|
+
])
|
|
46
|
+
}
|
|
47
|
+
}
|