@capawesome/capacitor-screen-orientation

中文文档
8.0.4发布于 2026/10/21MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 9.5万

Capacitor plugin to lock/unlock the screen orientation on Android, iOS, and Web.

原始使用文档
文档目录32 节
  1. Features
  2. Use Cases
  3. Compatibility
  4. Demo
  5. Installation
  6. iOS
  7. Configuration
  8. Usage
  9. Lock the screen orientation
  10. Unlock the screen orientation
  11. Get the current screen orientation
  12. API
  13. lock(...)
  14. unlock()
  15. getCurrentOrientation()
  16. addListener('screenOrientationChange', ...)
  17. removeAllListeners()
  18. Interfaces
  19. Type Aliases
  20. Enums
  21. FAQ
  22. Why does the orientation lock not work on iPad?
  23. Do I need to modify my AppDelegate on iOS?
  24. What is the difference between LANDSCAPE and LANDSCAPE_PRIM…
  25. How do I restore automatic rotation after locking the orien…
  26. How can I react to orientation changes?
  27. Can I use this plugin with Ionic, React, Vue or Angular?
  28. Related Plugins
  29. Newsletter
  30. Changelog
  31. License
  32. Credits

Capacitor Screen Orientation Plugin

Capacitor plugin to lock/unlock the screen orientation.

Features

The Capacitor Screen Orientation plugin is one of the most complete orientation control solutions for Capacitor apps. 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.
  • 🤝 Compatibility: Works alongside the Home Indicator, Keep Awake and Navigation Bar plugins.
  • 🔁 Up-to-date: Always supports the latest Capacitor version.

Missing a feature? Just open an issue and we'll take a look!

Use Cases

The Screen Orientation plugin is typically used whenever certain screens of an app only work well in a specific orientation, for example:

  • Video players: Lock the screen to landscape for fullscreen video playback.
  • Games: Keep the game in a fixed orientation regardless of how the device is held.
  • Camera and scanner screens: Lock the screen to portrait while capturing photos or scanning codes.
  • Forms and reading views: Prevent accidental rotation while the user is typing or reading.
  • Responsive layouts: React to orientation changes with the screenOrientationChange event to adapt your UI.

Compatibility

Plugin VersionCapacitor VersionStatus
8.x.x>=8.x.xActive support
7.x.x7.x.xDeprecated
6.x.x6.x.xDeprecated
5.x.x5.x.xDeprecated

Demo

A working example can be found here: robingenz/capacitor-plugin-demo

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

 Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-screen-orientation` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capawesome/capacitor-screen-orientation
npx cap sync

iOS

General

On iOS you must add the following to your app's AppDelegate.swift:

+ import ScreenOrientationPlugin

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

+ func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
+   return ScreenOrientation.getSupportedInterfaceOrientations()
+ }

If your project still uses CocoaPods instead of Swift Package Manager (SPM), import CapawesomeCapacitorScreenOrientation rather than ScreenOrientationPlugin:

+ import CapawesomeCapacitorScreenOrientation

iPad Orientation Lock

On iPad, you must add the following to your app's Info.plist:

<key>UIRequiresFullScreen</key>
<true/>

Configuration

No configuration required for this plugin.

Usage

The following examples show how to lock, unlock, and read the current screen orientation.

Lock the screen orientation

Lock the device to a specific orientation, for example landscape. Besides LANDSCAPE and PORTRAIT, you can also lock to a primary or secondary mode such as LANDSCAPE_PRIMARY for fine-grained control:

import { ScreenOrientation, OrientationType } from '@capawesome/capacitor-screen-orientation';

const lock = async () => {
  await ScreenOrientation.lock({ type: OrientationType.LANDSCAPE });
};

Unlock the screen orientation

Remove the orientation lock and restore automatic rotation:

import { ScreenOrientation } from '@capawesome/capacitor-screen-orientation';

const unlock = async () => {
  await ScreenOrientation.unlock();
};

Get the current screen orientation

Read the current orientation type of the device:

import { ScreenOrientation } from '@capawesome/capacitor-screen-orientation';

const getCurrentOrientation = async () => {
  const result = await ScreenOrientation.getCurrentOrientation();
  return result.type;
};

API

lock(...)

lock(options?: LockOptions | undefined) => Promise<void>

Locks the device orientation.

ParamType
optionsLockOptions

unlock()

unlock() => Promise<void>

Unlocks the device orientation.


getCurrentOrientation()

getCurrentOrientation() => Promise<GetCurrentOrientationResult>

Gets the current device orientation type.

Returns: Promise<GetCurrentOrientationResult>


addListener('screenOrientationChange', ...)

addListener(eventName: 'screenOrientationChange', listenerFunc: ScreenOrientationChangeListener) => Promise<PluginListenerHandle>

Listen for screen orientation changes.

ParamType
eventName'screenOrientationChange'
listenerFuncScreenOrientationChangeListener

Returns: Promise<PluginListenerHandle>


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.


Interfaces

LockOptions

PropTypeDescription
typeOrientationTypeThe orientation lock type.

GetCurrentOrientationResult

PropTypeDescription
typeOrientationTypeThe current orientation type.

PluginListenerHandle

PropType
remove() => Promise<void>

ScreenOrientationChange

PropTypeDescription
typeOrientationTypeThe current orientation type.

Type Aliases

ScreenOrientationChangeListener

Callback to receive the screen orientation change notifications.

(change: ScreenOrientationChange): void

Enums

OrientationType

MembersValueDescription
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.

FAQ

Why does the orientation lock not work on iPad?

For the orientation lock to work on iPad, you must add the UIRequiresFullScreen key with the value true to your app's Info.plist file, as described in the Installation section. Also make sure that you have applied the required changes to your AppDelegate.swift.

Do I need to modify my AppDelegate on iOS?

Yes. You must implement the supportedInterfaceOrientationsFor method in your app's AppDelegate.swift and return ScreenOrientation.getSupportedInterfaceOrientations(), as shown in the Installation section. Without this change, the orientation lock has no effect on iOS.

What is the difference between LANDSCAPE and LANDSCAPE_PRIMARY?

The LANDSCAPE type covers both landscape modes, so the device can be rotated between landscape-primary and landscape-secondary while locked. The LANDSCAPE_PRIMARY and LANDSCAPE_SECONDARY types lock the screen to exactly one of the two landscape modes. The same applies to PORTRAIT, PORTRAIT_PRIMARY and PORTRAIT_SECONDARY.

How do I restore automatic rotation after locking the orientation?

Simply call the unlock() method. It removes the orientation lock so that the device rotates automatically again based on the user's device settings.

How can I react to orientation changes?

Add a listener for the screenOrientationChange event using the addListener(...) method. The listener receives the new orientation type every time the screen orientation changes. Use removeAllListeners() to remove all listeners when you no longer need them.

Can I use this plugin with Ionic, React, Vue or Angular?

Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

License

See LICENSE.

Credits

This plugin is based on the Capacitor Screen Orientation plugin. Thanks to everyone who contributed to the project!

版本与发布记录

@capawesome/capacitor-screen-orientation 共发布 19 个版本,首次发布于 2022/08/04;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.0.4latest2026/10/2119 天前
8.0.32026/09/022 个月前
8.0.22026/08/162 个月前
8.0.12026/02/198 个月前
8.0.02025/12/1710 个月前
7.0.0-dev.1765885034dev2025/12/1610 个月前

关于 @capawesome/capacitor-screen-orientation 的常见问题

@capawesome/capacitor-screen-orientation 是什么?

Capacitor plugin to lock/unlock the screen orientation on Android, iOS, and Web.

如何安装 @capawesome/capacitor-screen-orientation?

在项目目录运行 npm install @capawesome/capacitor-screen-orientation,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capawesome/capacitor-screen-orientation 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capawesome/capacitor-screen-orientation 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capawesome/capacitor-screen-orientation 可以商用吗?

@capawesome/capacitor-screen-orientation 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@capawesome/capacitor-screen-orientation 的下载量有多少?

根据 npm 官方下载统计,@capawesome/capacitor-screen-orientation 在 2026/10/09 – 2026/11/07 这 30 天内被下载 95,321 次,日均约 3,177 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capawesome/capacitor-screen-orientation 还在维护吗?

最新版本 8.0.4 发布于 2026/10/21(19 天前);至今共发布 19 个版本,其中过去 12 个月发布了 7 个;首次发布于 2022/08/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。