logo
On this page

Adaptive mobile rotation

Add dependencies.

  1. Need to upgrade ZegoUIKit to version 2.7.0 or above.
Untitled
"@zegocloud/zego-uikit-rn": "^2.7.0",
1
Copied!
  1. Run the following code in your project root directory, to install react-native-orientation-locker.
yarn
npm
yarn add react-native-orientation-locker
1
Copied!
npm install react-native-orientation-locker
1
Copied!

Sample code

Here is the sample code.

Untitled
import ZegoUIKit from '@zegocloud/zego-uikit-rn'
import Orientation from 'react-native-orientation-locker';

  useEffect(() => {
    
    // Add screen orientation listener, and set the app Orientation to UIKit.
    // App Orientation:
    // 0 - PORTRAIT
    // 1 - LANDSCAPE-LEFT
    // 2 - PORTRAIT-UPSIDEDOWN
    // 3 - LANDSCAPE-RIGHT
    Orientation.addOrientationListener((orientation) => {
      var orientationValue = 0;
      if (orientation === 'PORTRAIT') {
        orientationValue = 0;
      } else if (orientation === 'LANDSCAPE-LEFT') {
        orientationValue = 1;
      } else if (orientation === 'LANDSCAPE-RIGHT') {
        orientationValue = 3;
      }
      console.log('+++++++Orientation+++++++', orientation, orientationValue);
      ZegoUIKit.setAppOrientation(orientationValue);
    });

  }, [])
1
Copied!

Effects

Local Portrait - Remote PortraitLocal Portrait - Remote LandscapeLocal Landscape - Remote PortraitLocal Landscape - Remote Landscape