Skip to main content

Screen Orientation Capacitor plugin

Screen orientation plugin with support for bypassing orientation lock

Install

bun add @capgo/capacitor-screen-orientation bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-screen-orientation
  • pnpm add @capgo/capacitor-screen-orientation
  • yarn add @capgo/capacitor-screen-orientation

Guide

How to use Screen Orientation in Capacitor

Test on device

Download the Capgo app, then scan the QR code.

Screen Orientation plugin preview QR code

Using @capgo/capacitor-screen-orientation

Capacitor Screen Orientation Plugin interface.

Install

bun add @capgo/capacitor-screen-orientation
bunx cap sync

bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.

Import

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

API at a glance

Method Description
orientation Get the current screen orientation.
lock Lock the screen orientation to a specific type.
unlock Unlock the screen orientation.
startOrientationTracking Start tracking device orientation using motion sensors.
stopOrientationTracking Stop tracking device orientation using motion sensors.
isOrientationLocked Check if device orientation lock is currently enabled.
isDeviceFoldable Listen for screen orientation changes.
getFoldState Read the current fold.
getHingeAngle Read the hinge angle in degrees.
getReservedRegions Read the fold and anything covering the screen.
getBarPlacement Read where iPhone Duo puts native tab bars and toolbars.
setVerticalBarBehavior Choose whether iPhone Duo may move this app's bars to the side.
getSizeClass Read the window size classes.

Examples

orientation()

Get the current screen orientation.

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

const result = await ScreenOrientation.orientation();
console.log('Current orientation:', result.type);

lock()

Lock the screen orientation to a specific type.

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

// Standard lock
await ScreenOrientation.lock({ orientation: 'landscape' });

// Lock with motion tracking on iOS
await ScreenOrientation.lock({
  orientation: 'portrait',
  bypassOrientationLock: true
});

unlock()

Unlock the screen orientation.

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

await ScreenOrientation.unlock();

startOrientationTracking()

Start tracking device orientation using motion sensors.

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

await ScreenOrientation.startOrientationTracking({
  bypassOrientationLock: true
});

// Listen for changes
ScreenOrientation.addListener('screenOrientationChange', (result) => {
  console.log('Orientation changed:', result.type);
});

stopOrientationTracking()

Stop tracking device orientation using motion sensors.

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

await ScreenOrientation.stopOrientationTracking();

isOrientationLocked()

Check if device orientation lock is currently enabled.

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

// Start motion tracking first
await ScreenOrientation.startOrientationTracking({
  bypassOrientationLock: true
});

// Check lock status
const status = await ScreenOrientation.isOrientationLocked();
if (status.locked) {
  console.log('Orientation lock is ON');
  console.log('Physical:', status.physicalOrientation);
  console.log('UI:', status.uiOrientation);
}

The table above lists the 13 core methods. Listener and version helpers, and the full contract of each method, are documented in the GitHub repository.

Listen to events

addListener returns a handle. Call handle.remove() when the screen unmounts, or ScreenOrientation.removeAllListeners() to clear every listener.

Full reference

Keep going from Using @capgo/capacitor-screen-orientation

If you are using Using @capgo/capacitor-screen-orientation to plan native media and interface behavior, connect it with @capgo/capacitor-screen-orientation for the implementation detail in @capgo/capacitor-screen-orientation, Getting Started for the implementation detail in Getting Started, Using @capgo/capacitor-live-activities for the native capability in Using @capgo/capacitor-live-activities, @capgo/capacitor-live-activities for the implementation detail in @capgo/capacitor-live-activities, and Using @capgo/capacitor-video-player for the native capability in Using @capgo/capacitor-video-player.

FAQ

Screen Orientation plugin FAQ

How do I install the Screen Orientation plugin in a Capacitor app?

Run "bun add @capgo/capacitor-screen-orientation" (or "npm install @capgo/capacitor-screen-orientation"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-screen-orientation" in your app code.

Does @capgo/capacitor-screen-orientation work with React, Vue and Angular?

Yes. Screen Orientation is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-screen-orientation support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-screen-orientation free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-screen-orientation/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses Screen Orientation without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship Screen Orientation changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo