Giter Site home page Giter Site logo

vcalvello / react-native-device-display Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kkjdaniel/react-native-device-display

0.0 2.0 0.0 251 KB

Allowing the creation of adaptable and universal apps

License: BSD 2-Clause "Simplified" License

Objective-C 41.79% JavaScript 58.21%

react-native-device-display's Introduction

React Native Device Display

A simple way to create dynamic views through device and display detection, allowing the creation of adaptable and universal apps. Currently only for React Native iOS, Android support in progress.

GitHub issues Version Downloads

Example GIF Demo

Installation (iOS)

Simply install the package as shown below...

$ npm install react-native-device-display

Next you need to import the DisplayDeviceUtil classes into your project, these come bundled inside the NPM package.

Classes Installation Visual

Then require it in your project wherever you need it...

var Display = require('react-native-device-display');

Methods

Display.percentage(type, value);

Returns in pixels the percentage value of type width or height

Display.isTablet();

Returns true if the the device is a tablet (e.g iPad)

Display.isPhone();

Returns true if the the device is a phone (e.g iPhone)

Display.isPortrait();

Returns true if the the device is in a portrait position

Display.isLandscape();

Returns true if the the device is in a landscape position

Display.onOrientationDidChange(handler)

Triggers the handler call-back when the orientation changes

Properties

Display.width

Width in pixels of the display

Display.height

Height in pixels of the display

Display.verbose

Defaults to 'false'. Changing it to 'true' enables console.log messages of orientation change events

Example

var Display = require('react-native-device-display');
var listener;

var testing = React.createClass({

  componentDidMount: function() {
    listener = Display.onOrientationDidChange(function() {
      //Change States, perform Magic, etc...
    });
  },

  componentWillUnmount: function() {
    //Unlisten the onOrientationChange...
    listener = null;
  },
  
  render: function() {
    if (Display.isPortrait()) {
      //Return portrait view...
    } else if (Display.isLandscape()) {
      //Return landscape view...
    } 
    //Add as many conditions and views as you see fit...
  }
  
});

react-native-device-display's People

Contributors

albertwchang avatar dsibiski avatar eliagrady avatar jdeal avatar kkjdaniel avatar

Watchers

 avatar  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.