Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/capawesome-team/capacitor-screen-orientation

⚡️ Capacitor plugin to lock/unlock the screen orientation.
https://github.com/capawesome-team/capacitor-screen-orientation

List: capacitor-screen-orientation

android capacitor capacitor-android capacitor-community capacitor-ios capacitor-plugin capawesome ios pwa web

Last synced: about 2 months ago
JSON representation

⚡️ Capacitor plugin to lock/unlock the screen orientation.

Awesome Lists containing this project

README

        

## ⚠️ Deprecated repository

**This project has been moved to the following monorepo: [capawesome-team/capacitor-plugins](https://github.com/capawesome-team/capacitor-plugins).**

-----



Screen Orientation


@capawesome/capacitor-screen-orientation



Capacitor plugin to lock/unlock the screen orientation.










## Maintainers

| Maintainer | GitHub | Social |
| ---------- | ----------------------------------------- | --------------------------------------------- |
| Robin Genz | [robingenz](https://github.com/robingenz) | [@robin_genz](https://twitter.com/robin_genz) |

## Sponsors

This is an MIT-licensed open source project.
It can grow thanks to the support by these awesome people.
If you'd like to join them, please read more [here](https://github.com/sponsors/capawesome-team).

## Installation

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

### iOS

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()
+ }
```

## Configuration

No configuration required for this plugin.

## Demo

A working example can be found here: [robingenz/capacitor-plugin-demo](https://github.com/robingenz/capacitor-plugin-demo)

## Usage

```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;
};
```

## API

* [`lock(...)`](#lock)
* [`unlock()`](#unlock)
* [`getCurrentOrientation()`](#getcurrentorientation)
* [`addListener('screenOrientationChange', ...)`](#addlistenerscreenorientationchange)
* [`removeAllListeners()`](#removealllisteners)
* [Interfaces](#interfaces)
* [Type Aliases](#type-aliases)
* [Enums](#enums)

### lock(...)

```typescript
lock(options: LockOptions) => Promise
```

Locks the device orientation.

| Param | Type |
| ------------- | --------------------------------------------------- |
| **`options`** | LockOptions |

--------------------

### unlock()

```typescript
unlock() => Promise
```

Unlocks the device orientation.

--------------------

### getCurrentOrientation()

```typescript
getCurrentOrientation() => Promise
```

Gets the current device orientation type.

**Returns:** Promise<GetCurrentOrientationResult>

--------------------

### addListener('screenOrientationChange', ...)

```typescript
addListener(eventName: 'screenOrientationChange', listenerFunc: ScreenOrientationChangeListener) => Promise & PluginListenerHandle
```

Listen for screen orientation changes.

| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------- |
| **`eventName`** | 'screenOrientationChange' |
| **`listenerFunc`** | ScreenOrientationChangeListener |

**Returns:** Promise<PluginListenerHandle> & PluginListenerHandle

--------------------

### removeAllListeners()

```typescript
removeAllListeners() => Promise
```

Remove all listeners for this plugin.

--------------------

### Interfaces

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

### Type Aliases

#### ScreenOrientationChangeListener

Callback to receive the screen orientation change notifications.

(change: ScreenOrientationChange): void

### Enums

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

## Changelog

See [CHANGELOG.md](https://github.com/capawesome-team/capacitor-screen-orientation/blob/master/CHANGELOG.md).

## License

See [LICENSE](https://github.com/capawesome-team/capacitor-screen-orientation/blob/master/LICENSE).