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

Orientation not working on Android #75

Open
florisdh opened this issue Oct 19, 2020 · 4 comments
Open

Orientation not working on Android #75

florisdh opened this issue Oct 19, 2020 · 4 comments

Comments

@florisdh
Copy link

Bug Report

Problem

Since a few weeks we noticed that the orientation suddenly didn't allow unlocking anymore in our app.

What is expected to happen?

After calling unlock(), the app should use the sensor for the right orientation.

What does actually happen?

When calling unlock(), it was going back to forced portrait.

Environment, Platform, Device

Tried on multiple android devices.

Version information

  • @capacitor/*: 2.4.0
  • Android build: (minSdkVersion = 21, compileSdkVersion = 29, targetSdkVersion = 29)
  • Android version: 10

I've made a fix which we are using now, which can be found here.

  • Based on the 3.0.2 tag since the master branch didn't work for us
@timbru31
Copy link
Member

Sorry, clicked the wrong button. Can you elaborate what's the difference in your fix and why it works again as expected?

@timbru31 timbru31 reopened this Oct 19, 2020
@breautek
Copy link
Contributor

From the android docs

Sensor:

Orientation is determined by a physical orientation sensor: the display will rotate based on how the user moves the device. Ignores user's setting to turn off sensor-based rotation.

Unspecified:

No preference specified: let the system decide the best orientation. This will either be the orientation selected by the activity below, or the user's preferred orientation if this activity is the bottom of a task. If the user explicitly turned off sensor based orientation through settings sensor based device rotation will be ignored. If not by default sensor based orientation will be taken into account and the orientation will changed based on how the user rotates the device.

It sounds like if we used sensor it may cause the app to ignore user settings, which sounds like a bad assumption to make.

@florisdh
Copy link
Author

Hey guys, thanks for the quick reply. 🤘

In the end I decided to create a demo project showing the issue that we're facing. After some hours of debugging why our project actually has this behaviour, I found what was causing this weird behaviour here

You can run my demo project and see that running screen.orientation.unlock() will cause the screen to lock to portrait for some reason.

This is probably caused by the underlaying activity somehow being locked to portrait by this and the unspecified option used by this plugin will use this as seen in the docs

Unspecified: ... This will either be the orientation selected by the activity below, or ...

Aside from this my 'fix' was using Sensor as breautek mentioned, which is also not really ideal since it would ignore the user settings, so I changed it to use the 'ActivityInfo.SCREEN_ORIENTATION_USER' as seen here. This will only use the sensor if enabled.

As a developer I would expect that calling screen.orientation.unlock() would actually unlock the screen orientation by using the sensor if enabled in the settings, thus I think it would be best to change it to ActivityInfo.SCREEN_ORIENTATION_USER.

Anyway our issue is fixed, so I rest my case.

Thanks for the support!

@Andalusio
Copy link

In my case, .lock("landscape") doesn't work. It either still uses the setting from the config.xml or, if you used .unlock() first, the phone will still use all orientations instead of just "landscape".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants