@capgo/capacitor-screen-orientation 8.1.20 → 8.2.0
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/README.md +235 -9
- package/android/build.gradle +2 -0
- package/android/src/main/java/ee/forgr/capacitor/screenorientation/CapacitorScreenOrientationPlugin.java +189 -1
- package/android/src/main/java/ee/forgr/capacitor/screenorientation/FoldLayout.java +176 -0
- package/dist/docs.json +525 -10
- package/dist/esm/definitions.d.ts +234 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +8 -1
- package/dist/esm/web.js +43 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +45 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +45 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapacitorScreenOrientationPlugin/CapacitorScreenOrientationPlugin.swift +100 -1
- package/package.json +2 -1
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst ScreenOrientation = registerPlugin('CapacitorScreenOrientation', {\n web: () => import('./web').then((m) => new m.CapacitorScreenOrientationWeb()),\n});\nexport * from './definitions';\nexport { ScreenOrientation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapacitorScreenOrientationWeb extends WebPlugin {\n constructor() {\n var _a;\n super();\n this.pluginVersion = '1.0.0';\n if ((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation) {\n window.screen.orientation.addEventListener('change', () => {\n this.notifyListeners('screenOrientationChange', {\n type: this.mapOrientationType(window.screen.orientation.type),\n });\n });\n }\n }\n async orientation() {\n var _a;\n if (!((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation)) {\n throw this.unavailable('Screen Orientation API not available');\n }\n return {\n type: this.mapOrientationType(window.screen.orientation.type),\n };\n }\n async lock(options) {\n var _a;\n const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;\n if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.lock)) {\n throw this.unavailable('Screen Orientation lock not available');\n }\n // bypassOrientationLock is only supported on iOS native platform\n // Silently ignore it on web\n try {\n await screenOrientation.lock(options.orientation);\n }\n catch (error) {\n throw new Error(`Failed to lock orientation: ${error}`);\n }\n }\n async unlock() {\n var _a;\n const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;\n if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.unlock)) {\n throw this.unavailable('Screen Orientation unlock not available');\n }\n screenOrientation.unlock();\n }\n async startOrientationTracking(_options) {\n // Motion-based orientation tracking is only supported on iOS\n // Silently ignore on web\n console.warn('Motion-based orientation tracking is not available on web platform', _options);\n }\n async stopOrientationTracking() {\n // Motion-based orientation tracking is only supported on iOS\n // Silently ignore on web\n }\n async isOrientationLocked() {\n const orientationResult = await this.orientation();\n return {\n locked: false,\n uiOrientation: orientationResult.type,\n };\n }\n async getPluginVersion() {\n return { version: this.pluginVersion };\n }\n mapOrientationType(type) {\n if (type.includes('portrait-primary') || type === 'portrait-primary') {\n return 'portrait-primary';\n }\n if (type.includes('portrait-secondary') || type === 'portrait-secondary') {\n return 'portrait-secondary';\n }\n if (type.includes('landscape-primary') || type === 'landscape-primary') {\n return 'landscape-primary';\n }\n if (type.includes('landscape-secondary') || type === 'landscape-secondary') {\n return 'landscape-secondary';\n }\n return 'portrait-primary'; // default fallback\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,iBAAiB,GAAGA,mBAAc,CAAC,4BAA4B,EAAE;IACvE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,6BAA6B,EAAE,CAAC;IACjF,CAAC;;
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst ScreenOrientation = registerPlugin('CapacitorScreenOrientation', {\n web: () => import('./web').then((m) => new m.CapacitorScreenOrientationWeb()),\n});\nexport * from './definitions';\nexport { ScreenOrientation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nconst FLAT_FOLD = { state: 'flat', isSeparating: false, posture: 'flat' };\nexport function sizeClassOf(width, height) {\n const widthClass = width >= 1600\n ? 'extraLarge'\n : width >= 1200\n ? 'large'\n : width >= 840\n ? 'expanded'\n : width >= 600\n ? 'medium'\n : 'compact';\n const heightClass = height >= 900 ? 'expanded' : height >= 480 ? 'medium' : 'compact';\n return {\n horizontal: width >= 600 ? 'regular' : 'compact',\n vertical: height >= 480 ? 'regular' : 'compact',\n widthClass,\n heightClass,\n };\n}\nexport class CapacitorScreenOrientationWeb extends WebPlugin {\n constructor() {\n var _a;\n super();\n this.pluginVersion = '1.0.0';\n this.lastSizeClass = null;\n if ((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation) {\n window.screen.orientation.addEventListener('change', () => {\n this.notifyListeners('screenOrientationChange', {\n type: this.mapOrientationType(window.screen.orientation.type),\n });\n });\n }\n window.addEventListener('resize', () => {\n const next = this.readSizeClass();\n const previous = JSON.stringify(this.lastSizeClass);\n if (previous === JSON.stringify(next))\n return;\n this.lastSizeClass = next;\n this.notifyListeners('sizeClassChange', next);\n });\n }\n async orientation() {\n var _a;\n if (!((_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation)) {\n throw this.unavailable('Screen Orientation API not available');\n }\n return {\n type: this.mapOrientationType(window.screen.orientation.type),\n };\n }\n async lock(options) {\n var _a;\n const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;\n if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.lock)) {\n throw this.unavailable('Screen Orientation lock not available');\n }\n // bypassOrientationLock is only supported on iOS native platform\n // Silently ignore it on web\n try {\n await screenOrientation.lock(options.orientation);\n }\n catch (error) {\n throw new Error(`Failed to lock orientation: ${error}`);\n }\n }\n async unlock() {\n var _a;\n const screenOrientation = (_a = window.screen) === null || _a === void 0 ? void 0 : _a.orientation;\n if (!(screenOrientation === null || screenOrientation === void 0 ? void 0 : screenOrientation.unlock)) {\n throw this.unavailable('Screen Orientation unlock not available');\n }\n screenOrientation.unlock();\n }\n async startOrientationTracking(_options) {\n // Motion-based orientation tracking is only supported on iOS\n // Silently ignore on web\n console.warn('Motion-based orientation tracking is not available on web platform', _options);\n }\n async stopOrientationTracking() {\n // Motion-based orientation tracking is only supported on iOS\n // Silently ignore on web\n }\n async isOrientationLocked() {\n const orientationResult = await this.orientation();\n return {\n locked: false,\n uiOrientation: orientationResult.type,\n };\n }\n async isDeviceFoldable() {\n return { foldable: false, supportsTabletop: false };\n }\n async getFoldState() {\n return FLAT_FOLD;\n }\n async getHingeAngle() {\n return { angle: null };\n }\n async getSizeClass() {\n return this.readSizeClass();\n }\n async getPluginVersion() {\n return { version: this.pluginVersion };\n }\n readSizeClass() {\n return sizeClassOf(window.innerWidth, window.innerHeight);\n }\n mapOrientationType(type) {\n if (type.includes('portrait-primary') || type === 'portrait-primary') {\n return 'portrait-primary';\n }\n if (type.includes('portrait-secondary') || type === 'portrait-secondary') {\n return 'portrait-secondary';\n }\n if (type.includes('landscape-primary') || type === 'landscape-primary') {\n return 'landscape-primary';\n }\n if (type.includes('landscape-secondary') || type === 'landscape-secondary') {\n return 'landscape-secondary';\n }\n return 'portrait-primary'; // default fallback\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,iBAAiB,GAAGA,mBAAc,CAAC,4BAA4B,EAAE;IACvE,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,6BAA6B,EAAE,CAAC;IACjF,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
13
13
|
public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
14
|
-
private let pluginVersion: String = "8.
|
|
14
|
+
private let pluginVersion: String = "8.2.0"
|
|
15
15
|
public let identifier = "CapacitorScreenOrientationPlugin"
|
|
16
16
|
public let jsName = "CapacitorScreenOrientation"
|
|
17
17
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -21,6 +21,10 @@ public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
21
21
|
CAPPluginMethod(name: "startOrientationTracking", returnType: CAPPluginReturnPromise),
|
|
22
22
|
CAPPluginMethod(name: "stopOrientationTracking", returnType: CAPPluginReturnPromise),
|
|
23
23
|
CAPPluginMethod(name: "isOrientationLocked", returnType: CAPPluginReturnPromise),
|
|
24
|
+
CAPPluginMethod(name: "isDeviceFoldable", returnType: CAPPluginReturnPromise),
|
|
25
|
+
CAPPluginMethod(name: "getFoldState", returnType: CAPPluginReturnPromise),
|
|
26
|
+
CAPPluginMethod(name: "getHingeAngle", returnType: CAPPluginReturnPromise),
|
|
27
|
+
CAPPluginMethod(name: "getSizeClass", returnType: CAPPluginReturnPromise),
|
|
24
28
|
CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise)
|
|
25
29
|
]
|
|
26
30
|
|
|
@@ -30,6 +34,17 @@ public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
30
34
|
private var lastNotifiedOrientation: String?
|
|
31
35
|
private var capViewController: CAPBridgeViewController?
|
|
32
36
|
private var defaultSupportedOrientations: [Int] = []
|
|
37
|
+
private var lastSizeClassKey: String?
|
|
38
|
+
private var sizeClassProbe: SizeClassProbe?
|
|
39
|
+
|
|
40
|
+
private final class SizeClassProbe: UIView {
|
|
41
|
+
var onLayout: (() -> Void)?
|
|
42
|
+
|
|
43
|
+
override func layoutSubviews() {
|
|
44
|
+
super.layoutSubviews()
|
|
45
|
+
onLayout?()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
33
48
|
|
|
34
49
|
override public func load() {
|
|
35
50
|
// Listen for device orientation changes from system
|
|
@@ -47,15 +62,22 @@ public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
47
62
|
self.capViewController = viewController
|
|
48
63
|
self.defaultSupportedOrientations = viewController.supportedOrientations
|
|
49
64
|
}
|
|
65
|
+
DispatchQueue.main.async {
|
|
66
|
+
self.attachSizeClassProbe()
|
|
67
|
+
self.notifySizeClassIfChanged()
|
|
68
|
+
}
|
|
50
69
|
}
|
|
51
70
|
|
|
52
71
|
deinit {
|
|
53
72
|
stopMotionTracking()
|
|
73
|
+
sizeClassProbe?.removeFromSuperview()
|
|
54
74
|
UIDevice.current.endGeneratingDeviceOrientationNotifications()
|
|
55
75
|
NotificationCenter.default.removeObserver(self)
|
|
56
76
|
}
|
|
57
77
|
|
|
58
78
|
@objc private func orientationDidChange() {
|
|
79
|
+
notifySizeClassIfChanged()
|
|
80
|
+
|
|
59
81
|
// Skip system orientation changes when motion tracking is active
|
|
60
82
|
// to avoid duplicate events
|
|
61
83
|
guard !isTrackingWithMotion else { return }
|
|
@@ -66,6 +88,28 @@ public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
66
88
|
}
|
|
67
89
|
}
|
|
68
90
|
|
|
91
|
+
@objc func isDeviceFoldable(_ call: CAPPluginCall) {
|
|
92
|
+
call.resolve(["foldable": false, "supportsTabletop": false])
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@objc func getFoldState(_ call: CAPPluginCall) {
|
|
96
|
+
call.resolve([
|
|
97
|
+
"state": "flat",
|
|
98
|
+
"isSeparating": false,
|
|
99
|
+
"posture": "flat"
|
|
100
|
+
])
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@objc func getHingeAngle(_ call: CAPPluginCall) {
|
|
104
|
+
call.resolve(["angle": NSNull()])
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@objc func getSizeClass(_ call: CAPPluginCall) {
|
|
108
|
+
DispatchQueue.main.async {
|
|
109
|
+
call.resolve(self.currentSizeClass())
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
69
113
|
@objc func orientation(_ call: CAPPluginCall) {
|
|
70
114
|
let orientationType = getCurrentOrientationType()
|
|
71
115
|
call.resolve(["type": orientationType])
|
|
@@ -316,6 +360,61 @@ public class CapacitorScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
316
360
|
}
|
|
317
361
|
}
|
|
318
362
|
|
|
363
|
+
private func currentSizeClass() -> [String: Any] {
|
|
364
|
+
let view = self.bridge?.webView
|
|
365
|
+
let width = Double(view?.bounds.width ?? UIScreen.main.bounds.width)
|
|
366
|
+
let height = Double(view?.bounds.height ?? UIScreen.main.bounds.height)
|
|
367
|
+
let traits = view?.traitCollection
|
|
368
|
+
let horizontal = sizeName(traits?.horizontalSizeClass, points: width, regularAt: 600)
|
|
369
|
+
let vertical = sizeName(traits?.verticalSizeClass, points: height, regularAt: 480)
|
|
370
|
+
return [
|
|
371
|
+
"horizontal": horizontal,
|
|
372
|
+
"vertical": vertical,
|
|
373
|
+
"widthClass": materialWidth(width),
|
|
374
|
+
"heightClass": height >= 900 ? "expanded" : height >= 480 ? "medium" : "compact"
|
|
375
|
+
]
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
private func attachSizeClassProbe() {
|
|
379
|
+
guard sizeClassProbe == nil, let webView = bridge?.webView else { return }
|
|
380
|
+
let probe = SizeClassProbe(frame: webView.bounds)
|
|
381
|
+
probe.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
382
|
+
probe.isUserInteractionEnabled = false
|
|
383
|
+
probe.backgroundColor = .clear
|
|
384
|
+
probe.onLayout = { [weak self] in
|
|
385
|
+
self?.notifySizeClassIfChanged()
|
|
386
|
+
}
|
|
387
|
+
webView.addSubview(probe)
|
|
388
|
+
sizeClassProbe = probe
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
private func notifySizeClassIfChanged() {
|
|
392
|
+
let sizeClass = currentSizeClass()
|
|
393
|
+
let key = "\(sizeClass["horizontal"] ?? "")-\(sizeClass["vertical"] ?? "")-\(sizeClass["widthClass"] ?? "")-\(sizeClass["heightClass"] ?? "")"
|
|
394
|
+
guard key != lastSizeClassKey else { return }
|
|
395
|
+
lastSizeClassKey = key
|
|
396
|
+
notifyListeners("sizeClassChange", data: sizeClass)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
private func sizeName(_ sizeClass: UIUserInterfaceSizeClass?, points: Double, regularAt: Double) -> String {
|
|
400
|
+
switch sizeClass {
|
|
401
|
+
case .some(.regular):
|
|
402
|
+
return "regular"
|
|
403
|
+
case .some(.compact):
|
|
404
|
+
return "compact"
|
|
405
|
+
default:
|
|
406
|
+
return points >= regularAt ? "regular" : "compact"
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
private func materialWidth(_ width: Double) -> String {
|
|
411
|
+
if width >= 1600 { return "extraLarge" }
|
|
412
|
+
if width >= 1200 { return "large" }
|
|
413
|
+
if width >= 840 { return "expanded" }
|
|
414
|
+
if width >= 600 { return "medium" }
|
|
415
|
+
return "compact"
|
|
416
|
+
}
|
|
417
|
+
|
|
319
418
|
private func getOrientationMask(from orientationString: String) -> UIInterfaceOrientationMask? {
|
|
320
419
|
switch orientationString {
|
|
321
420
|
case "any":
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-screen-orientation",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "Screen orientation plugin with support for bypassing orientation lock",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"watch": "tsc --watch",
|
|
55
55
|
"prepublishOnly": "bun run build",
|
|
56
56
|
"check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs",
|
|
57
|
+
"check:cap9-deprecated": "node scripts/check-cap9-deprecated.mjs",
|
|
57
58
|
"example:install": "cd example-app && bun install --frozen-lockfile",
|
|
58
59
|
"example:build": "bun run build && cd example-app && bun install --frozen-lockfile && bun run build",
|
|
59
60
|
"changelog:ai": "node scripts/generate-ai-changelog.mjs"
|