capacitor-plugins
capacitor-plugins copied to clipboard
feat(@capacitor/screen-orientation): Orientation 'landscape' lock should use current held landscape if any
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: https://github.com/ionic-team/capacitor-plugins/blob/be3dd6889b5d147cd43ff17ae2cfdb936a146a34/screen-orientation/ios/Sources/ScreenOrientationPlugin/ScreenOrientation.swift#L87 Android: https://github.com/ionic-team/capacitor-plugins/blob/be3dd6889b5d147cd43ff17ae2cfdb936a146a34/screen-orientation/android/src/main/java/com/capacitorjs/plugins/screenorientation/ScreenOrientation.java#L62
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
Updating the issue as a feature request as you can achieve explicit "landscape right" by using the landscape-secondary
option.
@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.
@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 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.
This issue would be resolved by making a separate case statement for "landscape" here: https://github.com/ionic-team/capacitor-plugins/blob/be3dd6889b5d147cd43ff17ae2cfdb936a146a34/screen-orientation/ios/Sources/ScreenOrientationPlugin/ScreenOrientation.swift#L87
And returning UIInterfaceOrientationMask.landscape
For Android I would suggest using SCREEN_ORIENTATION_SENSOR_LANDSCAPE (https://stackoverflow.com/a/35669103/16687547).
Me and my colleague created a fix for this issue
Hi all, any idea when this pull request will be reviewed?
This is an essential function. is anything else happening here?
@jansgescheit we tmp fixed this by using our own fork (based on v5)
{
"dependencies": {
"@capacitor/screen-orientation": "github:codepip55/screen-orientation#main",
}
}
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.
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.