GithubHelp home page GithubHelp logo

ptzagk / react-native-orientation-listener Goto Github PK

View Code? Open in Web Editor NEW

This project forked from walmartlabs/react-native-orientation-listener

0.0 1.0 0.0 46 KB

A react-native library for obtaining current device orientation

License: MIT License

Objective-C 32.72% Java 53.82% JavaScript 5.97% Ruby 7.49%

react-native-orientation-listener's Introduction

react-native-orientation-listener

A react-native library for obtaining current device orientation

###Getting Started

  • Run npm install --save react-native-orientation-listener

###IOS

  • Open your Xcode project, and select your project in the Project Navigator tab
  • Right click the Libraries folder and select "Add files to [your project]"
  • Add RCTOrientationListener.xcodeproj from your node_modules folder
  • Click your main project icon back in the Project Navigator to bring up preferences, and go to the Build Phases tab.
  • Click the + button underneath Link Binary With Libraries section.
  • Add libRCTOrientationListener.a

###Android

  • Open /android/settings.gradle
  • Replace include ':app' with:
include ':com.walmartreact.ReactOrientationListener', ':app'
project(':com.walmartreact.ReactOrientationListener').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-orientation-listener/android')
  • Open android/app/build.gradle
  • Add the following under dependencies:
compile project(':com.walmartreact.ReactOrientationListener')
  • Open your MainActivity.java file under android/src
  • Import the lib using import com.walmartreact.ReactOrientationListener.*;
  • Add the following after .addPackage(new MainReactPackage()):
.addPackage(new ReactOrientationListener())

###Usage

Import the library:

var Orientation = require('react-native-orientation-listener');

####getOrientation(callback)

This method will return the current orientation and device string in the form of a callback:

componentDidMount(){
  Orientation.getOrientation(
    (orientation, device) => {
      console.log(orientation, device);
    }
  );
}

####addListener(callback)

This method will add a listener that will call the callback anytime the device orienatation changes:

_setOrientation(data) {
  this.setState({
    orientation: evt.orientation,
    device: evt.device
  });
},
componentDidMount(){
  Orientation.addListener(this._setOrientation);
}

####removeListener(callback)

This method removes the listener you added in componentDidMount:

componentWillUnmount() {
  Orientation.removeListener(this._setOrientation);
}

react-native-orientation-listener's People

Contributors

atticoos avatar bartgryszko avatar bartonhammond avatar kenwheeler avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.