yamill / react-native-orientation

Listen to device orientation changes in react-native and set preferred orientation on screen to screen basis.
https://www.npmjs.com/package/react-native-orientation
ISC License
1.72k stars 810 forks source link

Locking doesn't rotate the interface when device is already rotated properly #205

Open thehappycoder opened 7 years ago

thehappycoder commented 7 years ago

I have two components. One of them (B) locks to portrait and the other one (A) -- to landscape right.

To reproduce:

  1. Load A
  2. Rotate the device to portrait
  3. Click a button to make it switch to component B

Expected

Actual

Workaround

If I want to lock the orientation and also make sure that interface is autorotated, I lock orientation to opposite value first:

Orientation.lockToPortrait()
Orientation.lockToLandscapeRight()
thehappycoder commented 7 years ago

Alternative workaround (which is better in my case)

Add this [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; before calling [[UIDevice currentDevice] setValue: ];

and

while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]) {
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
  }

before return [Orientation getOrientation]; in AppDelegate's application supportedInterfaceOrientationsForWindow

codedogfish commented 7 years ago

@thehappycoder make a PR :D

josepbordesjove commented 6 years ago

As I saw there were no PR for this issue, I got the solution from @thehappycoder and created one. Hope you don't mind..! The pull request is the #247.

mcordini commented 6 years ago

I still get this issue on 3.1.3. First workaround works