@capawesome/capacitor-screen-orientation 7.0.2 → 8.0.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/CapawesomeCapacitorScreenOrientation.podspec +1 -1
- package/Package.swift +2 -2
- package/README.md +31 -2
- package/android/build.gradle +9 -9
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenorientation/ScreenOrientation.java +9 -26
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenorientation/ScreenOrientationPlugin.java +10 -4
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/screenorientation/ScreenOrientationType.java +39 -8
- package/dist/docs.json +2 -2
- package/dist/esm/definitions.d.ts +3 -3
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.js +9 -2
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +9 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +9 -2
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/ScreenOrientation.swift +16 -7
- package/ios/Plugin/ScreenOrientationPlugin.swift +1 -1
- package/package.json +10 -10
|
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
|
|
|
11
11
|
s.author = package['author']
|
|
12
12
|
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
13
|
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
-
s.ios.deployment_target
|
|
14
|
+
s.ios.deployment_target = '15.0'
|
|
15
15
|
s.dependency 'Capacitor'
|
|
16
16
|
s.swift_version = '5.1'
|
|
17
17
|
end
|
package/Package.swift
CHANGED
|
@@ -3,14 +3,14 @@ import PackageDescription
|
|
|
3
3
|
|
|
4
4
|
let package = Package(
|
|
5
5
|
name: "CapawesomeCapacitorScreenOrientation",
|
|
6
|
-
platforms: [.iOS(.
|
|
6
|
+
platforms: [.iOS(.v15)],
|
|
7
7
|
products: [
|
|
8
8
|
.library(
|
|
9
9
|
name: "CapawesomeCapacitorScreenOrientation",
|
|
10
10
|
targets: ["ScreenOrientationPlugin"])
|
|
11
11
|
],
|
|
12
12
|
dependencies: [
|
|
13
|
-
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "
|
|
13
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
|
|
14
14
|
],
|
|
15
15
|
targets: [
|
|
16
16
|
.target(
|
package/README.md
CHANGED
|
@@ -4,10 +4,39 @@ Capacitor plugin to lock/unlock the screen orientation.
|
|
|
4
4
|
|
|
5
5
|
<div class="capawesome-z29o10a">
|
|
6
6
|
<a href="https://cloud.capawesome.io/" target="_blank">
|
|
7
|
-
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-
|
|
7
|
+
<img alt="Deliver Live Updates to your Capacitor app with Capawesome Cloud" src="https://cloud.capawesome.io/assets/banners/cloud-build-and-deploy-capacitor-apps.png?t=1" />
|
|
8
8
|
</a>
|
|
9
9
|
</div>
|
|
10
10
|
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
We are proud to offer one of the most complete and feature-rich Capacitor plugins for screen orientation control. Here are some of the key features:
|
|
14
|
+
|
|
15
|
+
- 🖥️ **Cross-platform**: Supports Android, iOS, and Web.
|
|
16
|
+
- 🔒 **Orientation locking**: Lock screen to specific orientations.
|
|
17
|
+
- 🔓 **Orientation unlocking**: Unlock and restore automatic orientation.
|
|
18
|
+
- 📱 **Multiple orientations**: Support for portrait, landscape, and specific orientations.
|
|
19
|
+
- 🔄 **Orientation detection**: Get current screen orientation.
|
|
20
|
+
- 📢 **Event listeners**: Listen to orientation change events.
|
|
21
|
+
- 📐 **Fine-grained control**: Primary and secondary orientation modes.
|
|
22
|
+
- 🍎 **iPad support**: Special configuration for iPad orientation locking.
|
|
23
|
+
- 🔁 **Up-to-date**: Always supports the latest Capacitor version.
|
|
24
|
+
|
|
25
|
+
Missing a feature? Just [open an issue](https://github.com/capawesome-team/capacitor-plugins/issues) and we'll take a look!
|
|
26
|
+
|
|
27
|
+
## Newsletter
|
|
28
|
+
|
|
29
|
+
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our [Capawesome Newsletter](https://cloud.capawesome.io/newsletter/).
|
|
30
|
+
|
|
31
|
+
## Compatibility
|
|
32
|
+
|
|
33
|
+
| Plugin Version | Capacitor Version | Status |
|
|
34
|
+
| -------------- | ----------------- | -------------- |
|
|
35
|
+
| 8.x.x | >=8.x.x | Active support |
|
|
36
|
+
| 7.x.x | 7.x.x | Deprecated |
|
|
37
|
+
| 6.x.x | 6.x.x | Deprecated |
|
|
38
|
+
| 5.x.x | 5.x.x | Deprecated |
|
|
39
|
+
|
|
11
40
|
## Installation
|
|
12
41
|
|
|
13
42
|
```bash
|
|
@@ -89,7 +118,7 @@ const getCurrentOrientation = async () => {
|
|
|
89
118
|
### lock(...)
|
|
90
119
|
|
|
91
120
|
```typescript
|
|
92
|
-
lock(options
|
|
121
|
+
lock(options?: LockOptions | undefined) => Promise<void>
|
|
93
122
|
```
|
|
94
123
|
|
|
95
124
|
Locks the device orientation.
|
package/android/build.gradle
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
ext {
|
|
2
2
|
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
-
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.
|
|
4
|
-
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.
|
|
5
|
-
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
buildscript {
|
|
@@ -11,18 +11,18 @@ buildscript {
|
|
|
11
11
|
mavenCentral()
|
|
12
12
|
}
|
|
13
13
|
dependencies {
|
|
14
|
-
classpath 'com.android.tools.build:gradle:8.
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
apply plugin: 'com.android.library'
|
|
19
19
|
|
|
20
20
|
android {
|
|
21
|
-
namespace "io.capawesome.capacitorjs.plugins.screenorientation"
|
|
22
|
-
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion :
|
|
21
|
+
namespace = "io.capawesome.capacitorjs.plugins.screenorientation"
|
|
22
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
23
23
|
defaultConfig {
|
|
24
|
-
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion :
|
|
25
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
26
26
|
versionCode 1
|
|
27
27
|
versionName "1.0"
|
|
28
28
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
@@ -34,7 +34,7 @@ android {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
lintOptions {
|
|
37
|
-
abortOnError false
|
|
37
|
+
abortOnError = false
|
|
38
38
|
}
|
|
39
39
|
compileOptions {
|
|
40
40
|
sourceCompatibility JavaVersion.VERSION_21
|
|
@@ -44,44 +44,27 @@ public class ScreenOrientation {
|
|
|
44
44
|
return orientationChangeListener;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
public void lock(String orientationType) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
break;
|
|
52
|
-
case ScreenOrientationType.LANDSCAPE_PRIMARY:
|
|
53
|
-
bridge.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
54
|
-
break;
|
|
55
|
-
case ScreenOrientationType.LANDSCAPE_SECONDARY:
|
|
56
|
-
bridge.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
|
|
57
|
-
break;
|
|
58
|
-
case ScreenOrientationType.PORTRAIT:
|
|
59
|
-
bridge.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
|
|
60
|
-
break;
|
|
61
|
-
case ScreenOrientationType.PORTRAIT_PRIMARY:
|
|
62
|
-
bridge.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
63
|
-
break;
|
|
64
|
-
case ScreenOrientationType.PORTRAIT_SECONDARY:
|
|
65
|
-
bridge.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
47
|
+
public void lock(@Nullable String orientationType) throws Exception {
|
|
48
|
+
final String key = (orientationType == null) ? getCurrentOrientationTypeKey() : orientationType;
|
|
49
|
+
int value = ScreenOrientationType.toInt(key);
|
|
50
|
+
bridge.getActivity().setRequestedOrientation(value);
|
|
68
51
|
}
|
|
69
52
|
|
|
70
53
|
public void unlock() {
|
|
71
54
|
bridge.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
|
|
72
55
|
}
|
|
73
56
|
|
|
74
|
-
public String
|
|
57
|
+
public String getCurrentOrientationTypeKey() {
|
|
75
58
|
int rotation = bridge.getActivity().getWindowManager().getDefaultDisplay().getRotation();
|
|
76
59
|
switch (rotation) {
|
|
77
60
|
case Surface.ROTATION_90:
|
|
78
|
-
return ScreenOrientationType.LANDSCAPE_PRIMARY;
|
|
61
|
+
return ScreenOrientationType.LANDSCAPE_PRIMARY.key();
|
|
79
62
|
case Surface.ROTATION_180:
|
|
80
|
-
return ScreenOrientationType.PORTRAIT_SECONDARY;
|
|
63
|
+
return ScreenOrientationType.PORTRAIT_SECONDARY.key();
|
|
81
64
|
case Surface.ROTATION_270:
|
|
82
|
-
return ScreenOrientationType.LANDSCAPE_SECONDARY;
|
|
65
|
+
return ScreenOrientationType.LANDSCAPE_SECONDARY.key();
|
|
83
66
|
default:
|
|
84
|
-
return ScreenOrientationType.PORTRAIT_PRIMARY;
|
|
67
|
+
return ScreenOrientationType.PORTRAIT_PRIMARY.key();
|
|
85
68
|
}
|
|
86
69
|
}
|
|
87
70
|
}
|
|
@@ -10,6 +10,8 @@ import com.getcapacitor.annotation.CapacitorPlugin;
|
|
|
10
10
|
@CapacitorPlugin(name = "ScreenOrientation")
|
|
11
11
|
public class ScreenOrientationPlugin extends Plugin {
|
|
12
12
|
|
|
13
|
+
public static final String ERROR_UNSUPPORTED_ORIENTATION_TYPE = "Unsupported orientation type.";
|
|
14
|
+
|
|
13
15
|
public static final String SCREEN_ORIENTATION_CHANGE_EVENT = "screenOrientationChange";
|
|
14
16
|
|
|
15
17
|
private ScreenOrientation implementation;
|
|
@@ -29,8 +31,12 @@ public class ScreenOrientationPlugin extends Plugin {
|
|
|
29
31
|
@PluginMethod
|
|
30
32
|
public void lock(PluginCall call) {
|
|
31
33
|
String orientationType = call.getString("type");
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
try {
|
|
35
|
+
implementation.lock(orientationType);
|
|
36
|
+
call.resolve();
|
|
37
|
+
} catch (Exception exception) {
|
|
38
|
+
call.reject(exception.getMessage());
|
|
39
|
+
}
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
@PluginMethod
|
|
@@ -42,14 +48,14 @@ public class ScreenOrientationPlugin extends Plugin {
|
|
|
42
48
|
@PluginMethod
|
|
43
49
|
public void getCurrentOrientation(PluginCall call) {
|
|
44
50
|
JSObject ret = new JSObject();
|
|
45
|
-
String orientationType = implementation.
|
|
51
|
+
String orientationType = implementation.getCurrentOrientationTypeKey();
|
|
46
52
|
ret.put("type", orientationType);
|
|
47
53
|
call.resolve(ret);
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
private void updateOrientation() {
|
|
51
57
|
JSObject ret = new JSObject();
|
|
52
|
-
String orientationType = implementation.
|
|
58
|
+
String orientationType = implementation.getCurrentOrientationTypeKey();
|
|
53
59
|
ret.put("type", orientationType);
|
|
54
60
|
notifyListeners(SCREEN_ORIENTATION_CHANGE_EVENT, ret);
|
|
55
61
|
}
|
|
@@ -1,11 +1,42 @@
|
|
|
1
1
|
package io.capawesome.capacitorjs.plugins.screenorientation;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import android.content.pm.ActivityInfo;
|
|
4
|
+
import androidx.annotation.NonNull;
|
|
5
|
+
|
|
6
|
+
public enum ScreenOrientationType {
|
|
7
|
+
LANDSCAPE("landscape", ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE),
|
|
8
|
+
LANDSCAPE_PRIMARY("landscape-primary", ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE),
|
|
9
|
+
LANDSCAPE_SECONDARY("landscape-secondary", ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE),
|
|
10
|
+
PORTRAIT("portrait", ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT),
|
|
11
|
+
PORTRAIT_PRIMARY("portrait-primary", ActivityInfo.SCREEN_ORIENTATION_PORTRAIT),
|
|
12
|
+
PORTRAIT_SECONDARY("portrait-secondary", ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
|
|
13
|
+
|
|
14
|
+
private final String key;
|
|
15
|
+
private final int orientation;
|
|
16
|
+
|
|
17
|
+
ScreenOrientationType(String key, int orientation) {
|
|
18
|
+
this.key = key;
|
|
19
|
+
this.orientation = orientation;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public String key() {
|
|
23
|
+
return key;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public int orientation() {
|
|
27
|
+
return orientation;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@NonNull
|
|
31
|
+
public static ScreenOrientationType fromString(String s) throws Exception {
|
|
32
|
+
String k = s.toLowerCase();
|
|
33
|
+
for (ScreenOrientationType t : values()) {
|
|
34
|
+
if (t.key.equals(k)) return t;
|
|
35
|
+
}
|
|
36
|
+
throw new Exception(ScreenOrientationPlugin.ERROR_UNSUPPORTED_ORIENTATION_TYPE);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public static int toInt(@NonNull String type) throws Exception {
|
|
40
|
+
return fromString(type).orientation();
|
|
41
|
+
}
|
|
11
42
|
}
|
package/dist/docs.json
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
"methods": [
|
|
8
8
|
{
|
|
9
9
|
"name": "lock",
|
|
10
|
-
"signature": "(options
|
|
10
|
+
"signature": "(options?: LockOptions | undefined) => Promise<void>",
|
|
11
11
|
"parameters": [
|
|
12
12
|
{
|
|
13
13
|
"name": "options",
|
|
14
14
|
"docs": "",
|
|
15
|
-
"type": "LockOptions"
|
|
15
|
+
"type": "LockOptions | undefined"
|
|
16
16
|
}
|
|
17
17
|
],
|
|
18
18
|
"returns": "Promise<void>",
|
|
@@ -3,7 +3,7 @@ export interface ScreenOrientationPlugin {
|
|
|
3
3
|
/**
|
|
4
4
|
* Locks the device orientation.
|
|
5
5
|
*/
|
|
6
|
-
lock(options
|
|
6
|
+
lock(options?: LockOptions): Promise<void>;
|
|
7
7
|
/**
|
|
8
8
|
* Unlocks the device orientation.
|
|
9
9
|
*/
|
|
@@ -25,7 +25,7 @@ export interface LockOptions {
|
|
|
25
25
|
/**
|
|
26
26
|
* The orientation lock type.
|
|
27
27
|
*/
|
|
28
|
-
type
|
|
28
|
+
type?: OrientationType;
|
|
29
29
|
}
|
|
30
30
|
export interface GetCurrentOrientationResult {
|
|
31
31
|
/**
|
|
@@ -62,7 +62,7 @@ export declare enum OrientationType {
|
|
|
62
62
|
/**
|
|
63
63
|
* Callback to receive the screen orientation change notifications.
|
|
64
64
|
*/
|
|
65
|
-
export
|
|
65
|
+
export type ScreenOrientationChangeListener = (change: ScreenOrientationChange) => void;
|
|
66
66
|
export interface ScreenOrientationChange {
|
|
67
67
|
/**
|
|
68
68
|
* The current orientation type.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA0CA,MAAM,CAAN,IAAY,eAyBX;AAzBD,WAAY,eAAe;IACzB;;OAEG;IACH,0CAAuB,CAAA;IACvB;;OAEG;IACH,0DAAuC,CAAA;IACvC;;OAEG;IACH,8DAA2C,CAAA;IAC3C;;OAEG;IACH,wCAAqB,CAAA;IACrB;;OAEG;IACH,wDAAqC,CAAA;IACrC;;OAEG;IACH,4DAAyC,CAAA;AAC3C,CAAC,EAzBW,eAAe,KAAf,eAAe,QAyB1B","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface ScreenOrientationPlugin {\n /**\n * Locks the device orientation.\n */\n lock(options
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AA0CA,MAAM,CAAN,IAAY,eAyBX;AAzBD,WAAY,eAAe;IACzB;;OAEG;IACH,0CAAuB,CAAA;IACvB;;OAEG;IACH,0DAAuC,CAAA;IACvC;;OAEG;IACH,8DAA2C,CAAA;IAC3C;;OAEG;IACH,wCAAqB,CAAA;IACrB;;OAEG;IACH,wDAAqC,CAAA;IACrC;;OAEG;IACH,4DAAyC,CAAA;AAC3C,CAAC,EAzBW,eAAe,KAAf,eAAe,QAyB1B","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface ScreenOrientationPlugin {\n /**\n * Locks the device orientation.\n */\n lock(options?: LockOptions): Promise<void>;\n /**\n * Unlocks the device orientation.\n */\n unlock(): Promise<void>;\n /**\n * Gets the current device orientation type.\n */\n getCurrentOrientation(): Promise<GetCurrentOrientationResult>;\n /**\n * Listen for screen orientation changes.\n */\n addListener(\n eventName: 'screenOrientationChange',\n listenerFunc: ScreenOrientationChangeListener,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n */\n removeAllListeners(): Promise<void>;\n}\n\nexport interface LockOptions {\n /**\n * The orientation lock type.\n */\n type?: OrientationType;\n}\n\nexport interface GetCurrentOrientationResult {\n /**\n * The current orientation type.\n */\n type: OrientationType;\n}\n\nexport enum OrientationType {\n /**\n * The orientation is either landscape-primary or landscape-secondary.\n */\n LANDSCAPE = 'landscape',\n /**\n * The orientation is in the primary landscape mode.\n */\n LANDSCAPE_PRIMARY = 'landscape-primary',\n /**\n * The orientation is in the secondary landscape mode.\n */\n LANDSCAPE_SECONDARY = 'landscape-secondary',\n /**\n * The orientation is either portrait-primary or portrait-secondary.\n */\n PORTRAIT = 'portrait',\n /**\n * The orientation is in the primary portrait mode.\n */\n PORTRAIT_PRIMARY = 'portrait-primary',\n /**\n * The orientation is in the secondary portrait mode.\n */\n PORTRAIT_SECONDARY = 'portrait-secondary',\n}\n\n/**\n * Callback to receive the screen orientation change notifications.\n */\nexport type ScreenOrientationChangeListener = (\n change: ScreenOrientationChange,\n) => void;\n\nexport interface ScreenOrientationChange {\n /**\n * The current orientation type.\n */\n type: OrientationType;\n}\n"]}
|
package/dist/esm/web.js
CHANGED
|
@@ -3,7 +3,6 @@ import { OrientationType } from './definitions';
|
|
|
3
3
|
export class ScreenOrientationWeb extends WebPlugin {
|
|
4
4
|
constructor() {
|
|
5
5
|
super();
|
|
6
|
-
this.isSupported = 'orientation' in screen;
|
|
7
6
|
this.handleOrientationChange = async () => {
|
|
8
7
|
const result = await this.getCurrentOrientation();
|
|
9
8
|
const changeEvent = {
|
|
@@ -11,15 +10,23 @@ export class ScreenOrientationWeb extends WebPlugin {
|
|
|
11
10
|
};
|
|
12
11
|
this.notifyListeners('screenOrientationChange', changeEvent);
|
|
13
12
|
};
|
|
13
|
+
try {
|
|
14
|
+
this.isSupported = 'orientation' in screen;
|
|
15
|
+
}
|
|
16
|
+
catch (_a) {
|
|
17
|
+
this.isSupported = false;
|
|
18
|
+
}
|
|
14
19
|
if (this.isSupported) {
|
|
15
20
|
screen.orientation.addEventListener('change', this.handleOrientationChange);
|
|
16
21
|
}
|
|
17
22
|
}
|
|
18
23
|
async lock(options) {
|
|
24
|
+
var _a;
|
|
19
25
|
if (!this.isSupported) {
|
|
20
26
|
this.throwUnsupportedError();
|
|
21
27
|
}
|
|
22
|
-
|
|
28
|
+
const type = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : screen.orientation.type;
|
|
29
|
+
await screen.orientation.lock(type);
|
|
23
30
|
}
|
|
24
31
|
async unlock() {
|
|
25
32
|
if (!this.isSupported) {
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,MAAM,OAAO,oBACX,SAAQ,SAAS;IAKjB;QACE,KAAK,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQ5C,OAAO,E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AC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC/B,CAAC;QACD,QAAQ,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YAChC,KAAK,mBAAmB;gBACtB,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC,iBAAiB,EAAE,CAAC;YACrD,KAAK,qBAAqB;gBACxB,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC,mBAAmB,EAAE,CAAC;YACvD,KAAK,oBAAoB;gBACvB,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC,kBAAkB,EAAE,CAAC;YACtD;gBACE,OAAO,EAAE,IAAI,EAAE,eAAe,CAAC,gBAAgB,EAAE,CAAC;QACtD,CAAC;IACH,CAAC;IAUO,qBAAqB;QAC3B,MAAM,IAAI,CAAC,WAAW,CACpB,uDAAuD,CACxD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n GetCurrentOrientationResult,\n LockOptions,\n ScreenOrientationChange,\n ScreenOrientationPlugin,\n} from './definitions';\nimport { OrientationType } from './definitions';\n\nexport class ScreenOrientationWeb\n extends WebPlugin\n implements ScreenOrientationPlugin\n{\n private readonly isSupported: boolean;\n\n constructor() {\n super();\n try {\n this.isSupported = 'orientation' in screen;\n } catch {\n this.isSupported = false;\n }\n\n if (this.isSupported) {\n screen.orientation.addEventListener(\n 'change',\n this.handleOrientationChange,\n );\n }\n }\n\n public async lock(options: LockOptions): Promise<void> {\n if (!this.isSupported) {\n this.throwUnsupportedError();\n }\n const type = options?.type ?? screen.orientation.type;\n await screen.orientation.lock(type);\n }\n\n public async unlock(): Promise<void> {\n if (!this.isSupported) {\n this.throwUnsupportedError();\n }\n screen.orientation.unlock();\n }\n\n public async getCurrentOrientation(): Promise<GetCurrentOrientationResult> {\n if (!this.isSupported) {\n this.throwUnsupportedError();\n }\n switch (screen.orientation.type) {\n case 'landscape-primary':\n return { type: OrientationType.LANDSCAPE_PRIMARY };\n case 'landscape-secondary':\n return { type: OrientationType.LANDSCAPE_SECONDARY };\n case 'portrait-secondary':\n return { type: OrientationType.PORTRAIT_SECONDARY };\n default:\n return { type: OrientationType.PORTRAIT_PRIMARY };\n }\n }\n\n private handleOrientationChange = async () => {\n const result = await this.getCurrentOrientation();\n const changeEvent: ScreenOrientationChange = {\n type: result.type,\n };\n this.notifyListeners('screenOrientationChange', changeEvent);\n };\n\n private throwUnsupportedError(): never {\n throw this.unavailable(\n 'Screen Orientation API not available in this browser.',\n );\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -37,7 +37,6 @@ const ScreenOrientation = core.registerPlugin('ScreenOrientation', {
|
|
|
37
37
|
class ScreenOrientationWeb extends core.WebPlugin {
|
|
38
38
|
constructor() {
|
|
39
39
|
super();
|
|
40
|
-
this.isSupported = 'orientation' in screen;
|
|
41
40
|
this.handleOrientationChange = async () => {
|
|
42
41
|
const result = await this.getCurrentOrientation();
|
|
43
42
|
const changeEvent = {
|
|
@@ -45,15 +44,23 @@ class ScreenOrientationWeb extends core.WebPlugin {
|
|
|
45
44
|
};
|
|
46
45
|
this.notifyListeners('screenOrientationChange', changeEvent);
|
|
47
46
|
};
|
|
47
|
+
try {
|
|
48
|
+
this.isSupported = 'orientation' in screen;
|
|
49
|
+
}
|
|
50
|
+
catch (_a) {
|
|
51
|
+
this.isSupported = false;
|
|
52
|
+
}
|
|
48
53
|
if (this.isSupported) {
|
|
49
54
|
screen.orientation.addEventListener('change', this.handleOrientationChange);
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
async lock(options) {
|
|
58
|
+
var _a;
|
|
53
59
|
if (!this.isSupported) {
|
|
54
60
|
this.throwUnsupportedError();
|
|
55
61
|
}
|
|
56
|
-
|
|
62
|
+
const type = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : screen.orientation.type;
|
|
63
|
+
await screen.orientation.lock(type);
|
|
57
64
|
}
|
|
58
65
|
async unlock() {
|
|
59
66
|
if (!this.isSupported) {
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var OrientationType;\n(function (OrientationType) {\n /**\n * The orientation is either landscape-primary or landscape-secondary.\n */\n OrientationType[\"LANDSCAPE\"] = \"landscape\";\n /**\n * The orientation is in the primary landscape mode.\n */\n OrientationType[\"LANDSCAPE_PRIMARY\"] = \"landscape-primary\";\n /**\n * The orientation is in the secondary landscape mode.\n */\n OrientationType[\"LANDSCAPE_SECONDARY\"] = \"landscape-secondary\";\n /**\n * The orientation is either portrait-primary or portrait-secondary.\n */\n OrientationType[\"PORTRAIT\"] = \"portrait\";\n /**\n * The orientation is in the primary portrait mode.\n */\n OrientationType[\"PORTRAIT_PRIMARY\"] = \"portrait-primary\";\n /**\n * The orientation is in the secondary portrait mode.\n */\n OrientationType[\"PORTRAIT_SECONDARY\"] = \"portrait-secondary\";\n})(OrientationType || (OrientationType = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst ScreenOrientation = registerPlugin('ScreenOrientation', {\n web: () => import('./web').then(m => new m.ScreenOrientationWeb()),\n});\nexport * from './definitions';\nexport { ScreenOrientation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { OrientationType } from './definitions';\nexport class ScreenOrientationWeb extends WebPlugin {\n constructor() {\n super();\n this.
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var OrientationType;\n(function (OrientationType) {\n /**\n * The orientation is either landscape-primary or landscape-secondary.\n */\n OrientationType[\"LANDSCAPE\"] = \"landscape\";\n /**\n * The orientation is in the primary landscape mode.\n */\n OrientationType[\"LANDSCAPE_PRIMARY\"] = \"landscape-primary\";\n /**\n * The orientation is in the secondary landscape mode.\n */\n OrientationType[\"LANDSCAPE_SECONDARY\"] = \"landscape-secondary\";\n /**\n * The orientation is either portrait-primary or portrait-secondary.\n */\n OrientationType[\"PORTRAIT\"] = \"portrait\";\n /**\n * The orientation is in the primary portrait mode.\n */\n OrientationType[\"PORTRAIT_PRIMARY\"] = \"portrait-primary\";\n /**\n * The orientation is in the secondary portrait mode.\n */\n OrientationType[\"PORTRAIT_SECONDARY\"] = \"portrait-secondary\";\n})(OrientationType || (OrientationType = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst ScreenOrientation = registerPlugin('ScreenOrientation', {\n web: () => import('./web').then(m => new m.ScreenOrientationWeb()),\n});\nexport * from './definitions';\nexport { ScreenOrientation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { OrientationType } from './definitions';\nexport class ScreenOrientationWeb extends WebPlugin {\n constructor() {\n super();\n this.handleOrientationChange = async () => {\n const result = await this.getCurrentOrientation();\n const changeEvent = {\n type: result.type,\n };\n this.notifyListeners('screenOrientationChange', changeEvent);\n };\n try {\n this.isSupported = 'orientation' in screen;\n }\n catch (_a) {\n this.isSupported = false;\n }\n if (this.isSupported) {\n screen.orientation.addEventListener('change', this.handleOrientationChange);\n }\n }\n async lock(options) {\n var _a;\n if (!this.isSupported) {\n this.throwUnsupportedError();\n }\n const type = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : screen.orientation.type;\n await screen.orientation.lock(type);\n }\n async unlock() {\n if (!this.isSupported) {\n this.throwUnsupportedError();\n }\n screen.orientation.unlock();\n }\n async getCurrentOrientation() {\n if (!this.isSupported) {\n this.throwUnsupportedError();\n }\n switch (screen.orientation.type) {\n case 'landscape-primary':\n return { type: OrientationType.LANDSCAPE_PRIMARY };\n case 'landscape-secondary':\n return { type: OrientationType.LANDSCAPE_SECONDARY };\n case 'portrait-secondary':\n return { type: OrientationType.PORTRAIT_SECONDARY };\n default:\n return { type: OrientationType.PORTRAIT_PRIMARY };\n }\n }\n throwUnsupportedError() {\n throw this.unavailable('Screen Orientation API not available in this browser.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["OrientationType","registerPlugin","WebPlugin"],"mappings":";;;;AAAWA;AACX,CAAC,UAAU,eAAe,EAAE;AAC5B;AACA;AACA;AACA,IAAI,eAAe,CAAC,WAAW,CAAC,GAAG,WAAW;AAC9C;AACA;AACA;AACA,IAAI,eAAe,CAAC,mBAAmB,CAAC,GAAG,mBAAmB;AAC9D;AACA;AACA;AACA,IAAI,eAAe,CAAC,qBAAqB,CAAC,GAAG,qBAAqB;AAClE;AACA;AACA;AACA,IAAI,eAAe,CAAC,UAAU,CAAC,GAAG,UAAU;AAC5C;AACA;AACA;AACA,IAAI,eAAe,CAAC,kBAAkB,CAAC,GAAG,kBAAkB;AAC5D;AACA;AACA;AACA,IAAI,eAAe,CAAC,oBAAoB,CAAC,GAAG,oBAAoB;AAChE,CAAC,EAAEA,uBAAe,KAAKA,uBAAe,GAAG,EAAE,CAAC,CAAC;;ACzBxC,MAAC,iBAAiB,GAAGC,mBAAc,CAAC,mBAAmB,EAAE;AAC9D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,oBAAoB,EAAE,CAAC;AACtE,CAAC;;ACDM,MAAM,oBAAoB,SAASC,cAAS,CAAC;AACpD,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,EAAE;AACf,QAAQ,IAAI,CAAC,uBAAuB,GAAG,YAAY;AACnD,YAAY,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE;AAC7D,YAAY,MAAM,WAAW,GAAG;AAChC,gBAAgB,IAAI,EAAE,MAAM,CAAC,IAAI;AACjC,aAAa;AACb,YAAY,IAAI,CAAC,eAAe,CAAC,yBAAyB,EAAE,WAAW,CAAC;AACxE,QAAQ,CAAC;AACT,QAAQ,IAAI;AACZ,YAAY,IAAI,CAAC,WAAW,GAA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B;AACtC,gBAAgB,OAAO,EAAE,IAAI,EAAEA,uBAAe,CAAC,mBAAmB,EAAE;AACpE,YAAY,KAAK,oBAAoB;AACrC,gBAAgB,OAAO,EAAE,IAAI,EAAEA,uBAAe,CAAC,kBAAkB,EAAE;AACnE,YAAY;AACZ,gBAAgB,OAAO,EAAE,IAAI,EAAEA,uBAAe,CAAC,gBAAgB,EAAE;AACjE;AACA,IAAI;AACJ,IAAI,qBAAqB,GAAG;AAC5B,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,uDAAuD,CAAC;AACvF,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -36,7 +36,6 @@ var capacitorScreenOrientation = (function (exports, core) {
|
|
|
36
36
|
class ScreenOrientationWeb extends core.WebPlugin {
|
|
37
37
|
constructor() {
|
|
38
38
|
super();
|
|
39
|
-
this.isSupported = 'orientation' in screen;
|
|
40
39
|
this.handleOrientationChange = async () => {
|
|
41
40
|
const result = await this.getCurrentOrientation();
|
|
42
41
|
const changeEvent = {
|
|
@@ -44,15 +43,23 @@ var capacitorScreenOrientation = (function (exports, core) {
|
|
|
44
43
|
};
|
|
45
44
|
this.notifyListeners('screenOrientationChange', changeEvent);
|
|
46
45
|
};
|
|
46
|
+
try {
|
|
47
|
+
this.isSupported = 'orientation' in screen;
|
|
48
|
+
}
|
|
49
|
+
catch (_a) {
|
|
50
|
+
this.isSupported = false;
|
|
51
|
+
}
|
|
47
52
|
if (this.isSupported) {
|
|
48
53
|
screen.orientation.addEventListener('change', this.handleOrientationChange);
|
|
49
54
|
}
|
|
50
55
|
}
|
|
51
56
|
async lock(options) {
|
|
57
|
+
var _a;
|
|
52
58
|
if (!this.isSupported) {
|
|
53
59
|
this.throwUnsupportedError();
|
|
54
60
|
}
|
|
55
|
-
|
|
61
|
+
const type = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : screen.orientation.type;
|
|
62
|
+
await screen.orientation.lock(type);
|
|
56
63
|
}
|
|
57
64
|
async unlock() {
|
|
58
65
|
if (!this.isSupported) {
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var OrientationType;\n(function (OrientationType) {\n /**\n * The orientation is either landscape-primary or landscape-secondary.\n */\n OrientationType[\"LANDSCAPE\"] = \"landscape\";\n /**\n * The orientation is in the primary landscape mode.\n */\n OrientationType[\"LANDSCAPE_PRIMARY\"] = \"landscape-primary\";\n /**\n * The orientation is in the secondary landscape mode.\n */\n OrientationType[\"LANDSCAPE_SECONDARY\"] = \"landscape-secondary\";\n /**\n * The orientation is either portrait-primary or portrait-secondary.\n */\n OrientationType[\"PORTRAIT\"] = \"portrait\";\n /**\n * The orientation is in the primary portrait mode.\n */\n OrientationType[\"PORTRAIT_PRIMARY\"] = \"portrait-primary\";\n /**\n * The orientation is in the secondary portrait mode.\n */\n OrientationType[\"PORTRAIT_SECONDARY\"] = \"portrait-secondary\";\n})(OrientationType || (OrientationType = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst ScreenOrientation = registerPlugin('ScreenOrientation', {\n web: () => import('./web').then(m => new m.ScreenOrientationWeb()),\n});\nexport * from './definitions';\nexport { ScreenOrientation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { OrientationType } from './definitions';\nexport class ScreenOrientationWeb extends WebPlugin {\n constructor() {\n super();\n this.
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var OrientationType;\n(function (OrientationType) {\n /**\n * The orientation is either landscape-primary or landscape-secondary.\n */\n OrientationType[\"LANDSCAPE\"] = \"landscape\";\n /**\n * The orientation is in the primary landscape mode.\n */\n OrientationType[\"LANDSCAPE_PRIMARY\"] = \"landscape-primary\";\n /**\n * The orientation is in the secondary landscape mode.\n */\n OrientationType[\"LANDSCAPE_SECONDARY\"] = \"landscape-secondary\";\n /**\n * The orientation is either portrait-primary or portrait-secondary.\n */\n OrientationType[\"PORTRAIT\"] = \"portrait\";\n /**\n * The orientation is in the primary portrait mode.\n */\n OrientationType[\"PORTRAIT_PRIMARY\"] = \"portrait-primary\";\n /**\n * The orientation is in the secondary portrait mode.\n */\n OrientationType[\"PORTRAIT_SECONDARY\"] = \"portrait-secondary\";\n})(OrientationType || (OrientationType = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst ScreenOrientation = registerPlugin('ScreenOrientation', {\n web: () => import('./web').then(m => new m.ScreenOrientationWeb()),\n});\nexport * from './definitions';\nexport { ScreenOrientation };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { OrientationType } from './definitions';\nexport class ScreenOrientationWeb extends WebPlugin {\n constructor() {\n super();\n this.handleOrientationChange = async () => {\n const result = await this.getCurrentOrientation();\n const changeEvent = {\n type: result.type,\n };\n this.notifyListeners('screenOrientationChange', changeEvent);\n };\n try {\n this.isSupported = 'orientation' in screen;\n }\n catch (_a) {\n this.isSupported = false;\n }\n if (this.isSupported) {\n screen.orientation.addEventListener('change', this.handleOrientationChange);\n }\n }\n async lock(options) {\n var _a;\n if (!this.isSupported) {\n this.throwUnsupportedError();\n }\n const type = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : screen.orientation.type;\n await screen.orientation.lock(type);\n }\n async unlock() {\n if (!this.isSupported) {\n this.throwUnsupportedError();\n }\n screen.orientation.unlock();\n }\n async getCurrentOrientation() {\n if (!this.isSupported) {\n this.throwUnsupportedError();\n }\n switch (screen.orientation.type) {\n case 'landscape-primary':\n return { type: OrientationType.LANDSCAPE_PRIMARY };\n case 'landscape-secondary':\n return { type: OrientationType.LANDSCAPE_SECONDARY };\n case 'portrait-secondary':\n return { type: OrientationType.PORTRAIT_SECONDARY };\n default:\n return { type: OrientationType.PORTRAIT_PRIMARY };\n }\n }\n throwUnsupportedError() {\n throw this.unavailable('Screen Orientation API not available in this browser.');\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["OrientationType","registerPlugin","WebPlugin"],"mappings":";;;AAAWA;IACX,CAAC,UAAU,eAAe,EAAE;IAC5B;IACA;IACA;IACA,IAAI,eAAe,CAAC,WAAW,CAAC,GAAG,WAAW;IAC9C;IACA;IACA;IACA,IAAI,eAAe,CAAC,mBAAmB,CAAC,GAAG,mBAAmB;IAC9D;IACA;IACA;IACA,IAAI,eAAe,CAAC,qBAAqB,CAAC,GAAG,qBAAqB;IAClE;IACA;IACA;IACA,IAAI,eAAe,CAAC,UAAU,CAAC,GAAG,UAAU;IAC5C;IACA;IACA;IACA,IAAI,eAAe,CAAC,kBAAkB,CAAC,GAAG,kBAAkB;IAC5D;IACA;IACA;IACA,IAAI,eAAe,CAAC,oBAAoB,CAAC,GAAG,oBAAoB;IAChE,CAAC,EAAEA,uBAAe,KAAKA,uBAAe,GAAG,EAAE,CAAC,CAAC;;ACzBxC,UAAC,iBAAiB,GAAGC,mBAAc,CAAC,mBAAmB,EAAE;IAC9D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,oBAAoB,EAAE,CAAC;IACtE,CAAC;;ICDM,MAAM,oBAAoB,SAASC,cAAS,CAAC;IACpD,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,EAAE;IACf,QAAQ,IAAI,CAAC,uBAAuB,GAAG,YAAY;IACnD,YAAY,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE;IAC7D,YAAY,MAAM,WAAW,GAAG;IAChC,gBAAgB,IAAI,EAAE,MAAM,CAAC,IAAI;IACjC,aAAa;IACb,YAAY,IAAI,CAAC,eAAe,CAAC,yBAAyB,EAAE,WAAW,CAAC;IACxE,QAAQ,CAAC;IACT,QAAQ,IAAI;IACZ,YAAY,IAAI,CAAC,WAAW,GAAG,aAAa,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gBAAgB,OAAO,EAAE,IAAI,EAAEA,uBAAe,CAAC,mBAAmB,EAAE;IACpE,YAAY,KAAK,oBAAoB;IACrC,gBAAgB,OAAO,EAAE,IAAI,EAAEA,uBAAe,CAAC,kBAAkB,EAAE;IACnE,YAAY;IACZ,gBAAgB,OAAO,EAAE,IAAI,EAAEA,uBAAe,CAAC,gBAAgB,EAAE;IACjE;IACA,IAAI;IACJ,IAAI,qBAAqB,GAAG;IAC5B,QAAQ,MAAM,IAAI,CAAC,WAAW,CAAC,uDAAuD,CAAC;IACvF,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -18,20 +18,29 @@ import Capacitor
|
|
|
18
18
|
return ScreenOrientation.supportedInterfaceOrientations
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
@objc public func lock(_ orientationType: String
|
|
21
|
+
@objc public func lock(_ orientationType: String?, completion: @escaping () -> Void) {
|
|
22
22
|
DispatchQueue.main.async { [weak self] in
|
|
23
23
|
guard let strongSelf = self else {
|
|
24
24
|
return
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
let
|
|
29
|
-
|
|
26
|
+
var nextOrientationValue: Int
|
|
27
|
+
var nextOrientationMask: UIInterfaceOrientationMask
|
|
28
|
+
if let orientationType {
|
|
29
|
+
nextOrientationValue = strongSelf.convertOrientationTypeToValue(orientationType)
|
|
30
|
+
nextOrientationMask = strongSelf.convertOrientationTypeToMask(orientationType)
|
|
31
|
+
} else {
|
|
32
|
+
nextOrientationValue = UIDevice.current.orientation.rawValue
|
|
33
|
+
nextOrientationMask = strongSelf.convertOrientationValueToMask(nextOrientationValue)
|
|
34
|
+
}
|
|
30
35
|
strongSelf.requestGeometryUpdate(orientationValue: nextOrientationValue, orientationMask: nextOrientationMask)
|
|
31
36
|
ScreenOrientation.supportedInterfaceOrientations = nextOrientationMask
|
|
32
37
|
UINavigationController.attemptRotationToDeviceOrientation()
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
if let orientationType {
|
|
39
|
+
strongSelf.notifyOrientationChangeListeners(orientationType)
|
|
40
|
+
} else {
|
|
41
|
+
let convertedOrientationType = strongSelf.convertOrientationValueToType(nextOrientationValue)
|
|
42
|
+
strongSelf.notifyOrientationChangeListeners(convertedOrientationType)
|
|
43
|
+
}
|
|
35
44
|
completion()
|
|
36
45
|
}
|
|
37
46
|
}
|
|
@@ -26,7 +26,7 @@ public class ScreenOrientationPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
@objc func lock(_ call: CAPPluginCall) {
|
|
29
|
-
let orientationType = call.getString("type")
|
|
29
|
+
let orientationType = call.getString("type")
|
|
30
30
|
implementation?.lock(orientationType, completion: {
|
|
31
31
|
call.resolve()
|
|
32
32
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capawesome/capacitor-screen-orientation",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Capacitor plugin to lock/unlock the screen orientation.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -63,23 +63,23 @@
|
|
|
63
63
|
"prepublishOnly": "npm run build"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@capacitor/android": "
|
|
67
|
-
"@capacitor/cli": "
|
|
68
|
-
"@capacitor/core": "
|
|
69
|
-
"@capacitor/docgen": "0.3.
|
|
70
|
-
"@capacitor/ios": "
|
|
66
|
+
"@capacitor/android": "8.0.0",
|
|
67
|
+
"@capacitor/cli": "8.0.0",
|
|
68
|
+
"@capacitor/core": "8.0.0",
|
|
69
|
+
"@capacitor/docgen": "0.3.1",
|
|
70
|
+
"@capacitor/ios": "8.0.0",
|
|
71
71
|
"@ionic/eslint-config": "0.4.0",
|
|
72
72
|
"@ionic/swiftlint-config": "2.0.0",
|
|
73
73
|
"eslint": "8.57.0",
|
|
74
74
|
"prettier": "3.4.2",
|
|
75
75
|
"prettier-plugin-java": "2.6.7",
|
|
76
|
-
"rimraf": "6.
|
|
77
|
-
"rollup": "4.
|
|
76
|
+
"rimraf": "6.1.2",
|
|
77
|
+
"rollup": "4.53.3",
|
|
78
78
|
"swiftlint": "2.0.0",
|
|
79
|
-
"typescript": "
|
|
79
|
+
"typescript": "5.9.3"
|
|
80
80
|
},
|
|
81
81
|
"peerDependencies": {
|
|
82
|
-
"@capacitor/core": ">=
|
|
82
|
+
"@capacitor/core": ">=8.0.0"
|
|
83
83
|
},
|
|
84
84
|
"swiftlint": "@ionic/swiftlint-config",
|
|
85
85
|
"eslintConfig": {
|