Skip to main content
Use this API to stop listening for screen orientation changes that were registered with my.onScreenOrientationChange().

Parameters

PropertyTypeRequiredDescription
callbackFunctionNoThe specific callback to remove. If omitted, all listeners are removed.

Code Example

Remove All Listeners

// Remove all orientation change listeners
my.offScreenOrientationChange();

Remove Specific Listener

Page({
  onLoad() {
    my.onScreenOrientationChange(this.handleOrientation);
  },

  handleOrientation(res) {
    console.log('New orientation:', res.orientation);
  },

  onUnload() {
    my.offScreenOrientationChange(this.handleOrientation);
  }
});

Toggle Orientation Listener

Page({
  data: {
    orientationListenerActive: false
  },

  toggleOrientationListener() {
    if (this.data.orientationListenerActive) {
      my.offScreenOrientationChange(this.onOrientationChange);
      this.setData({ orientationListenerActive: false });
    } else {
      my.onScreenOrientationChange(this.onOrientationChange);
      this.setData({ orientationListenerActive: true });
    }
  },

  onOrientationChange(res) {
    this.setData({ orientation: res.orientation });
  }
});
Pass the same callback function reference to my.offScreenOrientationChange() that was used with my.onScreenOrientationChange() to remove only that specific listener.

my.onScreenOrientationChange

Listen for orientation changes

my.getScreenOrientation

Get current orientation