Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScreenOrientation.unlockOrientation() doesn't unlock #939

Closed
ivanovvitaly opened this issue Jan 7, 2017 · 9 comments
Closed

ScreenOrientation.unlockOrientation() doesn't unlock #939

ivanovvitaly opened this issue Jan 7, 2017 · 9 comments

Comments

@ivanovvitaly
Copy link

ivanovvitaly commented Jan 7, 2017

I have modal page presented in landscape mode. When user dismisses the modal page I want to return screen orientation back to portrait mode without locking the orientation.

The problem is that orientation does changes to portrait, however after screen is rotated to portrait it stays locked in portrait orientation and doesn't react on device rotation. Using ionic-native 2.2.14 and iPhone

code from modal page

ionViewWillUnload(){
    ScreenOrientation.lockOrientation('portrait');
    ScreenOrientation.unlockOrientation();    
}

As workaround if I add delay to unlock the orientation it works, after screen returned to portrait I can rotate the phone and it changes the screen orientation

ionViewWillUnload(){
    ScreenOrientation.lockOrientation('portrait');
    setTimeout(function() {
        ScreenOrientation.unlockOrientation();    
    }, 100);        
}

So, maybe it does make sense to change lock\unlock functions to return Promise\Observable?

Please advice

@ihadeed
Copy link
Collaborator

ihadeed commented Jan 24, 2017

@ivanovvitaly

Can you try to modify your index.html and make sure that cordova.js is included AFTER polyfills.js ?

@ivanovvitaly
Copy link
Author

Moved cordova.js under polyfills.js. Didn't help, it rotates back to portrait, but stays locked.

@ihadeed
Copy link
Collaborator

ihadeed commented Jan 24, 2017

@ivanovvitaly I just realized the plugin returns back a promise, see https://github.com/apache/cordova-plugin-screen-orientation/blob/master/www/screenorientation.js#L71-L83

I will do the necessary changes to the ionic-native code to work with that.

@ivanovvitaly
Copy link
Author

ivanovvitaly commented Jan 25, 2017

Orientation still stays locked after update. Following doesn't help

ScreenOrientation.lockOrientation('portrait').then(() => ScreenOrientation.unlockOrientation());

Unlock after timeout still works as workaround.

@tskweres
Copy link

tskweres commented Feb 8, 2017

@ivanovvitaly I tried wrapping unlock inside a $timeout ( Angular 1.5 ) and it's not working, still locked. Can you send me a code sample of what you speak of as a work-around?

@ivanovvitaly
Copy link
Author

ivanovvitaly commented Feb 9, 2017

@tskweres
This works in ionic-native 2.4.0. Play with timeout values 200-300 is enough

 ionViewWillUnload(){
    ScreenOrientation.lockOrientation('portrait');

    setTimeout(function() {
        ScreenOrientation.unlockOrientation();    
    }, 300);        
}

@ndvbd
Copy link

ndvbd commented Jan 12, 2018

I'm using ionic 1.7.16 and cordova-plugin-screen-orientation 3.0.1, and the unlock doesn't work on iphones... Any clue why? the lock works.

@Anuj-logiciel
Copy link

Anuj-logiciel commented Feb 27, 2018

@NadavB It also depends on the plugin method.
I am also using https://github.com/apache/cordova-plugin-screen-orientation@3.0.1 and its working by using method : window.screen.orientation.unlock();

@TheSniper102
Copy link

this work fine for me

if(this.platform.is('cordova')){
  this.platform.ready().then(()=>{
    this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);
  })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants