Force landscape until switched back to portrait


#1

So, I have a view where the user will be holding the phone in portrait, and I want to force the new view that pops in after they tap to be in landcape, but I want them to be able to go to a portrait view once the move the phone to landscape and back to portrait.

I can easily force the landscape view with…

      this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE);

but if I add…

    this.screenOrientation.onChange().subscribe(()=>{
       this.screenOrientation.unlock();
    });

…it never goes into landscape because it is detecting an orientation change and unlocking.

I thought what would happen is that after forcing the landscape view, the user would turn the phone to landscape, which would fire the onChange and unlock it, then when they turn the phone back to portrait view, it would go to portrait view.

So, now I only seem to be able to lock it in landscape or have the normal functionality which changes based on the device detecting the orientation.

How can I lock it to landscape just on the initial load and then let it switch back to detecting the normal device orientation?

Cheers.


#2

"The type read-only property of the ScreenOrientation interface returns the document’s current orientation type, one of “portrait-primary”, “portrait-secondary”, “landscape-primary”, or “landscape-secondary”.

Syntax:

type = ScreenOrientation.type"
– from Mozilla.

You can get the type on change and lock it or not