Toggle screen orientation lock


#1

Hi, thought this would be easy, but there’s no way to check whether the the screen is currently locked, so it seems to be more complicated than I thought. I want a button to toggle the screen lock for the current orientation. Anyone have any ideas to a best approach? Cheers.


#2

Maybe Screen Orientation Plugin can help you.


#3

Yes, I am speaking of with the screen orientation plugin.

This is what ended up working for me. You have to go into the view with the screen orientation locked.

  lockOrUnlockRotation() {
    if (this.lockState === true) {
      this.screenOrientation.unlock()
      this.lockState = false
    } else {
      if (this.screenOrientation.type == "landscape-secondary") {
        this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.LANDSCAPE_SECONDARY);
      } else {
        this.screenOrientation.lock(this.screenOrientation.ORIENTATIONS.PORTRAIT);
      }
      this.lockState = true
    }
  }