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

feat(@capacitor/screen-orientation): Orientation 'landscape' lock should use current held landscape if any #2039

Open
codepip55 opened this issue Feb 23, 2024 · 12 comments
Labels
platform: android platform: ios type: feature request A new feature, enhancement, or improvement

Comments

@codepip55
Copy link

Bug Report

Plugin(s)

@capacitor/screen-orientation 5.0.7

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

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

Installed Dependencies:

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

Platform(s)

Android and iOS

Current Behavior

When locking the screen orientation to 'landscape' it locks it to landscape left. Meaning that if I'm holding my phone in landscape right mode, the view rotates 180 degrees and locks there. (Same goes for android with landscape and landscape reverse).

You can see this is how its configured in the plugin code:
iOS:


Android:

Expected Behavior

If the phone is physically held in either landscape left or right (normal or reverse for android), when locking the orientation to 'landscape' it should lock the current orientation without rotating anything.

Code Reproduction

This simple app by WIStudent reproduces the problem: https://github.com/WIStudent/capacitor-screen-orientation-issue-reproduction-app/tree/main

Other Technical Details

Additional Context

@ionitron-bot ionitron-bot bot added the triage label Feb 23, 2024
@ionitron-bot ionitron-bot bot removed the triage label Feb 23, 2024
@IT-MikeS IT-MikeS self-assigned this Feb 23, 2024
@IT-MikeS IT-MikeS changed the title @capacitor/screen-orientation - Bug: Orientation 'landscape' and rotating the phone 180 degrees does not rotate the view @capacitor/screen-orientation - Feature Request: Orientation 'landscape' lock should use current held landscape if any Feb 23, 2024
@IT-MikeS IT-MikeS added the type: feature request A new feature, enhancement, or improvement label Feb 23, 2024
@IT-MikeS
Copy link
Contributor

Updating the issue as a feature request as you can achieve explicit "landscape right" by using the landscape-secondary option.

@IT-MikeS IT-MikeS removed their assignment Feb 23, 2024
@IT-MikeS IT-MikeS changed the title @capacitor/screen-orientation - Feature Request: Orientation 'landscape' lock should use current held landscape if any feat(@capacitor/screen-orientation): Orientation 'landscape' lock should use current held landscape if any Feb 23, 2024
@brian-weasner
Copy link
Contributor

@IT-MikeS This issue and #2022 are similar but not the same.

iOS is broken on lock, not just when locking to 'landscape' because the Landscape Values returned by different native level functions are from different objects and are NOT equivalent.

@codepip55
Copy link
Author

@IT-MikeS To clarify, the issue is not that the app cant be locked to "landscape right", its that the "landscape" option in the plugin is defined as just "landscape left" instead of both "landscape left" and "landscape right".

@IT-MikeS
Copy link
Contributor

@IT-MikeS To clarify, the issue is not that the app cant be locked to "landscape right", its that the "landscape" option in the plugin is defined as just "landscape left" instead of both "landscape left" and "landscape right".

Understood, Im going to leave it as a feature request as it changes current behaviour of the plugin, however I agree that landscape option should respect the current rotation the device is in when being locked.

@brian-weasner
Copy link
Contributor

This issue would be resolved by making a separate case statement for "landscape" here:

And returning UIInterfaceOrientationMask.landscape

@codepip55
Copy link
Author

For Android I would suggest using SCREEN_ORIENTATION_SENSOR_LANDSCAPE (https://stackoverflow.com/a/35669103/16687547).

@codepip55
Copy link
Author

Me and my colleague created a fix for this issue

@ericmulder
Copy link

Hi all, any idea when this pull request will be reviewed?

@jansgescheit
Copy link

This is an essential function. is anything else happening here?

@ericmulder
Copy link

@jansgescheit we tmp fixed this by using our own fork (based on v5)

{
  "dependencies": {
    "@capacitor/screen-orientation": "github:codepip55/screen-orientation#main",
  }
}

@denesh-r
Copy link

I had a similar issue, however my use case was different.
My app needs to be only in landscape and be able to rotate to one or the other landscape modes when the user rotates the phone.

I initially battled with this ScreenOrientation plugin, however for IOS, in the App properties, I enabled only landscape orientations, and did not use ScreenOrientation.lock()

This gave me the required behavior. App starts in landscape mode and user is able to flip around and still be only in landscape.

image

@ericmulder
Copy link

Hi @denesh-r, that is a good solution when you want to lock the orientation all the time. But we have an app where the orientation switches depending per page. And when flipping back to locked landscape it produces the error which @codepip55 fixed in the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: android platform: ios type: feature request A new feature, enhancement, or improvement
Projects
None yet
Development

No branches or pull requests

7 participants