react-native-orientation icon indicating copy to clipboard operation
react-native-orientation copied to clipboard

addSpecificOrientationListener is not a function

Open Tsiniloiv opened this issue 7 years ago • 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?

Tsiniloiv avatar Jan 19 '18 12:01 Tsiniloiv

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

olbor avatar Jan 22 '18 09:01 olbor

I have not resoled this problem, no.

Tsiniloiv avatar Jan 22 '18 09:01 Tsiniloiv

I see thanks.

olbor avatar Jan 22 '18 09:01 olbor

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

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

nolan-m avatar Feb 22 '18 19:02 nolan-m

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.

olbor avatar Feb 23 '18 11:02 olbor

Same issue on Android.

bulats avatar May 07 '18 12:05 bulats

The issue hasn't been resolved?

MarcoPortillo avatar May 16 '18 22:05 MarcoPortillo

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

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

Resonious avatar May 17 '18 20:05 Resonious

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?

mdstroebel avatar May 22 '18 19:05 mdstroebel

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?

mdstroebel avatar May 22 '18 22:05 mdstroebel

Same issue on Android.

supermanxiacheng avatar Jun 27 '18 07:06 supermanxiacheng

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

supermanxiacheng avatar Jun 27 '18 07:06 supermanxiacheng

+1

bendadaniel avatar May 12 '19 14:05 bendadaniel