@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,56 +1,56 @@
|
|
|
1
|
-
package io.capawesome.capacitorjs.plugins.screenorientation;
|
|
2
|
-
|
|
3
|
-
import android.content.res.Configuration;
|
|
4
|
-
import com.getcapacitor.JSObject;
|
|
5
|
-
import com.getcapacitor.Plugin;
|
|
6
|
-
import com.getcapacitor.PluginCall;
|
|
7
|
-
import com.getcapacitor.PluginMethod;
|
|
8
|
-
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
9
|
-
|
|
10
|
-
@CapacitorPlugin(name = "ScreenOrientation")
|
|
11
|
-
public class ScreenOrientationPlugin extends Plugin {
|
|
12
|
-
|
|
13
|
-
public static final String SCREEN_ORIENTATION_CHANGE_EVENT = "screenOrientationChange";
|
|
14
|
-
|
|
15
|
-
private ScreenOrientation implementation;
|
|
16
|
-
|
|
17
|
-
@Override
|
|
18
|
-
public void load() {
|
|
19
|
-
implementation = new ScreenOrientation(getBridge());
|
|
20
|
-
implementation.setOrientationChangeListener(this::updateOrientation);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
@Override
|
|
24
|
-
public void handleOnConfigurationChanged(Configuration newConfig) {
|
|
25
|
-
super.handleOnConfigurationChanged(newConfig);
|
|
26
|
-
implementation.handleOnConfigurationChanged(newConfig);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
@PluginMethod
|
|
30
|
-
public void lock(PluginCall call) {
|
|
31
|
-
String orientationType = call.getString("type");
|
|
32
|
-
implementation.lock(orientationType);
|
|
33
|
-
call.resolve();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
@PluginMethod
|
|
37
|
-
public void unlock(PluginCall call) {
|
|
38
|
-
implementation.unlock();
|
|
39
|
-
call.resolve();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
@PluginMethod
|
|
43
|
-
public void getCurrentOrientation(PluginCall call) {
|
|
44
|
-
JSObject ret = new JSObject();
|
|
45
|
-
String orientationType = implementation.getCurrentOrientationType();
|
|
46
|
-
ret.put("type", orientationType);
|
|
47
|
-
call.resolve(ret);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
private void updateOrientation() {
|
|
51
|
-
JSObject ret = new JSObject();
|
|
52
|
-
String orientationType = implementation.getCurrentOrientationType();
|
|
53
|
-
ret.put("type", orientationType);
|
|
54
|
-
notifyListeners(SCREEN_ORIENTATION_CHANGE_EVENT, ret);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.screenorientation;
|
|
2
|
+
|
|
3
|
+
import android.content.res.Configuration;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import com.getcapacitor.Plugin;
|
|
6
|
+
import com.getcapacitor.PluginCall;
|
|
7
|
+
import com.getcapacitor.PluginMethod;
|
|
8
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
9
|
+
|
|
10
|
+
@CapacitorPlugin(name = "ScreenOrientation")
|
|
11
|
+
public class ScreenOrientationPlugin extends Plugin {
|
|
12
|
+
|
|
13
|
+
public static final String SCREEN_ORIENTATION_CHANGE_EVENT = "screenOrientationChange";
|
|
14
|
+
|
|
15
|
+
private ScreenOrientation implementation;
|
|
16
|
+
|
|
17
|
+
@Override
|
|
18
|
+
public void load() {
|
|
19
|
+
implementation = new ScreenOrientation(getBridge());
|
|
20
|
+
implementation.setOrientationChangeListener(this::updateOrientation);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Override
|
|
24
|
+
public void handleOnConfigurationChanged(Configuration newConfig) {
|
|
25
|
+
super.handleOnConfigurationChanged(newConfig);
|
|
26
|
+
implementation.handleOnConfigurationChanged(newConfig);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@PluginMethod
|
|
30
|
+
public void lock(PluginCall call) {
|
|
31
|
+
String orientationType = call.getString("type");
|
|
32
|
+
implementation.lock(orientationType);
|
|
33
|
+
call.resolve();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@PluginMethod
|
|
37
|
+
public void unlock(PluginCall call) {
|
|
38
|
+
implementation.unlock();
|
|
39
|
+
call.resolve();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@PluginMethod
|
|
43
|
+
public void getCurrentOrientation(PluginCall call) {
|
|
44
|
+
JSObject ret = new JSObject();
|
|
45
|
+
String orientationType = implementation.getCurrentOrientationType();
|
|
46
|
+
ret.put("type", orientationType);
|
|
47
|
+
call.resolve(ret);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private void updateOrientation() {
|
|
51
|
+
JSObject ret = new JSObject();
|
|
52
|
+
String orientationType = implementation.getCurrentOrientationType();
|
|
53
|
+
ret.put("type", orientationType);
|
|
54
|
+
notifyListeners(SCREEN_ORIENTATION_CHANGE_EVENT, ret);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
package io.capawesome.capacitorjs.plugins.screenorientation;
|
|
2
|
-
|
|
3
|
-
public class ScreenOrientationType {
|
|
4
|
-
|
|
5
|
-
public static final String LANDSCAPE = "landscape";
|
|
6
|
-
public static final String LANDSCAPE_PRIMARY = "landscape-primary";
|
|
7
|
-
public static final String LANDSCAPE_SECONDARY = "landscape-secondary";
|
|
8
|
-
public static final String PORTRAIT = "portrait";
|
|
9
|
-
public static final String PORTRAIT_PRIMARY = "portrait-primary";
|
|
10
|
-
public static final String PORTRAIT_SECONDARY = "portrait-secondary";
|
|
11
|
-
}
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.screenorientation;
|
|
2
|
+
|
|
3
|
+
public class ScreenOrientationType {
|
|
4
|
+
|
|
5
|
+
public static final String LANDSCAPE = "landscape";
|
|
6
|
+
public static final String LANDSCAPE_PRIMARY = "landscape-primary";
|
|
7
|
+
public static final String LANDSCAPE_SECONDARY = "landscape-secondary";
|
|
8
|
+
public static final String PORTRAIT = "portrait";
|
|
9
|
+
public static final String PORTRAIT_PRIMARY = "portrait-primary";
|
|
10
|
+
public static final String PORTRAIT_SECONDARY = "portrait-secondary";
|
|
11
|
+
}
|
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
-
export interface ScreenOrientationPlugin {
|
|
3
|
-
/**
|
|
4
|
-
* Locks the device orientation.
|
|
5
|
-
*/
|
|
6
|
-
lock(options: LockOptions): Promise<void>;
|
|
7
|
-
/**
|
|
8
|
-
* Unlocks the device orientation.
|
|
9
|
-
*/
|
|
10
|
-
unlock(): Promise<void>;
|
|
11
|
-
/**
|
|
12
|
-
* Gets the current device orientation type.
|
|
13
|
-
*/
|
|
14
|
-
getCurrentOrientation(): Promise<GetCurrentOrientationResult>;
|
|
15
|
-
/**
|
|
16
|
-
* Listen for screen orientation changes.
|
|
17
|
-
*/
|
|
18
|
-
addListener(eventName: 'screenOrientationChange', listenerFunc: ScreenOrientationChangeListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
19
|
-
/**
|
|
20
|
-
* Remove all listeners for this plugin.
|
|
21
|
-
*/
|
|
22
|
-
removeAllListeners(): Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
export interface LockOptions {
|
|
25
|
-
/**
|
|
26
|
-
* The orientation lock type.
|
|
27
|
-
*/
|
|
28
|
-
type: OrientationType;
|
|
29
|
-
}
|
|
30
|
-
export interface GetCurrentOrientationResult {
|
|
31
|
-
/**
|
|
32
|
-
* The current orientation type.
|
|
33
|
-
*/
|
|
34
|
-
type: OrientationType;
|
|
35
|
-
}
|
|
36
|
-
export declare enum OrientationType {
|
|
37
|
-
/**
|
|
38
|
-
* The orientation is either landscape-primary or landscape-secondary.
|
|
39
|
-
*/
|
|
40
|
-
LANDSCAPE = "landscape",
|
|
41
|
-
/**
|
|
42
|
-
* The orientation is in the primary landscape mode.
|
|
43
|
-
*/
|
|
44
|
-
LANDSCAPE_PRIMARY = "landscape-primary",
|
|
45
|
-
/**
|
|
46
|
-
* The orientation is in the secondary landscape mode.
|
|
47
|
-
*/
|
|
48
|
-
LANDSCAPE_SECONDARY = "landscape-secondary",
|
|
49
|
-
/**
|
|
50
|
-
* The orientation is either portrait-primary or portrait-secondary.
|
|
51
|
-
*/
|
|
52
|
-
PORTRAIT = "portrait",
|
|
53
|
-
/**
|
|
54
|
-
* The orientation is in the primary portrait mode.
|
|
55
|
-
*/
|
|
56
|
-
PORTRAIT_PRIMARY = "portrait-primary",
|
|
57
|
-
/**
|
|
58
|
-
* The orientation is in the secondary portrait mode.
|
|
59
|
-
*/
|
|
60
|
-
PORTRAIT_SECONDARY = "portrait-secondary"
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Callback to receive the screen orientation change notifications.
|
|
64
|
-
*/
|
|
65
|
-
export declare type ScreenOrientationChangeListener = (change: ScreenOrientationChange) => void;
|
|
66
|
-
export interface ScreenOrientationChange {
|
|
67
|
-
/**
|
|
68
|
-
* The current orientation type.
|
|
69
|
-
*/
|
|
70
|
-
type: OrientationType;
|
|
71
|
-
}
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
export interface ScreenOrientationPlugin {
|
|
3
|
+
/**
|
|
4
|
+
* Locks the device orientation.
|
|
5
|
+
*/
|
|
6
|
+
lock(options: LockOptions): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Unlocks the device orientation.
|
|
9
|
+
*/
|
|
10
|
+
unlock(): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Gets the current device orientation type.
|
|
13
|
+
*/
|
|
14
|
+
getCurrentOrientation(): Promise<GetCurrentOrientationResult>;
|
|
15
|
+
/**
|
|
16
|
+
* Listen for screen orientation changes.
|
|
17
|
+
*/
|
|
18
|
+
addListener(eventName: 'screenOrientationChange', listenerFunc: ScreenOrientationChangeListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
|
19
|
+
/**
|
|
20
|
+
* Remove all listeners for this plugin.
|
|
21
|
+
*/
|
|
22
|
+
removeAllListeners(): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export interface LockOptions {
|
|
25
|
+
/**
|
|
26
|
+
* The orientation lock type.
|
|
27
|
+
*/
|
|
28
|
+
type: OrientationType;
|
|
29
|
+
}
|
|
30
|
+
export interface GetCurrentOrientationResult {
|
|
31
|
+
/**
|
|
32
|
+
* The current orientation type.
|
|
33
|
+
*/
|
|
34
|
+
type: OrientationType;
|
|
35
|
+
}
|
|
36
|
+
export declare enum OrientationType {
|
|
37
|
+
/**
|
|
38
|
+
* The orientation is either landscape-primary or landscape-secondary.
|
|
39
|
+
*/
|
|
40
|
+
LANDSCAPE = "landscape",
|
|
41
|
+
/**
|
|
42
|
+
* The orientation is in the primary landscape mode.
|
|
43
|
+
*/
|
|
44
|
+
LANDSCAPE_PRIMARY = "landscape-primary",
|
|
45
|
+
/**
|
|
46
|
+
* The orientation is in the secondary landscape mode.
|
|
47
|
+
*/
|
|
48
|
+
LANDSCAPE_SECONDARY = "landscape-secondary",
|
|
49
|
+
/**
|
|
50
|
+
* The orientation is either portrait-primary or portrait-secondary.
|
|
51
|
+
*/
|
|
52
|
+
PORTRAIT = "portrait",
|
|
53
|
+
/**
|
|
54
|
+
* The orientation is in the primary portrait mode.
|
|
55
|
+
*/
|
|
56
|
+
PORTRAIT_PRIMARY = "portrait-primary",
|
|
57
|
+
/**
|
|
58
|
+
* The orientation is in the secondary portrait mode.
|
|
59
|
+
*/
|
|
60
|
+
PORTRAIT_SECONDARY = "portrait-secondary"
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Callback to receive the screen orientation change notifications.
|
|
64
|
+
*/
|
|
65
|
+
export declare type ScreenOrientationChangeListener = (change: ScreenOrientationChange) => void;
|
|
66
|
+
export interface ScreenOrientationChange {
|
|
67
|
+
/**
|
|
68
|
+
* The current orientation type.
|
|
69
|
+
*/
|
|
70
|
+
type: OrientationType;
|
|
71
|
+
}
|
package/dist/esm/definitions.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
export var OrientationType;
|
|
2
|
-
(function (OrientationType) {
|
|
3
|
-
/**
|
|
4
|
-
* The orientation is either landscape-primary or landscape-secondary.
|
|
5
|
-
*/
|
|
6
|
-
OrientationType["LANDSCAPE"] = "landscape";
|
|
7
|
-
/**
|
|
8
|
-
* The orientation is in the primary landscape mode.
|
|
9
|
-
*/
|
|
10
|
-
OrientationType["LANDSCAPE_PRIMARY"] = "landscape-primary";
|
|
11
|
-
/**
|
|
12
|
-
* The orientation is in the secondary landscape mode.
|
|
13
|
-
*/
|
|
14
|
-
OrientationType["LANDSCAPE_SECONDARY"] = "landscape-secondary";
|
|
15
|
-
/**
|
|
16
|
-
* The orientation is either portrait-primary or portrait-secondary.
|
|
17
|
-
*/
|
|
18
|
-
OrientationType["PORTRAIT"] = "portrait";
|
|
19
|
-
/**
|
|
20
|
-
* The orientation is in the primary portrait mode.
|
|
21
|
-
*/
|
|
22
|
-
OrientationType["PORTRAIT_PRIMARY"] = "portrait-primary";
|
|
23
|
-
/**
|
|
24
|
-
* The orientation is in the secondary portrait mode.
|
|
25
|
-
*/
|
|
26
|
-
OrientationType["PORTRAIT_SECONDARY"] = "portrait-secondary";
|
|
27
|
-
})(OrientationType || (OrientationType = {}));
|
|
1
|
+
export var OrientationType;
|
|
2
|
+
(function (OrientationType) {
|
|
3
|
+
/**
|
|
4
|
+
* The orientation is either landscape-primary or landscape-secondary.
|
|
5
|
+
*/
|
|
6
|
+
OrientationType["LANDSCAPE"] = "landscape";
|
|
7
|
+
/**
|
|
8
|
+
* The orientation is in the primary landscape mode.
|
|
9
|
+
*/
|
|
10
|
+
OrientationType["LANDSCAPE_PRIMARY"] = "landscape-primary";
|
|
11
|
+
/**
|
|
12
|
+
* The orientation is in the secondary landscape mode.
|
|
13
|
+
*/
|
|
14
|
+
OrientationType["LANDSCAPE_SECONDARY"] = "landscape-secondary";
|
|
15
|
+
/**
|
|
16
|
+
* The orientation is either portrait-primary or portrait-secondary.
|
|
17
|
+
*/
|
|
18
|
+
OrientationType["PORTRAIT"] = "portrait";
|
|
19
|
+
/**
|
|
20
|
+
* The orientation is in the primary portrait mode.
|
|
21
|
+
*/
|
|
22
|
+
OrientationType["PORTRAIT_PRIMARY"] = "portrait-primary";
|
|
23
|
+
/**
|
|
24
|
+
* The orientation is in the secondary portrait mode.
|
|
25
|
+
*/
|
|
26
|
+
OrientationType["PORTRAIT_SECONDARY"] = "portrait-secondary";
|
|
27
|
+
})(OrientationType || (OrientationType = {}));
|
|
28
28
|
//# sourceMappingURL=definitions.js.map
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ScreenOrientationPlugin } from './definitions';
|
|
2
|
-
declare const ScreenOrientation: ScreenOrientationPlugin;
|
|
3
|
-
export * from './definitions';
|
|
4
|
-
export { ScreenOrientation };
|
|
1
|
+
import type { ScreenOrientationPlugin } from './definitions';
|
|
2
|
+
declare const ScreenOrientation: ScreenOrientationPlugin;
|
|
3
|
+
export * from './definitions';
|
|
4
|
+
export { ScreenOrientation };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { registerPlugin } from '@capacitor/core';
|
|
2
|
-
const ScreenOrientation = registerPlugin('ScreenOrientation', {
|
|
3
|
-
web: () => import('./web').then(m => new m.ScreenOrientationWeb()),
|
|
4
|
-
});
|
|
5
|
-
export * from './definitions';
|
|
6
|
-
export { ScreenOrientation };
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
const ScreenOrientation = registerPlugin('ScreenOrientation', {
|
|
3
|
+
web: () => import('./web').then(m => new m.ScreenOrientationWeb()),
|
|
4
|
+
});
|
|
5
|
+
export * from './definitions';
|
|
6
|
+
export { ScreenOrientation };
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { GetCurrentOrientationResult, LockOptions, ScreenOrientationPlugin } from './definitions';
|
|
3
|
-
export declare class ScreenOrientationWeb extends WebPlugin implements ScreenOrientationPlugin {
|
|
4
|
-
private readonly isSupported;
|
|
5
|
-
constructor();
|
|
6
|
-
lock(options: LockOptions): Promise<void>;
|
|
7
|
-
unlock(): Promise<void>;
|
|
8
|
-
getCurrentOrientation(): Promise<GetCurrentOrientationResult>;
|
|
9
|
-
private handleOrientationChange;
|
|
10
|
-
private throwUnsupportedError;
|
|
11
|
-
}
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { GetCurrentOrientationResult, LockOptions, ScreenOrientationPlugin } from './definitions';
|
|
3
|
+
export declare class ScreenOrientationWeb extends WebPlugin implements ScreenOrientationPlugin {
|
|
4
|
+
private readonly isSupported;
|
|
5
|
+
constructor();
|
|
6
|
+
lock(options: LockOptions): Promise<void>;
|
|
7
|
+
unlock(): Promise<void>;
|
|
8
|
+
getCurrentOrientation(): Promise<GetCurrentOrientationResult>;
|
|
9
|
+
private handleOrientationChange;
|
|
10
|
+
private throwUnsupportedError;
|
|
11
|
+
}
|
package/dist/esm/web.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import { OrientationType } from './definitions';
|
|
3
|
-
export class ScreenOrientationWeb extends WebPlugin {
|
|
4
|
-
constructor() {
|
|
5
|
-
super();
|
|
6
|
-
this.isSupported = 'orientation' in screen;
|
|
7
|
-
this.handleOrientationChange = async () => {
|
|
8
|
-
const result = await this.getCurrentOrientation();
|
|
9
|
-
const changeEvent = {
|
|
10
|
-
type: result.type,
|
|
11
|
-
};
|
|
12
|
-
this.notifyListeners('screenOrientationChange', changeEvent);
|
|
13
|
-
};
|
|
14
|
-
if (this.isSupported) {
|
|
15
|
-
screen.orientation.addEventListener('change', this.handleOrientationChange);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
async lock(options) {
|
|
19
|
-
if (!this.isSupported) {
|
|
20
|
-
this.throwUnsupportedError();
|
|
21
|
-
}
|
|
22
|
-
await screen.orientation.lock(options.type);
|
|
23
|
-
}
|
|
24
|
-
async unlock() {
|
|
25
|
-
if (!this.isSupported) {
|
|
26
|
-
this.throwUnsupportedError();
|
|
27
|
-
}
|
|
28
|
-
screen.orientation.unlock();
|
|
29
|
-
}
|
|
30
|
-
async getCurrentOrientation() {
|
|
31
|
-
if (!this.isSupported) {
|
|
32
|
-
this.throwUnsupportedError();
|
|
33
|
-
}
|
|
34
|
-
switch (screen.orientation.type) {
|
|
35
|
-
case 'landscape-primary':
|
|
36
|
-
return { type: OrientationType.LANDSCAPE_PRIMARY };
|
|
37
|
-
case 'landscape-secondary':
|
|
38
|
-
return { type: OrientationType.LANDSCAPE_SECONDARY };
|
|
39
|
-
case 'portrait-secondary':
|
|
40
|
-
return { type: OrientationType.PORTRAIT_SECONDARY };
|
|
41
|
-
default:
|
|
42
|
-
return { type: OrientationType.PORTRAIT_PRIMARY };
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
throwUnsupportedError() {
|
|
46
|
-
throw this.unavailable('Screen Orientation API not available in this browser.');
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import { OrientationType } from './definitions';
|
|
3
|
+
export class ScreenOrientationWeb extends WebPlugin {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.isSupported = 'orientation' in screen;
|
|
7
|
+
this.handleOrientationChange = async () => {
|
|
8
|
+
const result = await this.getCurrentOrientation();
|
|
9
|
+
const changeEvent = {
|
|
10
|
+
type: result.type,
|
|
11
|
+
};
|
|
12
|
+
this.notifyListeners('screenOrientationChange', changeEvent);
|
|
13
|
+
};
|
|
14
|
+
if (this.isSupported) {
|
|
15
|
+
screen.orientation.addEventListener('change', this.handleOrientationChange);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async lock(options) {
|
|
19
|
+
if (!this.isSupported) {
|
|
20
|
+
this.throwUnsupportedError();
|
|
21
|
+
}
|
|
22
|
+
await screen.orientation.lock(options.type);
|
|
23
|
+
}
|
|
24
|
+
async unlock() {
|
|
25
|
+
if (!this.isSupported) {
|
|
26
|
+
this.throwUnsupportedError();
|
|
27
|
+
}
|
|
28
|
+
screen.orientation.unlock();
|
|
29
|
+
}
|
|
30
|
+
async getCurrentOrientation() {
|
|
31
|
+
if (!this.isSupported) {
|
|
32
|
+
this.throwUnsupportedError();
|
|
33
|
+
}
|
|
34
|
+
switch (screen.orientation.type) {
|
|
35
|
+
case 'landscape-primary':
|
|
36
|
+
return { type: OrientationType.LANDSCAPE_PRIMARY };
|
|
37
|
+
case 'landscape-secondary':
|
|
38
|
+
return { type: OrientationType.LANDSCAPE_SECONDARY };
|
|
39
|
+
case 'portrait-secondary':
|
|
40
|
+
return { type: OrientationType.PORTRAIT_SECONDARY };
|
|
41
|
+
default:
|
|
42
|
+
return { type: OrientationType.PORTRAIT_PRIMARY };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throwUnsupportedError() {
|
|
46
|
+
throw this.unavailable('Screen Orientation API not available in this browser.');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
49
|
//# sourceMappingURL=web.js.map
|
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;QAHO,gBAAW,GAAG,aAAa,IAAI,MAAM,CAAC;QA0C/C,4BAAuB,GAAG,KAAK,IAAI,EAAE;YAC3C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAClD,MAAM,WAAW,GAA4B;gBAC3C,IAAI,EAAE,MAAM,CAAC,IAAI;aAClB,CAAC;YACF,IAAI,CAAC,eAAe,CAAC,yBAAyB,EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC,CAAC;QA5CA,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,MAAM,CAAC,WAAW,CAAC,gBAAgB,CACjC,QAAQ,EACR,IAAI,CAAC,uBAAuB,CAC7B,CAAC;SACH;IACH,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,OAAoB;QACpC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,IAAI,CAAC,qBAAqB,EAAE,CAAC;SAC9B;QACD,MAAM,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,MAAM;QACjB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,IAAI,CAAC,qBAAqB,EAAE,CAAC;SAC9B;QACD,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAEM,KAAK,CAAC,qBAAqB;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,IAAI,CAAC,qBAAqB,EAAE,CAAC;SAC9B;QACD,QAAQ,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE;YAC/B,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;SACrD;IACH,CAAC;IAUO,qBAAqB;QAC3B,MAAM,IAAI,CAAC,WAAW,CACpB,uDAAuD,CACxD,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\
|
|
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;QAHO,gBAAW,GAAG,aAAa,IAAI,MAAM,CAAC;QA0C/C,4BAAuB,GAAG,KAAK,IAAI,EAAE;YAC3C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,qBAAqB,EAAE,CAAC;YAClD,MAAM,WAAW,GAA4B;gBAC3C,IAAI,EAAE,MAAM,CAAC,IAAI;aAClB,CAAC;YACF,IAAI,CAAC,eAAe,CAAC,yBAAyB,EAAE,WAAW,CAAC,CAAC;QAC/D,CAAC,CAAC;QA5CA,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,MAAM,CAAC,WAAW,CAAC,gBAAgB,CACjC,QAAQ,EACR,IAAI,CAAC,uBAAuB,CAC7B,CAAC;SACH;IACH,CAAC;IAEM,KAAK,CAAC,IAAI,CAAC,OAAoB;QACpC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,IAAI,CAAC,qBAAqB,EAAE,CAAC;SAC9B;QACD,MAAM,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,MAAM;QACjB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,IAAI,CAAC,qBAAqB,EAAE,CAAC;SAC9B;QACD,MAAM,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAEM,KAAK,CAAC,qBAAqB;QAChC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YACrB,IAAI,CAAC,qBAAqB,EAAE,CAAC;SAC9B;QACD,QAAQ,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE;YAC/B,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;SACrD;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 = 'orientation' in screen;\n\n constructor() {\n super();\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 await screen.orientation.lock(options.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"]}
|