Git Product home page Git Product logo

react-screen-orientation's Introduction

react-screen-orientation

Installation

npm install react-screen-orientation --save

Usage

Also see the example.

@import "~react-screen-orientation/src/index";
import React, {Component} from 'react'

import DeviceOrientation, { Orientation } from 'react-screen-orientation'

class Example extends Component {

  render () {
    return (
      <DeviceOrientation lockOrientation={'landscape'}>
        {/* Will only be in DOM in landscape */}
        <Orientation orientation='landscape' alwaysRender={false}>
          <div>
            <p>Only visible in landscape</p>
          </div>
        </Orientation>
        {/* Will stay in DOM, but is only visible in portrait */}
        <Orientation orientation='portrait'>
          <div>
            <p>Please rotate your device</p>
          </div>
        </Orientation>
      </DeviceOrientation>
    )
  }
}

Documentation

DeviceOrientation

childrenOrientation

Required. You MUST supply children of type Orientation. Each child will only be visible if it's orientation prop matches the current screen orientation.

classNameString ('')

Passes CSS classes to the underlying div.

lockOrientationString or Array (undefined)

Try to lock the device using either The Screen Orientation API or screen.lockOrientation.

Valid values are: portrait-primary, portrait-secondary, landscape-primary, landscape-secondary, portrait, landscape and default. Multiple values are allowed.

onLockOrientationfunction (success) (undefined)

Callback which will be called after trying to lock screen orientation using lockOrientation.

onOrientationChangefunction (orientation, type, angle) (undefined)

Will be called in componentWillMount and when screen orientation changes are detected. Orientation changes are detected using The Screen Orientation API or window.onorientationchange

window.screen.orientation.type is split into orientation and type parameters.

Parameters:

  • orientationportrait or landscape
  • typeprimary or secondary
  • angle0, 90, 180 or 270

Orientation

alwaysRenderboolean (true)

Set this to false to not render the component into the DOM if orientation does not match the current screen orientation. This can be helpful if you need your component to re-render when screen orientation changes.

children

Any children will be passed to the DOM.

classNameString ('')

Passes CSS classes to the underlying div.

orientationString (undefined)

Required Supply either portrait or landscape to indicate when the component should be visible.

react-screen-orientation's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

react-screen-orientation's Issues

Does not work with a React 15.5 peer dependency

If you have a peer of React >= 15.5, you'll see this error:

Uncaught TypeError: Cannot read property 'bool' of undefined
    at Object../node_modules/react-screen-orientation/lib/index.js (index.js:53)

This is because since 15.5, PropTypes is defined in a separate package. This can be fixed by merging #6.

Safari / MS Edge bugs

I'm trying to force my webapp to be in landscape view only. Having a rotate device message on portrait is appearing on desktop versions of Microsoft Edge and Safari.

Does anyone have any idea what could be causing this?

Doesn't work with Parcel?

I installed version 0.0.4 of react-screen-orientation using Yarn. This caused my app to no longer compile, with the following build error:

$ /home/docker/src/node_modules/.bin/parcel watch --hmr-port 8081 static/admin.html static/index.html
🚨  /home/docker/src/node_modules/react-screen-orientation/src/index.js:8:6: Unexpected token (8:6)
   6 |     const { orientation, children, className } = this.props
   7 |     return (
>  8 |       <div className={`${className} react-orientation react-orientation--${orientation}`}>
     |      ^
   9 |         {children}
  10 |       </div>
  11 |     )

It seems like the package was published to the registry without being compiled?

react-screen-orientation on Safari (macOS)

I'm running into problems with the plugin on macOS Safari (on iOS Safari everything works fine).
I get a warning message in console "No orientationchange events" and the screen gets set to "portrait" orientation instead of default "landscape".

ETA react-16 support release

Is there any ETA for the version that will support react-16?

I see the code has been already merged into develop, so it should be a matter of publishing it to the npm repository

TypeError on Safari

On safari getting the following error.

TypeError: undefined is not an object (evaluating 'window.screen.orientation.type')

On a Mac laptop and without any orientation changes occurring, happening on page rendering.

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.