bug(@capacitor/screen-orientation): iOS landscape lock using incorrect mappings
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
- Rotate iOS device to be in landscape.
- Query the orientation
- Lock to that orientation.
- See the screen rotate 180 degrees in the other landscape position.
Expected Behavior
- Rotate iOS device to be in landscape.
- Query the orientation
- Lock to that orientation.
- 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
UIDeviceOrientation.landscapeLeftis NOT the same asUIInterfaceOrientation.landscapeLeftUIDeviceOrientation.landscapeRightis NOT the same asUIInterfaceOrientation.landscapeRight
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:
-
Change mappings in
fromOrientationTypeToMaskandfromOrientationTypeToIntso thatlandscape-primarymaps toUIInterfaceOrientationMask.landscapeRightandUIInterfaceOrientation.landscapeRight.rawValuerespectfullylandscape-secondarymaps toUIInterfaceOrientationMask.landscapeLeftandUIInterfaceOrientation.landscapeLeft.rawValuerespectfully
-
Change mapping in
fromDeviceOrientationToOrientationTypeso thatUIDeviceOrientation.landscapeRightmaps tolandscape-primaryUIDeviceOrientation.landscapeLeftmaps tolandscape-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.
Tracking in #2039
This is not completed and the linked ticket does not describe the same problem.
Ah I see now what you mean. Okay I'm going to reopen this and add it as a bug.
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.
@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.
I believe its being looked at now
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?
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
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.