React-native-orientation: Cannot read property 'lockToLandscape' of undefined

Created on 22 Aug 2016  ยท  7Comments  ยท  Source: yamill/react-native-orientation

Hello,

I'm getting the following error. (I'm using react-native 0.31.0 for android)

I have run rnpm link react-native-orientation and tried manually linking

Manually linking caused a world of errors, see ticket https://github.com/yamill/react-native-orientation/issues/93

Cannot read property 'lockToLandscape' of undefined
Object.lockToLandscape
    index.js:23
VideoPlayer.componentDidMount
    VideoPlayer.js:74
ReactCompositeComponentWrapper.invokeComponentDidMountWithTimer
    ReactCompositeComponent.js:54
CallbackQueue.notifyAll
    CallbackQueue.js:67
ReactNativeReconcileTransaction.close
    ReactNativeReconcileTransaction.js:38
ReactNativeReconcileTransaction.closeAll
    Transaction.js:204
ReactNativeReconcileTransaction.perform
    Transaction.js:151
ReactUpdatesFlushTransaction.perform
    Transaction.js:138
ReactUpdatesFlushTransaction.perform
    ReactUpdates.js:90
Object.flushBatchedUpdates
    ReactUpdates.js:173

Here is a snippet of the code I'm using

// tried various import/require methods
// import { Orientation } from 'react-native-orientation';
// import Orientation from 'react-native-orientation';
const Orientation = require('react-native-orientation');

export class VideoPlayer extends Component {
....
  componentDidMount() {
    Orientation.lockToLandscape();
  }

  componentWillUnmount() {
    Orientation.unlockAllOrientations();
  }
....
}

I presume these errors are coming from not being linked correctly.

Any thoughts?

Many thanks

Most helpful comment

Same on 0.31, this works well on iOS but Android

All 7 comments

Same on 0.31, this works well on iOS but Android

Same as @Liroo and @magicspon

the steps of @xiongzhend solved this problem. Beware that when you download the master you have rename from "react-native-orientation-master" to "react-native-orientation"

https://github.com/yamill/react-native-orientation/issues/96

I solved this problem! I re-compiler my project 'react-native run-android', then it works!

Orientation.lockToLandscape();
โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“ โ†“
Orientation.lockToLandscape;

Please follow the updated guide on README on how to install and link native dependencies. Check version v2.0.0.

Make sure to include this line int eh AppDelegate.m.

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

It clearly says so in the README, but I saw the # and thought it was a comment at first.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

testxin picture testxin  ยท  4Comments

MrEdinLaw picture MrEdinLaw  ยท  3Comments

DriesVS picture DriesVS  ยท  7Comments

Mactub07 picture Mactub07  ยท  7Comments

sergio-solnet picture sergio-solnet  ยท  9Comments