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

Screen orientation lock not working (eg. portrait-primary) if the device is locked in other orientation (eg. landscape-primary) but held in the first orientation (eg. portrait-primary) #82

Open
ghost opened this issue Jun 25, 2021 · 1 comment

Comments

@ghost
Copy link

ghost commented Jun 25, 2021

Bug Report

Hello, I have an application which plays live streams. Because we want custom controls on iOS we can't use the fullscreen API from our player, so we need to mimic it by using css. When the user hits a button the app is locked to landscape and the css changes for fullscreen view. The other way around for exit fullscreen.

Problem

The screen orientation works perfect on Android, but not for iOS.

What is expected to happen?

The application should change its orientation as the call to screenOrientation.lock is made.

What does actually happen?

If the phone is HELD in the same orientation everything works as expected, even on iOS.

But if the following steps are done:

  • the phone is held in portrait (locked)
  • user hits fullscreen => app locks to landscape and everything looks good
  • the user turns the phone to landscape then back to portrait (the app is still in landscape, being locked)
  • the user hits the exit fullscreen button which should lock the phone to portrait => the phone remains in landscape (100% of the cases). Here is the even stranger part, if the user turns the phone in any landscape mode the app goes in portrait and it is locked there. It seems that somehow the phone realizes it is not in portrait only after the user rotates the phone and then it changes to portrait, as already mentioned.

Information

The code runs without any issues, no warnings, no errors, logs from within the lock promise are displayed, everything seems fine, the phone does not change its orientation.

Command or Code

import {ScreenOrientation} from '@ionic-native/screen-orientation/ngx';

constructor(private screenOrientation: ScreenOrientation) {
        this.orientation = this.screenOrientation.type;

        this.screenOrientation.onChange().subscribe(() => {
            if (this.orientation !== this.screenOrientation.type) {
                this.orientation = this.screenOrientation.type;
                this.orientationChangeSubject.next(this.screenOrientation.type);
            }
        });
}

private changeTo(orientation, unlock: boolean = true): Promise<void> {
        return this.screenOrientation.lock(orientation).then(() => {
            this.orientation = orientation;
            if (unlock) {
                this.unlock();
            }
        }).catch(() =>
            console.error('The fullscreen button does not work from the browser, only from mobile devices')
        );
}

// The "changeTo " method is called like this:
changeToPortraitAndLock() {
        return this.changeTo(this.screenOrientation.ORIENTATIONS.PORTRAIT_PRIMARY, false);
}

Environment, Platform, Device

iOS 14.3

Version information

"@capacitor/android": "^2.4.2",
"@capacitor/core": "^2.4.2",
"@capacitor/ios": "^2.4.2",
"@ionic-native/core": "^5.0.7",
"@ionic-native/screen-orientation": "^5.33.1",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic/angular": "^5.0.0",
"@ionic/pwa-elements": "^1.5.2",
"cordova-plugin-screen-orientation": "^3.0.2",

Checklist

  • [ X ] I searched for existing GitHub issues
  • [ X ] I updated all Cordova tooling to most recent version
  • [ X ] I included all the necessary information above
@ghost ghost changed the title Screen orientation not working randomly Screen orientation lock not working (eg. portrait-primary) if the device is locked in other orientation (eg. landscape-primary) but held in the first orientation (eg. portrait-primary)) Jul 29, 2021
@ghost ghost changed the title Screen orientation lock not working (eg. portrait-primary) if the device is locked in other orientation (eg. landscape-primary) but held in the first orientation (eg. portrait-primary)) Screen orientation lock not working (eg. portrait-primary) if the device is locked in other orientation (eg. landscape-primary) but held in the first orientation (eg. portrait-primary) Jul 29, 2021
@andrehhtm
Copy link

Do you have any updates about this problem?

(sorry for reopen this thread)

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

1 participant