@capawesome/capacitor-screen-orientation 1.1.7-dev.36f3183.1659623993
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 -0
- package/LICENSE +21 -0
- package/README.md +232 -0
- package/android/build.gradle +57 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/io/capawesome/capacitor/screenorientation/ScreenOrientation.java +87 -0
- package/android/src/main/java/io/capawesome/capacitor/screenorientation/ScreenOrientationPlugin.java +56 -0
- package/android/src/main/java/io/capawesome/capacitor/screenorientation/ScreenOrientationType.java +11 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +217 -0
- package/dist/esm/definitions.d.ts +71 -0
- package/dist/esm/definitions.js +28 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +11 -0
- package/dist/esm/web.js +49 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +92 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +95 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/ScreenOrientation.swift +141 -0
- package/ios/Plugin/ScreenOrientationPlugin.h +10 -0
- package/ios/Plugin/ScreenOrientationPlugin.m +11 -0
- package/ios/Plugin/ScreenOrientationPlugin.swift +47 -0
- package/package.json +81 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
@objc public class ScreenOrientation: NSObject {
|
|
5
|
+
static var supportedInterfaceOrientations = UIInterfaceOrientationMask.all
|
|
6
|
+
private let plugin: ScreenOrientationPlugin
|
|
7
|
+
private var currentOrientationType: String?
|
|
8
|
+
private var lastOrientationType: String?
|
|
9
|
+
|
|
10
|
+
init(plugin: ScreenOrientationPlugin) {
|
|
11
|
+
self.plugin = plugin
|
|
12
|
+
super.init()
|
|
13
|
+
NotificationCenter.default.addObserver(self, selector: #selector(self.handleOrientationChange), name: UIDevice.orientationDidChangeNotification, object: nil)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@objc public static func getSupportedInterfaceOrientations() -> UIInterfaceOrientationMask {
|
|
17
|
+
return ScreenOrientation.supportedInterfaceOrientations
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@objc public func lock(_ orientationType: String, completion: @escaping () -> Void) {
|
|
21
|
+
DispatchQueue.main.async { [weak self] in
|
|
22
|
+
guard let strongSelf = self else {
|
|
23
|
+
return
|
|
24
|
+
}
|
|
25
|
+
let currentOrientationValue = UIDevice.current.orientation.rawValue
|
|
26
|
+
let nextOrientationMask = strongSelf.convertOrientationTypeToMask(orientationType)
|
|
27
|
+
let nextOrientationValue = strongSelf.convertOrientationTypeToValue(orientationType)
|
|
28
|
+
UIDevice.current.setValue(nextOrientationValue, forKey: "orientation")
|
|
29
|
+
ScreenOrientation.supportedInterfaceOrientations = nextOrientationMask
|
|
30
|
+
UINavigationController.attemptRotationToDeviceOrientation()
|
|
31
|
+
UIDevice.current.setValue(currentOrientationValue, forKey: "orientation")
|
|
32
|
+
strongSelf.notifyOrientationChangeListeners(orientationType)
|
|
33
|
+
completion()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@objc public func unlock(completion: @escaping () -> Void) {
|
|
38
|
+
DispatchQueue.main.async {
|
|
39
|
+
ScreenOrientation.supportedInterfaceOrientations = UIInterfaceOrientationMask.all
|
|
40
|
+
UINavigationController.attemptRotationToDeviceOrientation()
|
|
41
|
+
guard let orientationType = self.lastOrientationType else {
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
self.notifyOrientationChangeListeners(orientationType)
|
|
45
|
+
completion()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@objc public func getCachedCurrentOrientationType(completion: @escaping (String) -> Void) {
|
|
50
|
+
guard let cachedOrientationType = self.currentOrientationType else {
|
|
51
|
+
self.getUncachedCurrentOrientationType(completion: completion)
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
completion(cachedOrientationType)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@objc private func getUncachedCurrentOrientationType(completion: @escaping (String) -> Void) {
|
|
58
|
+
DispatchQueue.main.async {
|
|
59
|
+
let orientationValue = UIDevice.current.orientation.rawValue
|
|
60
|
+
let orientationType = self.convertOrientationValueToType(orientationValue)
|
|
61
|
+
completion(orientationType)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@objc private func isCurrentOrientationValid() -> Bool {
|
|
66
|
+
return UIDevice.current.orientation.isValidInterfaceOrientation
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@objc private func handleOrientationChange() {
|
|
70
|
+
let isValid = self.isCurrentOrientationValid()
|
|
71
|
+
guard isValid else {
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
self.getUncachedCurrentOrientationType(completion: { orientationType in
|
|
75
|
+
self.lastOrientationType = orientationType
|
|
76
|
+
guard ScreenOrientation.supportedInterfaceOrientations == UIInterfaceOrientationMask.all else {
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
self.notifyOrientationChangeListeners(orientationType)
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@objc private func notifyOrientationChangeListeners(_ orientationType: String) {
|
|
84
|
+
self.currentOrientationType = orientationType
|
|
85
|
+
self.plugin.notifyOrientationChangeListeners(orientationType)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@objc private func convertOrientationTypeToMask(_ orientationType: String) -> UIInterfaceOrientationMask {
|
|
89
|
+
switch orientationType {
|
|
90
|
+
case "landscape":
|
|
91
|
+
return UIInterfaceOrientationMask.landscapeRight
|
|
92
|
+
case "landscape-primary":
|
|
93
|
+
return UIInterfaceOrientationMask.landscapeLeft
|
|
94
|
+
case "landscape-secondary":
|
|
95
|
+
return UIInterfaceOrientationMask.landscapeRight
|
|
96
|
+
case "portrait":
|
|
97
|
+
return UIInterfaceOrientationMask.portrait
|
|
98
|
+
case "portrait-primary":
|
|
99
|
+
return UIInterfaceOrientationMask.portrait
|
|
100
|
+
case "portrait-secondary":
|
|
101
|
+
return UIInterfaceOrientationMask.portraitUpsideDown
|
|
102
|
+
default:
|
|
103
|
+
return UIInterfaceOrientationMask.all
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@objc private func convertOrientationTypeToValue(_ orientationType: String) -> Int {
|
|
108
|
+
switch orientationType {
|
|
109
|
+
case "landscape":
|
|
110
|
+
return UIInterfaceOrientation.landscapeRight.rawValue
|
|
111
|
+
case "landscape-primary":
|
|
112
|
+
return UIInterfaceOrientation.landscapeLeft.rawValue
|
|
113
|
+
case "landscape-secondary":
|
|
114
|
+
return UIInterfaceOrientation.landscapeRight.rawValue
|
|
115
|
+
case "portrait":
|
|
116
|
+
return UIInterfaceOrientation.portrait.rawValue
|
|
117
|
+
case "portrait-primary":
|
|
118
|
+
return UIInterfaceOrientation.portrait.rawValue
|
|
119
|
+
case "portrait-secondary":
|
|
120
|
+
return UIInterfaceOrientation.portraitUpsideDown.rawValue
|
|
121
|
+
default:
|
|
122
|
+
return UIInterfaceOrientation.unknown.rawValue
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@objc private func convertOrientationValueToType(_ orientationValue: Int) -> String {
|
|
127
|
+
switch orientationValue {
|
|
128
|
+
case UIInterfaceOrientation.landscapeLeft.rawValue:
|
|
129
|
+
return "landscape-primary"
|
|
130
|
+
case UIInterfaceOrientation.landscapeRight.rawValue:
|
|
131
|
+
return "landscape-secondary"
|
|
132
|
+
case UIInterfaceOrientation.portrait.rawValue:
|
|
133
|
+
return "portrait-primary"
|
|
134
|
+
case UIInterfaceOrientation.portraitUpsideDown.rawValue:
|
|
135
|
+
return "portrait-secondary"
|
|
136
|
+
default:
|
|
137
|
+
let isPortrait = UIApplication.shared.statusBarOrientation.isPortrait
|
|
138
|
+
return isPortrait ? "portrait-primary" : "landscape-primary"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +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
|
+
|
|
@@ -0,0 +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
|
+
)
|
|
@@ -0,0 +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
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capawesome/capacitor-screen-orientation",
|
|
3
|
+
"version": "1.1.7-dev.36f3183.1659623993",
|
|
4
|
+
"description": "Capacitor plugin to lock/unlock the screen orientation.",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Plugin/",
|
|
14
|
+
"CapawesomeCapacitorScreenOrientation.podspec"
|
|
15
|
+
],
|
|
16
|
+
"author": "Robin Genz <mail@robingenz.dev>",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/capawesome-team/capacitor-screen-orientation.git"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/capawesome-team/capacitor-screen-orientation/issues"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"capacitor",
|
|
27
|
+
"plugin",
|
|
28
|
+
"native"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
32
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
33
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
34
|
+
"verify:web": "npm run build",
|
|
35
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
36
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
37
|
+
"eslint": "eslint . --ext ts",
|
|
38
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
39
|
+
"swiftlint": "node-swiftlint",
|
|
40
|
+
"docgen": "docgen --api ScreenOrientationPlugin --output-readme README.md --output-json dist/docs.json",
|
|
41
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
|
|
42
|
+
"clean": "rimraf ./dist",
|
|
43
|
+
"watch": "tsc --watch",
|
|
44
|
+
"prepublishOnly": "npm run build",
|
|
45
|
+
"release": "standard-version"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@capacitor/android": "4.0.1",
|
|
49
|
+
"@capacitor/cli": "4.0.1",
|
|
50
|
+
"@capacitor/core": "4.0.1",
|
|
51
|
+
"@capacitor/docgen": "0.2.0",
|
|
52
|
+
"@capacitor/ios": "4.0.1",
|
|
53
|
+
"@ionic/eslint-config": "0.3.0",
|
|
54
|
+
"@ionic/prettier-config": "1.0.1",
|
|
55
|
+
"@ionic/swiftlint-config": "1.1.2",
|
|
56
|
+
"eslint": "7.32.0",
|
|
57
|
+
"prettier": "2.3.2",
|
|
58
|
+
"prettier-plugin-java": "1.0.2",
|
|
59
|
+
"rimraf": "3.0.2",
|
|
60
|
+
"rollup": "2.77.2",
|
|
61
|
+
"standard-version": "9.5.0",
|
|
62
|
+
"swiftlint": "1.0.1",
|
|
63
|
+
"typescript": "4.1.5"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@capacitor/core": "^4.0.0"
|
|
67
|
+
},
|
|
68
|
+
"prettier": "@ionic/prettier-config",
|
|
69
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
70
|
+
"eslintConfig": {
|
|
71
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
72
|
+
},
|
|
73
|
+
"capacitor": {
|
|
74
|
+
"ios": {
|
|
75
|
+
"src": "ios"
|
|
76
|
+
},
|
|
77
|
+
"android": {
|
|
78
|
+
"src": "android"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|