yamill/react-native-orientation

addSpecificOrientationListener is not a function

Opened this issue · 13 comments

I've managed to get functions like lockToLandscape() working by using 'const Orientation = require('react-native').NativeModules.Orientation;' rather than 'import Orientation from 'react-native-orientation;', as using the latter results in Orientation being undefined.

But I can't add any sort of orientation listener, or even use getSpecificOrientation, because they all throw the same error - X is not a function.

I really need to track my device's orientation. How do I get these functions to work?

olbor commented

Have you resolved this problem? I have same issue. Function getSpecificOrientation doesn't work.

I have not resoled this problem, no.

olbor commented

I see thanks.

Do you have some reproduction case?
This works correctly for me on iOS.

  componentWillMount() {
    Orientation.getSpecificOrientation((err, specificOrientation) => {
      console.log('specificOrientation', specificOrientation)
    })
  }
olbor commented

Finally I got rid of Orientation and used react-native-sensors. It works good for both Android and iOS. Acceleration data gives me real current orientation of device.

Same issue on Android.

The issue hasn't been resolved?

I'm able to both add listeners and access current orientation with

const Orientation = require('react-native-orientation')

I checked the repo and it looks like "Android Specific Orientation" functionality was added in March 17, 2016 and then reverted the next day from the repo (March 18, 2016). I am not sure why this was done or why it has not been added back in... am I missing something here?

I have opened a PR to add back in the "GetSpecificOrientation" method. I did not add back the "addSpecificOrientationListener" at the moment since I didn't need it right now. Perhaps we could create another PR to add that listener back in?

Same issue on Android.

@olbor
can you give an example for how to get real current orientation of device by Acceleration data ?