npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-morientation-locker

v1.2.0

Published

A react-native module that can listen on orientation changing of device, get current orientation, lock to preferred orientation.

Downloads

8

Readme

react-native-orientation-locker

npm

A react-native module that can listen on orientation changing of device, get current orientation, lock to preferred orientation. (cross-platform support)

Feature

  • lock screen orientation to PORTRAIT|LANDSCAPE-LEFT|PORTRAIT-UPSIDEDOWN|LANDSCAPE-RIGHT.
  • listen on orientation changing of device
  • get the current orientation of device

ChangeLog

v1.1.7

  1. Add lockToPortraitUpsideDown() to iOS
  2. Minor case corrections

v1.1.6

  1. Catch unknown device orientation value
  2. When calling unlockAllOrientations(), forcibly unlock whether locked or not

v1.1.5

  1. Add Orientation.isLocked() and Orientation.removeAllListeners()

v1.1.4

  1. Fix TypeScript declarations

v1.1.3

  1. Add addLockListener and removeLockListener
  2. Improve Android orientation changed event sending condition

v1.1.2

  1. Improve Android orientation changed event timing

v1.1.1

  1. Fix show "supported event type for deviceOrientationDidChange..." error in debug
  2. Fix getAutoRotateState() code error

v1.1.0 BREAKING CHANGES

  1. Split addOrientationListener(function(orientation, deviceOrientation)) to addOrientationListener(function(orientation)) and addDeviceOrientationListener(function(deviceOrientation))
  2. Make sure when lockToXXX and unlockAllOrientations resend UI orientation event
  3. remove setTimout from orientation listener
  4. Add getAutoRotateState() for Android
  5. Add TypeScript definitions

[more]

Notice

  1. RN 0.58 + Android target SDK 27 maybe cause Issue: java.lang.IllegalStateException: Only fullscreen activities can request orientation problem, see [#55] for a solution.

  2. orientationDidChange will be delayed on iPads if we set upside down to true. Simply disable upside down for iPad and everything works like a charm ([#78] Thanks truongluong1314520)

  3. If you get the following build error on iOS: ld: library not found for -lRCTOrientation-tvOS Just remove it from linked libraries and frameworks

Installation

Using yarn (RN 0.60 and and above)

    yarn add react-native-orientation-locer

Using yarn (RN 0.59 and and below)

    yarn add react-native-orientation-locer
    react-native link react-native-orientation-locker

Using CocoaPods (iOS Only)

pod 'react-native-orientation-locker', :path => '../node_modules/react-native-orientation-locker/react-native-orientation-locker.podspec'

Consult the React Native documentation on how to install React Native using CocoaPods.

Configuration

iOS

Add the following to your project's AppDelegate.m:

+#import "Orientation.h"

@implementation AppDelegate

// ...

+- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
+  return [Orientation getOrientation];
+}

@end

Android

Add following to android/app/src/main/AndroidManifest.xml

      <activity
        ....
+       android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">

          ....

      </activity>

Implement onConfigurationChanged method (in MainActivity.java)

// ...

+import android.content.Intent;
+import android.content.res.Configuration;

public class MainActivity extends ReactActivity {

+   @Override
+   public void onConfigurationChanged(Configuration newConfig) {
+       super.onConfigurationChanged(newConfig);
+       Intent intent = new Intent("onConfigurationChanged");
+       intent.putExtra("newConfig", newConfig);
+       this.sendBroadcast(intent);
+   }

    // ......
}

Add following to MainApplication.java (This will be added automatically by the react-native-link. If not, please manually add the following )

//...
+import org.wonday.orientation.OrientationPackage;

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        //...
+        new OrientationPackage(),
        //...
      );
    }
//...

Usage

Whenever you want to use it within React Native code now you can: import Orientation from 'react-native-orientation-locker';


import Orientation from 'react-native-orientation-locker';


  _onOrientationDidChange = (orientation) => {
    if (orientation == 'LANDSCAPE-LEFT') {
      //do something with landscape left layout
    } else {
      //do something with portrait layout
    }
  };

  componentWillMount() {
    //The getOrientation method is async. It happens sometimes that
    //you need the orientation at the moment the js starts running on device.
    //getInitialOrientation returns directly because its a constant set at the
    //beginning of the js code.
    var initial = Orientation.getInitialOrientation();
    if (initial === 'PORTRAIT') {
      //do stuff
    } else {
      //do other stuff
    }
  },

  componentDidMount() {

    Orientation.getAutoRotateState((rotationLock) => this.setState({rotationLock}));
    //this allows to check if the system autolock is enabled or not.

    Orientation.lockToPortrait(); //this will lock the view to Portrait
    //Orientation.lockToLandscapeLeft(); //this will lock the view to Landscape
    //Orientation.unlockAllOrientations(); //this will unlock the view to all Orientations

    //get current UI orientation
    /*
    Orientation.getOrientation((orientation)=> {
      console.log("Current UI Orientation: ", orientation);
    });

    //get current device orientation
    Orientation.getDeviceOrientation((deviceOrientation)=> {
      console.log("Current Device Orientation: ", deviceOrientation);
    });
    */

    Orientation.addOrientationListener(this._onOrientationDidChange);
  },

  componentWillUnmount: function() {
    Orientation.removeOrientationListener(this._onOrientationDidChange);
  }

Events

  • addOrientationListener(function(orientation))

When UI orientation changed, callback function will be called. But if lockToXXX is called , callback function will be not called untill unlockAllOrientations. It can return either PORTRAIT LANDSCAPE-LEFT LANDSCAPE-RIGHT PORTRAIT-UPSIDEDOWN UNKNOWN When lockToXXX/unlockAllOrientations, it will force resend UI orientation changed event.

  • removeOrientationListener(function(orientation))

  • addDeviceOrientationListener(function(deviceOrientation))

When device orientation changed, callback function will be called. When lockToXXX is called, callback function also can be called. It can return either PORTRAIT LANDSCAPE-LEFT LANDSCAPE-RIGHT PORTRAIT-UPSIDEDOWN UNKNOWN

  • removeDeviceOrientationListener(function(deviceOrientation))

  • addLockListener(function(orientation))

When call lockToXXX/unlockAllOrientations, callback function will be called. It can return either PORTRAIT LANDSCAPE-LEFT LANDSCAPE-RIGHT UNKNOWN UNKNOWN means not be locked.

  • removeLockListener(function(orientation))

  • removeAllListeners()

Functions

  • lockToPortrait()
  • lockToLandscape()
  • lockToLandscapeLeft() this will lock to camera left home button right
  • lockToLandscapeRight() this will lock to camera right home button left
  • lockToPortraitUpsideDown only support android
  • unlockAllOrientations()
  • getOrientation(function(orientation))
  • getDeviceOrientation(function(deviceOrientation))
  • getAutoRotateState(function(state)) (android only)
  • isLocked() (lock status by this library)

orientation can return one of:

  • PORTRAIT
  • LANDSCAPE-LEFT camera left home button right
  • LANDSCAPE-RIGHT camera right home button left
  • PORTRAIT-UPSIDEDOWN
  • UNKNOWN

Notice: PORTRAIT-UPSIDEDOWN is currently not supported on iOS at the moment.