Skip to main content
Use this API to get the current screen orientation of the device.

Parameters

PropertyTypeRequiredDescription
successFunctionNoCallback on success
failFunctionNoCallback on failure
completeFunctionNoCallback that always executes

Success Callback Parameters

PropertyTypeDescription
orientationStringCurrent orientation: portrait, landscape, portraitUpsideDown, landscapeLeft, landscapeRight

Code Example

Basic Usage

my.getScreenOrientation({
  success(res) {
    console.log('Current orientation:', res.orientation);
  }
});

Adaptive Layout

Page({
  data: {
    isLandscape: false
  },

  onLoad() {
    this.checkOrientation();
    my.onScreenOrientationChange(this.handleOrientationChange);
  },

  checkOrientation() {
    my.getScreenOrientation({
      success: (res) => {
        const isLandscape = res.orientation.includes('landscape');
        this.setData({ isLandscape });
      }
    });
  },

  handleOrientationChange(res) {
    const isLandscape = res.orientation.includes('landscape');
    this.setData({ isLandscape });
  },

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

Orientation Values

ValueDescription
portraitDevice held upright
landscapeDevice held sideways
portraitUpsideDownDevice held upside down
landscapeLeftDevice rotated left
landscapeRightDevice rotated right

my.setScreenOrientation

Set screen orientation

my.onScreenOrientationChange

Listen for orientation changes