@capgo/capacitor-screen-orientation 7.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/README.md ADDED
@@ -0,0 +1,364 @@
1
+ # @capgo/capacitor-screen-orientation
2
+
3
+ <a href="https://capgo.app/"><img src='https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png' alt='Capgo - Instant updates for capacitor'/></a>
4
+
5
+ <div align="center">
6
+ <h2><a href="https://capgo.app/?ref=plugin_screen_orientation"> ➡️ Get Instant updates for your App with Capgo</a></h2>
7
+ <h2><a href="https://capgo.app/consulting/?ref=plugin_screen_orientation"> Missing a feature? We'll build the plugin for you 💪</a></h2>
8
+ </div>
9
+
10
+
11
+
12
+ Screen orientation plugin with support for detecting true physical device orientation
13
+
14
+ ## Features
15
+
16
+ - 📱 Full Screen Orientation API support
17
+ - 🔍 **Detect true physical device orientation** using motion sensors (even when orientation lock is enabled)
18
+ - iOS: Uses Core Motion framework
19
+ - Android: Uses accelerometer sensor
20
+ - 🔒 **Detect if orientation lock is enabled** by comparing physical vs UI orientation
21
+ - 🔄 Real-time orientation change detection
22
+ - 🎯 Lock orientation to specific modes
23
+ - 🌐 Web platform support
24
+
25
+ **Important Note:** This plugin can detect the physical orientation of the device using motion sensors, but it **cannot bypass the UI orientation lock**. The screen will still respect the user's orientation lock setting. This is useful for knowing how the device is physically held vs. how the UI is displayed.
26
+
27
+ ## Documentation
28
+
29
+ The most complete doc is available here: https://capgo.app/docs/plugins/screen-orientation/
30
+
31
+ ## Install
32
+
33
+ ```bash
34
+ npm install @capgo/capacitor-screen-orientation
35
+ npx cap sync
36
+ ```
37
+
38
+ ## iOS Configuration
39
+
40
+ To detect physical device orientation using motion sensors on iOS, you need to add the Motion Usage Description to your `Info.plist`:
41
+
42
+ ```xml
43
+ <key>NSMotionUsageDescription</key>
44
+ <string>This app uses motion sensors to detect the true physical orientation of your device.</string>
45
+ ```
46
+
47
+ ## Usage
48
+
49
+ ```typescript
50
+ import { ScreenOrientation } from '@capgo/capacitor-screen-orientation';
51
+
52
+ // Get current orientation
53
+ const result = await ScreenOrientation.orientation();
54
+ console.log('Current orientation:', result.type);
55
+
56
+ // Lock to landscape
57
+ await ScreenOrientation.lock({ orientation: 'landscape' });
58
+
59
+ // Lock UI orientation and track physical orientation via motion sensors
60
+ // Note: UI will still respect user's orientation lock, but you'll get physical orientation events
61
+ await ScreenOrientation.lock({
62
+ orientation: 'portrait',
63
+ bypassOrientationLock: true
64
+ });
65
+
66
+ // Listen for orientation changes
67
+ const listener = await ScreenOrientation.addListener(
68
+ 'screenOrientationChange',
69
+ (result) => {
70
+ console.log('Orientation changed:', result.type);
71
+ }
72
+ );
73
+
74
+ // Unlock orientation
75
+ await ScreenOrientation.unlock();
76
+
77
+ // Start motion-based tracking to detect physical device orientation
78
+ // This uses motion sensors to track how the device is actually held
79
+ await ScreenOrientation.startOrientationTracking({
80
+ bypassOrientationLock: true
81
+ });
82
+
83
+ // Check if device orientation lock is enabled
84
+ // Compares physical device orientation (from sensors) with UI orientation (from system)
85
+ const lockStatus = await ScreenOrientation.isOrientationLocked();
86
+ if (lockStatus.locked) {
87
+ console.log('Orientation lock is ON!');
88
+ console.log('Physical device orientation:', lockStatus.physicalOrientation);
89
+ console.log('UI orientation:', lockStatus.uiOrientation);
90
+ } else {
91
+ console.log('Orientation lock is OFF or motion tracking not active');
92
+ }
93
+
94
+ // Stop motion-based tracking
95
+ await ScreenOrientation.stopOrientationTracking();
96
+
97
+ // Remove listener
98
+ await listener.remove();
99
+ ```
100
+
101
+ ## API
102
+
103
+ <docgen-index>
104
+
105
+ * [`orientation()`](#orientation)
106
+ * [`lock(...)`](#lock)
107
+ * [`unlock()`](#unlock)
108
+ * [`startOrientationTracking(...)`](#startorientationtracking)
109
+ * [`stopOrientationTracking()`](#stoporientationtracking)
110
+ * [`isOrientationLocked()`](#isorientationlocked)
111
+ * [`addListener('screenOrientationChange', ...)`](#addlistenerscreenorientationchange-)
112
+ * [`removeAllListeners()`](#removealllisteners)
113
+ * [`getPluginVersion()`](#getpluginversion)
114
+ * [Interfaces](#interfaces)
115
+ * [Type Aliases](#type-aliases)
116
+
117
+ </docgen-index>
118
+
119
+ <docgen-api>
120
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
121
+
122
+ Capacitor Screen Orientation Plugin interface.
123
+
124
+ Provides methods to detect and control screen orientation,
125
+ with support for detecting true physical device orientation using motion sensors.
126
+
127
+ ### orientation()
128
+
129
+ ```typescript
130
+ orientation() => Promise<ScreenOrientationResult>
131
+ ```
132
+
133
+ Get the current screen orientation.
134
+
135
+ Returns the current orientation of the device screen.
136
+
137
+ **Returns:** <code>Promise&lt;<a href="#screenorientationresult">ScreenOrientationResult</a>&gt;</code>
138
+
139
+ **Since:** 1.0.0
140
+
141
+ --------------------
142
+
143
+
144
+ ### lock(...)
145
+
146
+ ```typescript
147
+ lock(options: OrientationLockOptions) => Promise<void>
148
+ ```
149
+
150
+ Lock the screen orientation to a specific type.
151
+
152
+ Locks the screen to the specified orientation.
153
+ On iOS, if bypassOrientationLock is true, it will also start
154
+ tracking physical device orientation using motion sensors.
155
+
156
+ Note: The UI will still respect the user's orientation lock setting.
157
+ Motion tracking allows you to detect how the device is physically held
158
+ even when the UI doesn't rotate.
159
+
160
+ | Param | Type | Description |
161
+ | ------------- | ------------------------------------------------------------------------- | ------------------------------------ |
162
+ | **`options`** | <code><a href="#orientationlockoptions">OrientationLockOptions</a></code> | Options for locking the orientation. |
163
+
164
+ **Since:** 1.0.0
165
+
166
+ --------------------
167
+
168
+
169
+ ### unlock()
170
+
171
+ ```typescript
172
+ unlock() => Promise<void>
173
+ ```
174
+
175
+ Unlock the screen orientation.
176
+
177
+ Allows the screen to rotate freely based on device position.
178
+ Also stops any motion-based orientation tracking if it was enabled.
179
+
180
+ **Since:** 1.0.0
181
+
182
+ --------------------
183
+
184
+
185
+ ### startOrientationTracking(...)
186
+
187
+ ```typescript
188
+ startOrientationTracking(options?: StartOrientationTrackingOptions | undefined) => Promise<void>
189
+ ```
190
+
191
+ Start tracking device orientation using motion sensors.
192
+
193
+ This method is useful when you want to track the device's physical
194
+ orientation independently from the screen orientation lock.
195
+ It uses Core Motion on iOS to detect orientation changes.
196
+
197
+ | Param | Type | Description |
198
+ | ------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------ |
199
+ | **`options`** | <code><a href="#startorientationtrackingoptions">StartOrientationTrackingOptions</a></code> | Options for starting orientation tracking. |
200
+
201
+ **Since:** 1.0.0
202
+
203
+ --------------------
204
+
205
+
206
+ ### stopOrientationTracking()
207
+
208
+ ```typescript
209
+ stopOrientationTracking() => Promise<void>
210
+ ```
211
+
212
+ Stop tracking device orientation using motion sensors.
213
+
214
+ Stops the motion-based orientation tracking if it was started.
215
+
216
+ **Since:** 1.0.0
217
+
218
+ --------------------
219
+
220
+
221
+ ### isOrientationLocked()
222
+
223
+ ```typescript
224
+ isOrientationLocked() => Promise<OrientationLockStatusResult>
225
+ ```
226
+
227
+ Check if device orientation lock is currently enabled.
228
+
229
+ This method compares the physical device orientation (from motion sensors)
230
+ with the UI orientation. If they differ, orientation lock is enabled.
231
+
232
+ Note: This requires motion tracking to be active via
233
+ startOrientationTracking() or lock() with bypassOrientationLock: true.
234
+ Works on both iOS (Core Motion) and Android (Accelerometer).
235
+
236
+ **Returns:** <code>Promise&lt;<a href="#orientationlockstatusresult">OrientationLockStatusResult</a>&gt;</code>
237
+
238
+ **Since:** 1.0.0
239
+
240
+ --------------------
241
+
242
+
243
+ ### addListener('screenOrientationChange', ...)
244
+
245
+ ```typescript
246
+ addListener(eventName: 'screenOrientationChange', listenerFunc: (result: ScreenOrientationResult) => void) => Promise<PluginListenerHandle>
247
+ ```
248
+
249
+ Listen for screen orientation changes.
250
+
251
+ Registers a listener that will be called whenever the screen orientation changes.
252
+ If motion-based tracking is enabled, this will also fire for orientation changes
253
+ detected by motion sensors even when orientation lock is enabled.
254
+
255
+ | Param | Type | Description |
256
+ | ------------------ | ------------------------------------------------------------------------------------------------ | --------------------------------------------------- |
257
+ | **`eventName`** | <code>'screenOrientationChange'</code> | The event name. Must be 'screenOrientationChange'. |
258
+ | **`listenerFunc`** | <code>(result: <a href="#screenorientationresult">ScreenOrientationResult</a>) =&gt; void</code> | Callback function invoked when orientation changes. |
259
+
260
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
261
+
262
+ **Since:** 1.0.0
263
+
264
+ --------------------
265
+
266
+
267
+ ### removeAllListeners()
268
+
269
+ ```typescript
270
+ removeAllListeners() => Promise<void>
271
+ ```
272
+
273
+ Remove all listeners for this plugin.
274
+
275
+ Removes all registered event listeners.
276
+
277
+ **Since:** 1.0.0
278
+
279
+ --------------------
280
+
281
+
282
+ ### getPluginVersion()
283
+
284
+ ```typescript
285
+ getPluginVersion() => Promise<{ version: string; }>
286
+ ```
287
+
288
+ Get the native plugin version.
289
+
290
+ Returns the current version of the native plugin implementation.
291
+
292
+ **Returns:** <code>Promise&lt;{ version: string; }&gt;</code>
293
+
294
+ **Since:** 1.0.0
295
+
296
+ --------------------
297
+
298
+
299
+ ### Interfaces
300
+
301
+
302
+ #### ScreenOrientationResult
303
+
304
+ Result returned by the orientation() method.
305
+
306
+ | Prop | Type | Description | Since |
307
+ | ---------- | ----------------------------------------------------------- | ----------------------------- | ----- |
308
+ | **`type`** | <code><a href="#orientationtype">OrientationType</a></code> | The current orientation type. | 1.0.0 |
309
+
310
+
311
+ #### OrientationLockOptions
312
+
313
+ Options for locking the screen orientation.
314
+
315
+ | Prop | Type | Description | Default | Since |
316
+ | --------------------------- | ------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
317
+ | **`orientation`** | <code><a href="#orientationlocktype">OrientationLockType</a></code> | The orientation type to lock to. | | 1.0.0 |
318
+ | **`bypassOrientationLock`** | <code>boolean</code> | Whether to track physical device orientation using motion sensors. When true, uses device motion sensors to detect the true physical orientation of the device, even when the device orientation lock is enabled. **Important:** This does NOT bypass the UI orientation lock. The screen will still respect the user's orientation lock setting. This option only affects orientation detection/tracking - you'll receive orientation change events based on how the device is physically held, but the UI will not rotate if orientation lock is enabled. Supported on iOS (Core Motion) and Android (Accelerometer). | <code>false</code> | 1.0.0 |
319
+
320
+
321
+ #### StartOrientationTrackingOptions
322
+
323
+ Options for starting orientation tracking using motion sensors.
324
+
325
+ | Prop | Type | Description | Default | Since |
326
+ | --------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
327
+ | **`bypassOrientationLock`** | <code>boolean</code> | Whether to track physical device orientation using motion sensors. When true, uses device motion sensors to detect the true physical orientation of the device, even when the device orientation lock is enabled. **Important:** This does NOT bypass the UI orientation lock. This only enables detection of the physical orientation. Supported on iOS (Core Motion) and Android (Accelerometer). | <code>false</code> | 1.0.0 |
328
+
329
+
330
+ #### OrientationLockStatusResult
331
+
332
+ Result returned by the isOrientationLocked() method.
333
+
334
+ | Prop | Type | Description | Since |
335
+ | ------------------------- | ----------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
336
+ | **`locked`** | <code>boolean</code> | Whether the device orientation lock is currently enabled. This is determined by comparing the physical device orientation (from motion sensors) with the UI orientation. If they differ, orientation lock is enabled. Available on iOS (Core Motion) and Android (Accelerometer) when motion tracking is active. | 1.0.0 |
337
+ | **`physicalOrientation`** | <code><a href="#orientationtype">OrientationType</a></code> | The physical orientation of the device from motion sensors. Available when motion tracking is active (iOS and Android). | 1.0.0 |
338
+ | **`uiOrientation`** | <code><a href="#orientationtype">OrientationType</a></code> | The current UI orientation reported by the system. | 1.0.0 |
339
+
340
+
341
+ #### PluginListenerHandle
342
+
343
+ | Prop | Type |
344
+ | ------------ | ----------------------------------------- |
345
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
346
+
347
+
348
+ ### Type Aliases
349
+
350
+
351
+ #### OrientationType
352
+
353
+ Orientation type that describes the orientation state of the device.
354
+
355
+ <code>'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary'</code>
356
+
357
+
358
+ #### OrientationLockType
359
+
360
+ Orientation lock type that can be used to lock the device orientation.
361
+
362
+ <code>'any' | 'natural' | 'landscape' | 'portrait' | 'portrait-primary' | 'portrait-secondary' | 'landscape-primary' | 'landscape-secondary'</code>
363
+
364
+ </docgen-api>
@@ -0,0 +1,58 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.7.2'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace "ee.forgr.capacitor.screenorientation"
22
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
26
+ versionCode 1
27
+ versionName "1.0"
28
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
+ }
30
+ buildTypes {
31
+ release {
32
+ minifyEnabled false
33
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
+ }
35
+ }
36
+ lintOptions {
37
+ abortOnError false
38
+ }
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_21
41
+ targetCompatibility JavaVersion.VERSION_21
42
+ }
43
+ }
44
+
45
+ repositories {
46
+ google()
47
+ mavenCentral()
48
+ }
49
+
50
+
51
+ dependencies {
52
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
53
+ implementation project(':capacitor-android')
54
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
55
+ testImplementation "junit:junit:$junitVersion"
56
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
+ }