1.1.7 • Published 2 years ago

@robingenz/capacitor-screen-orientation v1.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Maintainers

MaintainerGitHubSocial
Robin Genzrobingenz@robin_genz

Installation

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

iOS

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

+ import RobingenzCapacitorScreenOrientation

@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

Usage

import { ScreenOrientation } from '@robingenz/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(options: LockOptions) => 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>


Interfaces

LockOptions

PropTypeDescription
typeOrientationTypeThe orientation lock type.

GetCurrentOrientationResult

PropTypeDescription
typeOrientationTypeThe orientation lock type.

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.

Changelog

See CHANGELOG.md.

License

See LICENSE.