Capacitor plugin to lock/unlock the screen orientation.
npm install @capawesome/capacitor-screen-orientationCapacitor plugin to lock/unlock the screen orientation.
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:
- 🖥️ Cross-platform: Supports Android, iOS, and Web.
- 🔒 Orientation locking: Lock screen to specific orientations.
- 🔓 Orientation unlocking: Unlock and restore automatic orientation.
- 📱 Multiple orientations: Support for portrait, landscape, and specific orientations.
- 🔄 Orientation detection: Get current screen orientation.
- 📢 Event listeners: Listen to orientation change events.
- 📐 Fine-grained control: Primary and secondary orientation modes.
- 🍎 iPad support: Special configuration for iPad orientation locking.
- 🔁 Up-to-date: Always supports the latest Capacitor version.
Missing a feature? Just open an issue and we'll take a look!
Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.
| Plugin Version | Capacitor Version | Status |
| -------------- | ----------------- | -------------- |
| 8.x.x | >=8.x.x | Active support |
| 7.x.x | 7.x.x | Deprecated |
| 6.x.x | 6.x.x | Deprecated |
| 5.x.x | 5.x.x | Deprecated |
``bash`
npm install @capawesome/capacitor-screen-orientation
npx cap sync
#### General
On iOS you must add the following to your app's AppDelegate.swift:
`diff
+ import CapawesomeCapacitorScreenOrientation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
+ func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
+ return ScreenOrientation.getSupportedInterfaceOrientations()
+ }
`
#### iPad Orientation Lock
On iPad, you must add the following to your app's Info.plist:
`xml`
No configuration required for this plugin.
A working example can be found here: robingenz/capacitor-plugin-demo
`typescript
import { ScreenOrientation, OrientationType } from '@capawesome/capacitor-screen-orientation';
const lock = async () => {
await ScreenOrientation.lock({ type: OrientationType.LANDSCAPE });
};
const unlock = async () => {
await ScreenOrientation.unlock();
};
const getCurrentOrientation = async () => {
const result = await ScreenOrientation.getCurrentOrientation();
return result.type;
};
`
* lock(...)
* unlock()
* getCurrentOrientation()
* addListener('screenOrientationChange', ...)
* removeAllListeners()
* Interfaces
* Type Aliases
* Enums
`typescript`
lock(options?: LockOptions | undefined) => Promise
Locks the device orientation.
| Param | Type |
| ------------- | --------------------------------------------------- |
| options | LockOptions |
--------------------
`typescript`
unlock() => Promise
Unlocks the device orientation.
--------------------
`typescript`
getCurrentOrientation() => Promise
Gets the current device orientation type.
Returns: Promise<GetCurrentOrientationResult>
--------------------
`typescript`
addListener(eventName: 'screenOrientationChange', listenerFunc: ScreenOrientationChangeListener) => Promise
Listen for screen orientation changes.
| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------- |
| eventName | 'screenOrientationChange' |
| listenerFunc | ScreenOrientationChangeListener |
Returns: Promise<PluginListenerHandle>
--------------------
`typescript`
removeAllListeners() => Promise
Remove all listeners for this plugin.
--------------------
#### LockOptions
| Prop | Type | Description |
| ---------- | ----------------------------------------------------------- | -------------------------- |
| type | OrientationType | The orientation lock type. |
#### GetCurrentOrientationResult
| Prop | Type | Description |
| ---------- | ----------------------------------------------------------- | ----------------------------- |
| type | OrientationType | The current orientation type. |
#### PluginListenerHandle
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove | () => Promise<void> |
#### ScreenOrientationChange
| Prop | Type | Description |
| ---------- | ----------------------------------------------------------- | ----------------------------- |
| type | OrientationType | The current orientation type. |
#### ScreenOrientationChangeListener
Callback to receive the screen orientation change notifications.
(change: ScreenOrientationChange): void
#### OrientationType
| Members | Value | Description |
| ------------------------- | ---------------------------------- | ------------------------------------------------------------------- |
| LANDSCAPE | 'landscape' | The orientation is either landscape-primary or landscape-secondary. |
| LANDSCAPE_PRIMARY | 'landscape-primary' | The orientation is in the primary landscape mode. |
| LANDSCAPE_SECONDARY | 'landscape-secondary' | The orientation is in the secondary landscape mode. |
| PORTRAIT | 'portrait' | The orientation is either portrait-primary or portrait-secondary. |
| PORTRAIT_PRIMARY | 'portrait-primary' | The orientation is in the primary portrait mode. |
| PORTRAIT_SECONDARY` | 'portrait-secondary' | The orientation is in the secondary portrait mode. |
See CHANGELOG.md.
See LICENSE.
This plugin is based on the Capacitor Screen Orientation plugin.
Thanks to everyone who contributed to the project!