Skip to content

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

Notifications You must be signed in to change notification settings

Tredsite/react-native-orientation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-orientation

Listen to device orientation changes in react-native. Orientation module adapted from @clavery.

Add it to your project

  1. Run npm install react-native-orientation --save
  2. Open your project in XCode, right click on your project and click Add Files to "Your Project Name"
  3. Add RCTOrientation from your node_modules/react-native-orientation folder.
  4. Whenever you want to use it within React code now you can: var Orientation = require('react-native-orientation');

Usage

  _orientationDidChange: function(orientation) {
    if(orientation == 'LANDSCAPE'){
      //do something with landscape layout
    }else{
      //do something with portrait layout
    }
  },
  componentDidMount: function(){
    Orientation.addOrientationListener(this._orientationDidChange);
  },
  componentWillUnmount: function() {
    Orientation.removeOrientationListener(this._orientationDidChange);
  }

Events

addOrientationListener(function)

removeOrientationListener(function)

Functions

_orientationDidChange(orientation)

orientation can return either LANDSCAPE PORTRAIT UNKNOWN

TODOS

  • Add some way to allow setting a preferred orientation on a screen by screen basis.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 38.2%
  • Java 28.1%
  • JavaScript 25.7%
  • Python 5.6%
  • Ruby 2.4%