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

Wrong lock/unlock orientation behaviour on iOS Devices #80

Open
3 tasks done
Hanzofm opened this issue Apr 20, 2021 · 6 comments
Open
3 tasks done

Wrong lock/unlock orientation behaviour on iOS Devices #80

Hanzofm opened this issue Apr 20, 2021 · 6 comments

Comments

@Hanzofm
Copy link

Hanzofm commented Apr 20, 2021

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

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above
@Hanzofm Hanzofm changed the title Wrong Behaviour on iOS Devices Wrong lock/unlock orientation behaviour on iOS Devices Apr 20, 2021
@Hanzofm
Copy link
Author

Hanzofm commented Apr 21, 2021

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 Hanzofm mentioned this issue Apr 22, 2021
@WIStudent
Copy link

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
Copy link

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.

@ghost
Copy link

ghost commented Jul 29, 2021

I have the same issue, I already opened an issue (#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.

@visuallization
Copy link

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

@breautek
Copy link
Contributor

I believe this may be resolved by #102 (PR intended for iOS 16 issues, but contains code that I think would also address this issue)

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

4 participants