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-screen-orientation

v1.1.0

Published

Listen to device orientation changes in react-native and set preferred orientation on screen to screen basis

Downloads

21

Readme

react-native-orientation

Listen to device orientation changes in react-native and set preferred orientation on screen to screen basis.

Installation

via rnpm

Run rnpm install react-native-orientation

Note: rnpm will install and link the library automatically.

via npm

Run npm install react-native-orientation --save

Linking

Using rnpm (iOS + Android)

rnpm link react-native-orientation

Using CocoaPods (iOS Only)

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

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

Manually

iOS

  1. Add node_modules/react-native-orientation/iOS/RCTOrientation.xcodeproj to your xcode project, usually under the Libraries group
  2. Add libRCTOrientation.a (from Products under RCTOrientation.xcodeproj) to build target's Linked Frameworks and Libraries list

Android

  1. In android/setting.gradle

    ...
    include ':react-native-orientation', ':app'
    project(':react-native-orientation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation/android')
  2. In android/app/build.gradle

    ...
    dependencies {
        ...
        compile project(':react-native-orientation')
    }
  3. Register module (in MainApplication.java)

    import com.github.yamill.orientation.OrientationPackage;  // <--- import
    
    public class MainApplication extends Application implements ReactApplication {
      ......
    
      @Override
      protected List<ReactPackage> getPackages() {
          return Arrays.<ReactPackage>asList(
              new MainReactPackage(),
              new OrientationPackage()      <------- Add this
          );
      }
    
      ......
    
    }

Configuration

iOS

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

#import "Orientation.h" // <--- import

@implementation AppDelegate

  // ...

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

@end

Usage

Whenever you want to use it within React Native code now you can: var Orientation = require('react-native-orientation');

  _orientationDidChange: function(orientation) {
    if (orientation == 'LANDSCAPE') {
      //do something with landscape layout
    } else {
      //do something with portrait layout
    }
  },

  componentWillMount: function() {
    //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: function() {
    Orientation.lockToPortrait(); //this will lock the view to Portrait
    //Orientation.lockToLandscape(); //this will lock the view to Landscape
    //Orientation.unlockAllOrientations(); //this will unlock the view to all Orientations

    Orientation.addOrientationListener(this._orientationDidChange);
  },

  componentWillUnmount: function() {
    Orientation.getOrientation((err,orientation)=> {
      console.log("Current Device Orientation: ", orientation);
    });
    Orientation.removeOrientationListener(this._orientationDidChange);
  }

Events

  • addOrientationListener(function(orientation))

orientation can return either LANDSCAPE PORTRAIT UNKNOWN also PORTRAITUPSIDEDOWN is now different from PORTRAIT

  • removeOrientationListener(function(orientation))

  • addSpecificOrientationListener(function(specificOrientation))

specificOrientation can return either LANDSCAPE-LEFT LANDSCAPE-RIGHT PORTRAIT UNKNOWN PORTRAITUPSIDEDOWN

  • removeSpecificOrientationListener(function(specificOrientation))

Functions

  • lockToPortrait()
  • lockToLandscape()
  • lockToLandscapeLeft()
  • lockToLandscapeRight()
  • unlockAllOrientations()
  • getOrientation(function(err, orientation)

orientation can return either LANDSCAPE PORTRAIT UNKNOWN PORTRAITUPSIDEDOWN

  • getSpecificOrientation(function(err, specificOrientation)

specificOrientation can return either LANDSCAPE-LEFT LANDSCAPE-RIGHT PORTRAIT UNKNOWN PORTRAITUPSIDEDOWN

TODOS

  • [x] Add some way to allow setting a preferred orientation on a screen by screen basis.
  • [x] Make API Cleaner to Orientation Locking
  • [x] Android Support