@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.
@@ -0,0 +1,17 @@
1
+ require 'json'
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = 'CapawesomeCapacitorScreenOrientation'
7
+ s.version = package['version']
8
+ s.summary = package['description']
9
+ s.license = package['license']
10
+ s.homepage = package['repository']['url']
11
+ s.author = package['author']
12
+ s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
+ s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
14
+ s.ios.deployment_target = '12.0'
15
+ s.dependency 'Capacitor'
16
+ s.swift_version = '5.1'
17
+ end
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Robin Genz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,232 @@
1
+ <p align="center"><br><img src="https://user-images.githubusercontent.com/236501/85893648-1c92e880-b7a8-11ea-926d-95355b8175c7.png" width="128" height="128" /></p>
2
+ <h3 align="center">Screen Orientation</h3>
3
+ <p align="center"><strong><code>@capawesome/capacitor-screen-orientation</code></strong></p>
4
+ <p align="center">
5
+ Capacitor plugin to lock/unlock the screen orientation.
6
+ </p>
7
+
8
+ <p align="center">
9
+ <img src="https://img.shields.io/maintenance/yes/2022?style=flat-square" />
10
+ <a href="https://github.com/capawesome-team/capacitor-screen-orientation/actions?query=workflow%3A%22CI%22"><img src="https://img.shields.io/github/workflow/status/capawesome-team/capacitor-screen-orientation/CI/main?style=flat-square" /></a>
11
+ <a href="https://www.npmjs.com/package/@capawesome/capacitor-screen-orientation"><img src="https://img.shields.io/npm/l/@capawesome/capacitor-screen-orientation?style=flat-square" /></a>
12
+ <br>
13
+ <a href="https://www.npmjs.com/package/@capawesome/capacitor-screen-orientation"><img src="https://img.shields.io/npm/dw/@capawesome/capacitor-screen-orientation?style=flat-square" /></a>
14
+ <a href="https://www.npmjs.com/package/@capawesome/capacitor-screen-orientation"><img src="https://img.shields.io/npm/v/@capawesome/capacitor-screen-orientation?style=flat-square" /></a>
15
+ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
16
+ <a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-1-orange?style=flat-square" /></a>
17
+ <!-- ALL-CONTRIBUTORS-BADGE:END -->
18
+ </p>
19
+
20
+ ## Maintainers
21
+
22
+ | Maintainer | GitHub | Social |
23
+ | ---------- | ----------------------------------------- | --------------------------------------------- |
24
+ | Robin Genz | [robingenz](https://github.com/robingenz) | [@robin_genz](https://twitter.com/robin_genz) |
25
+
26
+ ## Sponsors
27
+
28
+ This is an MIT-licensed open source project.
29
+ It can grow thanks to the support by these awesome people.
30
+ If you'd like to join them, please read more [here](https://github.com/sponsors/capawesome-team).
31
+
32
+ <!-- sponsors --><!-- sponsors -->
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ npm install @capawesome/capacitor-screen-orientation
38
+ npx cap sync
39
+ ```
40
+
41
+ ### iOS
42
+
43
+ On iOS you must add the following to your app's `AppDelegate.swift`:
44
+
45
+ ```diff
46
+ + import CapawesomeCapacitorScreenOrientation
47
+
48
+ @UIApplicationMain
49
+ class AppDelegate: UIResponder, UIApplicationDelegate {
50
+
51
+ + func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
52
+ + return ScreenOrientation.getSupportedInterfaceOrientations()
53
+ + }
54
+ ```
55
+
56
+ ## Configuration
57
+
58
+ No configuration required for this plugin.
59
+
60
+ ## Demo
61
+
62
+ A working example can be found here: [robingenz/capacitor-plugin-demo](https://github.com/robingenz/capacitor-plugin-demo)
63
+
64
+ ## Usage
65
+
66
+ ```typescript
67
+ import { ScreenOrientation, OrientationType } from '@capawesome/capacitor-screen-orientation';
68
+
69
+ const lock = async () => {
70
+ await ScreenOrientation.lock({ type: OrientationType.LANDSCAPE });
71
+ };
72
+
73
+ const unlock = async () => {
74
+ await ScreenOrientation.unlock();
75
+ };
76
+
77
+ const getCurrentOrientation = async () => {
78
+ const result = await ScreenOrientation.getCurrentOrientation();
79
+ return result.type;
80
+ };
81
+ ```
82
+
83
+ ## API
84
+
85
+ <docgen-index>
86
+
87
+ * [`lock(...)`](#lock)
88
+ * [`unlock()`](#unlock)
89
+ * [`getCurrentOrientation()`](#getcurrentorientation)
90
+ * [`addListener('screenOrientationChange', ...)`](#addlistenerscreenorientationchange)
91
+ * [`removeAllListeners()`](#removealllisteners)
92
+ * [Interfaces](#interfaces)
93
+ * [Type Aliases](#type-aliases)
94
+ * [Enums](#enums)
95
+
96
+ </docgen-index>
97
+
98
+ <docgen-api>
99
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
100
+
101
+ ### lock(...)
102
+
103
+ ```typescript
104
+ lock(options: LockOptions) => Promise<void>
105
+ ```
106
+
107
+ Locks the device orientation.
108
+
109
+ | Param | Type |
110
+ | ------------- | --------------------------------------------------- |
111
+ | **`options`** | <code><a href="#lockoptions">LockOptions</a></code> |
112
+
113
+ --------------------
114
+
115
+
116
+ ### unlock()
117
+
118
+ ```typescript
119
+ unlock() => Promise<void>
120
+ ```
121
+
122
+ Unlocks the device orientation.
123
+
124
+ --------------------
125
+
126
+
127
+ ### getCurrentOrientation()
128
+
129
+ ```typescript
130
+ getCurrentOrientation() => Promise<GetCurrentOrientationResult>
131
+ ```
132
+
133
+ Gets the current device orientation type.
134
+
135
+ **Returns:** <code>Promise&lt;<a href="#getcurrentorientationresult">GetCurrentOrientationResult</a>&gt;</code>
136
+
137
+ --------------------
138
+
139
+
140
+ ### addListener('screenOrientationChange', ...)
141
+
142
+ ```typescript
143
+ addListener(eventName: 'screenOrientationChange', listenerFunc: ScreenOrientationChangeListener) => Promise<PluginListenerHandle> & PluginListenerHandle
144
+ ```
145
+
146
+ Listen for screen orientation changes.
147
+
148
+ | Param | Type |
149
+ | ------------------ | ------------------------------------------------------------------------------------------- |
150
+ | **`eventName`** | <code>'screenOrientationChange'</code> |
151
+ | **`listenerFunc`** | <code><a href="#screenorientationchangelistener">ScreenOrientationChangeListener</a></code> |
152
+
153
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
154
+
155
+ --------------------
156
+
157
+
158
+ ### removeAllListeners()
159
+
160
+ ```typescript
161
+ removeAllListeners() => Promise<void>
162
+ ```
163
+
164
+ Remove all listeners for this plugin.
165
+
166
+ --------------------
167
+
168
+
169
+ ### Interfaces
170
+
171
+
172
+ #### LockOptions
173
+
174
+ | Prop | Type | Description |
175
+ | ---------- | ----------------------------------------------------------- | -------------------------- |
176
+ | **`type`** | <code><a href="#orientationtype">OrientationType</a></code> | The orientation lock type. |
177
+
178
+
179
+ #### GetCurrentOrientationResult
180
+
181
+ | Prop | Type | Description |
182
+ | ---------- | ----------------------------------------------------------- | ----------------------------- |
183
+ | **`type`** | <code><a href="#orientationtype">OrientationType</a></code> | The current orientation type. |
184
+
185
+
186
+ #### PluginListenerHandle
187
+
188
+ | Prop | Type |
189
+ | ------------ | ----------------------------------------- |
190
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
191
+
192
+
193
+ #### ScreenOrientationChange
194
+
195
+ | Prop | Type | Description |
196
+ | ---------- | ----------------------------------------------------------- | ----------------------------- |
197
+ | **`type`** | <code><a href="#orientationtype">OrientationType</a></code> | The current orientation type. |
198
+
199
+
200
+ ### Type Aliases
201
+
202
+
203
+ #### ScreenOrientationChangeListener
204
+
205
+ Callback to receive the screen orientation change notifications.
206
+
207
+ <code>(change: <a href="#screenorientationchange">ScreenOrientationChange</a>): void</code>
208
+
209
+
210
+ ### Enums
211
+
212
+
213
+ #### OrientationType
214
+
215
+ | Members | Value | Description |
216
+ | ------------------------- | ---------------------------------- | ------------------------------------------------------------------- |
217
+ | **`LANDSCAPE`** | <code>'landscape'</code> | The orientation is either landscape-primary or landscape-secondary. |
218
+ | **`LANDSCAPE_PRIMARY`** | <code>'landscape-primary'</code> | The orientation is in the primary landscape mode. |
219
+ | **`LANDSCAPE_SECONDARY`** | <code>'landscape-secondary'</code> | The orientation is in the secondary landscape mode. |
220
+ | **`PORTRAIT`** | <code>'portrait'</code> | The orientation is either portrait-primary or portrait-secondary. |
221
+ | **`PORTRAIT_PRIMARY`** | <code>'portrait-primary'</code> | The orientation is in the primary portrait mode. |
222
+ | **`PORTRAIT_SECONDARY`** | <code>'portrait-secondary'</code> | The orientation is in the secondary portrait mode. |
223
+
224
+ </docgen-api>
225
+
226
+ ## Changelog
227
+
228
+ See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-screen-orientation/blob/master/CHANGELOG.md).
229
+
230
+ ## License
231
+
232
+ See [LICENSE](https://github.com/capawesome-team/capacitor-screen-orientation/blob/master/LICENSE).
@@ -0,0 +1,57 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.4.2'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:7.2.1'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
22
+ defaultConfig {
23
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
24
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32
25
+ versionCode 1
26
+ versionName "1.0"
27
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
28
+ }
29
+ buildTypes {
30
+ release {
31
+ minifyEnabled false
32
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
33
+ }
34
+ }
35
+ lintOptions {
36
+ abortOnError false
37
+ }
38
+ compileOptions {
39
+ sourceCompatibility JavaVersion.VERSION_11
40
+ targetCompatibility JavaVersion.VERSION_11
41
+ }
42
+ }
43
+
44
+ repositories {
45
+ google()
46
+ mavenCentral()
47
+ }
48
+
49
+
50
+ dependencies {
51
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
52
+ implementation project(':capacitor-android')
53
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
54
+ testImplementation "junit:junit:$junitVersion"
55
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
56
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
57
+ }
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="io.capawesome.capacitor.screenorientation">
3
+ </manifest>
@@ -0,0 +1,87 @@
1
+ package io.capawesome.capacitor.screenorientation;
2
+
3
+ import android.content.pm.ActivityInfo;
4
+ import android.content.res.Configuration;
5
+ import android.view.Surface;
6
+ import androidx.annotation.Nullable;
7
+ import com.getcapacitor.Bridge;
8
+
9
+ public class ScreenOrientation {
10
+
11
+ interface ScreenOrientationChangeListener {
12
+ void onScreenOrientationChanged();
13
+ }
14
+
15
+ @Nullable
16
+ private ScreenOrientationChangeListener orientationChangeListener;
17
+
18
+ @Nullable
19
+ private int lastOrientationConfiguration;
20
+
21
+ private Bridge bridge;
22
+
23
+ ScreenOrientation(Bridge bridge) {
24
+ this.bridge = bridge;
25
+ }
26
+
27
+ public void handleOnConfigurationChanged(Configuration newConfig) {
28
+ if (newConfig.orientation == lastOrientationConfiguration) {
29
+ return;
30
+ }
31
+ this.lastOrientationConfiguration = newConfig.orientation;
32
+ if (this.orientationChangeListener == null) {
33
+ return;
34
+ }
35
+ this.orientationChangeListener.onScreenOrientationChanged();
36
+ }
37
+
38
+ public void setOrientationChangeListener(@Nullable ScreenOrientationChangeListener listener) {
39
+ this.orientationChangeListener = listener;
40
+ }
41
+
42
+ @Nullable
43
+ public ScreenOrientationChangeListener getOrientationChangeListener() {
44
+ return orientationChangeListener;
45
+ }
46
+
47
+ public void lock(String orientationType) {
48
+ switch (orientationType) {
49
+ case ScreenOrientationType.LANDSCAPE:
50
+ bridge.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
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
+ }
68
+ }
69
+
70
+ public void unlock() {
71
+ bridge.getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_USER);
72
+ }
73
+
74
+ public String getCurrentOrientationType() {
75
+ int rotation = bridge.getActivity().getWindowManager().getDefaultDisplay().getRotation();
76
+ switch (rotation) {
77
+ case Surface.ROTATION_90:
78
+ return ScreenOrientationType.LANDSCAPE_PRIMARY;
79
+ case Surface.ROTATION_180:
80
+ return ScreenOrientationType.PORTRAIT_SECONDARY;
81
+ case Surface.ROTATION_270:
82
+ return ScreenOrientationType.LANDSCAPE_SECONDARY;
83
+ default:
84
+ return ScreenOrientationType.PORTRAIT_PRIMARY;
85
+ }
86
+ }
87
+ }
@@ -0,0 +1,56 @@
1
+ package io.capawesome.capacitor.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
+ }
@@ -0,0 +1,11 @@
1
+ package io.capawesome.capacitor.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
+ }
File without changes