capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

bug(@capacitor/screen-orientation): iOS landscape lock using incorrect mappings

Open brian-weasner opened this issue 1 year ago • 4 comments

Bug Report

Plugin(s)

@capacitor/[email protected]

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 5.6.0
  @capacitor/core: 5.6.0
  @capacitor/android: 5.6.0
  @capacitor/ios: 5.6.0

Installed Dependencies:

  @capacitor/cli: 5.2.3
  @capacitor/android: 5.4.1
  @capacitor/core: 5.4.1
  @capacitor/ios: 5.4.1

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

  • iOS 14.5 SEE NOTE in technical details below
  • iOS 16.2, and 17.1

Current Behavior

  1. Rotate iOS device to be in landscape.
  2. Query the orientation
  3. Lock to that orientation.
  4. See the screen rotate 180 degrees in the other landscape position.

Expected Behavior

  1. Rotate iOS device to be in landscape.
  2. Query the orientation
  3. Lock to that orientation.
  4. Screen orientation should lock to the current orientation and not rotate.

Code Reproduction

I verified that this is also an issue in the repo https://github.com/WIStudent/capacitor-screen-orientation-issue-reproduction-app made by @WIStudent

Other Technical Details

iOS 14.5

After the screen is locked to the current orientation and the screen rotates 180 degrees, if you query for the current location again, it still shows that the current orientation is NOT THE SAME as the original.

iOS 16.2 & 17.1

After the screen is locked to the current orientation and the screen rotates 180 degrees, if you query for the current location again, it still shows that the current orientation is THE SAME as the original.

What is the issue

Issue lies in the difference between LandscapeLeft and LandscapeRight in UIDeviceOrientation and UIInterfaceOrientation

In UIDeviceOrientation, the focus for left and right is based on the position of the camera, while in UIInterfaceOrientation, the focus for left and right is based on the position of the home button. Both of which, camera and home button, are on opposite sides of the phone.

How to fix

Either:

  1. Change mappings in fromOrientationTypeToMask and fromOrientationTypeToInt so that

    • landscape-primary maps to UIInterfaceOrientationMask.landscapeRight and UIInterfaceOrientation.landscapeRight.rawValue respectfully
    • landscape-secondary maps to UIInterfaceOrientationMask.landscapeLeft and UIInterfaceOrientation.landscapeLeft.rawValue respectfully
  2. Change mapping in fromDeviceOrientationToOrientationType so that

    • UIDeviceOrientation.landscapeRight maps to landscape-primary
    • UIDeviceOrientation.landscapeLeft maps to landscape-secondary

1. IS PREFERRED because it will align the landscape-primary value on iOS and Android devices by having the camera/top of the device on the left, and the home button/bottom of the device on the right. Currently they are in sync on both devices when retrieving current orientation, but not when locking to a specific landscape orientation.

brian-weasner avatar Feb 02 '24 22:02 brian-weasner

Tracking in #2039

IT-MikeS avatar Feb 23 '24 16:02 IT-MikeS

This is not completed and the linked ticket does not describe the same problem.

brian-weasner avatar Feb 23 '24 16:02 brian-weasner

Ah I see now what you mean. Okay I'm going to reopen this and add it as a bug.

IT-MikeS avatar Feb 23 '24 16:02 IT-MikeS

This issue has been labeled as type: bug. This label is added to issues that that have been reproduced and are being tracked in our internal issue tracker.

ionitron-bot[bot] avatar Feb 23 '24 16:02 ionitron-bot[bot]

@IT-MikeS Is there any eta for when my pr can get looked at, merged and released? I ask because it has been a couple of months since the issue has been opened, and over a month since the fix was submitted for review.

brian-weasner avatar Apr 16 '24 20:04 brian-weasner

I believe its being looked at now

IT-MikeS avatar Apr 18 '24 13:04 IT-MikeS

Looks like my Pr has been merged into the 5.x branch! Thank you @IT-MikeS If you don't mind me asking how long until a new version is published? I assume that version bumping was not something I was supposed to do in the pr?

brian-weasner avatar Apr 18 '24 14:04 brian-weasner

No, there will be a release as soon as the thumbs up is given, normally we wait until there are a few fixes in making the release more impactful rather than constant small releases. Expect to see it I'd say within a week but don't quote me on that.

However if you look at the Versions tab on NPM (https://www.npmjs.com/package/@capacitor/screen-orientation?activeTab=versions) you can see there is a nightly, this will have the fixes in it, and may help get you unblocked for development but I don't recommend using it in production

IT-MikeS avatar Apr 22 '24 15:04 IT-MikeS

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.

ionitron-bot[bot] avatar May 07 '24 16:05 ionitron-bot[bot]