cordova-plugin-screen-orientation icon indicating copy to clipboard operation
cordova-plugin-screen-orientation copied to clipboard

Wrong lock/unlock orientation behaviour on iOS Devices

Open Hanzofm opened this issue 4 years ago • 6 comments
trafficstars

Bug Report

Problem

What is expected to happen?

-screenOrientation is locked in whole applicaction to screenOrientation.ORIENTATIONS.PORTRAIT_PRIMARY

-User enter into a page that can be rotated.(ex. a photo viewer)

-screenOrientation is unlocked and the user rotate the device to landscape mode.

-Users decide to close the page and the close method execute (when is already in landscape mode) :

screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT_PRIMARY);

-the ui returns to the previous page and rotates to portrait

-Then in portrait mode, user decides to enter again into the page that can be rotated:

-the page does screenOrientation.unlock();

The orientation should keep on Portrait mode.

What does actually happen?

After locked ui into this.screenOrientation.ORIENTATIONS.PORTRAIT_PRIMARY being in landscape orientation if unlock the orientation being in vertical orientation the ui returns to landscape mode automatically.

Information

-Same code works fine on Android -Tested on iOS devices 12 and 14

Environment, Platform, Device

iOS devices 12, ,13, 14 versions

Version information

 Ionic CLI                     : 6.12.3 (/usr/local/lib/node_modules/@ionic/cli)
 Ionic Framework               : @ionic/angular 5.2.3
 @angular-devkit/build-angular : 0.1000.3
 @angular-devkit/schematics    : 10.0.3
 @angular/cli                  : 10.0.3
 @ionic/angular-toolkit        : 2.3.3


  Cordova CLI       : 10.0.0
  Cordova Platforms :  ios 5.1.1
  Cordova Plugins   : "cordova-plugin-screen-orientation": "3.0.2",

Checklist

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above

Hanzofm avatar Apr 20 '21 17:04 Hanzofm

The problem has a relationship with the code of CDVOrientation.m file:

if (_lastOrientation != UIInterfaceOrientationUnknown) { [[UIDevice currentDevice] setValue:[NSNumber numberWithInt:_lastOrientation] forKey:@"orientation"]; ((void (*)(CDVViewController*, SEL, NSMutableArray*))objc_msgSend)(vc,selector,result); [UINavigationController attemptRotationToDeviceOrientation]; }

If comment the line:

[[UIDevice currentDevice] setValue:[NSNumber numberWithInt:_lastOrientation] forKey:@"orientation"]

The problem disappears.

Hanzofm avatar Apr 21 '21 13:04 Hanzofm

I am having the same issue

  1. Started with holding device in portrait-primary position and screen locked to portrait-primary"
  2. unlock()
  3. rotate device to landscape-secondary (clockwise) window.screen.orientation change event fires window.screen.orientation.type is now "landscape-secondary"
  4. lock("landscape-secondary") No event fires because orientation has not changed
  5. lock("portrait") window.screen.orientation change event fires window.screen.orientation.type is now "portrait-primary"
  6. rotate device to portrait-primary (counter clockwise) Nothing happens because orientation is locked.
  7. unlock() screen rotates to "landscape-secondary" window.screen.orientation change event fires window.screen.orientation.type is now "landscape-secondary"

The issue lies within step 7. Instead of just unlocking the orientation but keeping it as it is (or even better: updating it to the physical orientation of the device) the unlock call changes it back to the orientation that was active before the last lock call was made.

Seeing that the last release of this plugin was 2 years ago I have little hope of actually getting a fix. Too bad capacitor relys on this plugin for its orientation handling.

WIStudent avatar May 28 '21 14:05 WIStudent

Unfortunately there are even more issues with the iOS implementation:

  1. Started with holding device in landscape-secondary and screen locked to landscape-secondary
  2. Rotate device to portrait-primary (counterclockwise)
  3. lock("portrait-primary") The screen does not rotate to portrait-primary but stays on landscape-secondary. Probably because the plugin thinks that it already reached portrait-primary but in reality only the device is being hold in portrait-primary while the screen is still in landscape-secondary. The screen will only rotate in the correct position if the counterclockwise rotation of the device is repeated (rotate the device to landscape-secondary and then back to portrait-primary). Then the screen will be rotated to portrait-primary and stay locked in that orientation.

WIStudent avatar May 28 '21 15:05 WIStudent

I have the same issue, I already opened an issue (https://github.com/apache/cordova-plugin-screen-orientation/issues/82) and only after saw @WIStudent's comment. It has a little more information and also some code of the implementation, so I will leave that issue open. If anybody has any input, please use the other issue, as this one is regarding the lock/unlock mechanism.

ghost avatar Jul 29 '21 10:07 ghost

We are experiencing the exact same problem @Hanzofm and @WIStudent have described. Are there any updates/solutions?

visuallization avatar Oct 19 '21 11:10 visuallization

I believe this may be resolved by https://github.com/apache/cordova-plugin-screen-orientation/pull/102 (PR intended for iOS 16 issues, but contains code that I think would also address this issue)

breautek avatar Sep 22 '22 02:09 breautek