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

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

Open codepip55 opened this issue 1 year ago • 12 comments

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

codepip55 avatar Feb 23 '24 15:02 codepip55

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

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

@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.

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

@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".

codepip55 avatar Feb 23 '24 16:02 codepip55

@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.

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

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

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

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

codepip55 avatar Feb 26 '24 08:02 codepip55

Me and my colleague created a fix for this issue

codepip55 avatar Feb 26 '24 09:02 codepip55

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

ericmulder avatar Mar 15 '24 07:03 ericmulder

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

jansgescheit avatar May 10 '24 06:05 jansgescheit

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

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

ericmulder avatar May 13 '24 08:05 ericmulder

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

denesh-r avatar May 28 '24 16:05 denesh-r

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.

ericmulder avatar May 29 '24 09:05 ericmulder