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

lockToPortrait not working RN58 IOS #341

Open erdouzun opened 5 years ago

erdouzun commented 5 years ago

Hi,

I'm trying to lock the screen on portrait mode. I applied every rule correctly according to https://github.com/yamill/react-native-orientation

componentDidMount() { Orientation.lockToPortrait(); Orientation.addOrientationListener(this._onOrientationDidChange); //Orientation.lockToLandscape() }

  componentWillUnmount() {
    // Remember to remove listener
    Orientation.removeOrientationListener(this._onOrientationDidChange);
    this._willFocusSubscription.remove();
  }

componentWillMount() { var initial = Orientation.getInitialOrientation(); if (initial === 'PORTRAIT') { //do stuff } else { //do other stuff } }

_onOrientationDidChange = (orientation) => { if (orientation == 'LANDSCAPE') { // } else { //do something with portrait layout } }

RN version 0.58 "react-native-orientation": "^3.1.3",

Can anyone help me about this issue? I searched the issues, found the similars but nothing helps me

domingogogo commented 5 years ago

checking the this url https://github.com/yamill/react-native-orientation/issues/121

retyui commented 5 years ago

Or use a react-native-orientation-locker module with normal support ! :+1:

chrismang commented 4 years ago

Try this configuration in AppDelegate.m:

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

@implementation AppDelegate

  // ...

  - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]) {
        [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
    }

    return [Orientation getOrientation];
  }

@end
alinakazzaa commented 11 months ago

Try this configuration in AppDelegate.m:

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

@implementation AppDelegate

  // ...

  - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]) {
        [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
    }

    return [Orientation getOrientation];
  }

@end

This worked for me, thank you!