Adaptive mobile rotation
Add dependencies.
- Need to upgrade
ZegoUIKit
to version 2.7.0 or above.
Untitled
"@zegocloud/zego-uikit-rn": "^2.7.0",
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
npm install react-native-orientation-locker
1
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
Effects
Local Portrait - Remote Portrait | Local Portrait - Remote Landscape | Local Landscape - Remote Portrait | Local Landscape - Remote Landscape |
---|---|---|---|