React Native 集成 react-native-orientation(横竖屏插件)以及代码示例
1、安装
- 官方链接:https://www.npmjs.com/package/react-native-orientation
#安装
npm install react-native-orientation --save
#链接所有依赖
react-native link react-native-orientation
2、官方API
#锁定为竖屏
lockToPortrait()
#锁定为横屏
lockToLandscape()
#锁定为左竖屏
lockToLandscapeLeft()
#锁定为右竖屏
lockToLandscapeRight()
#解除所有锁定
unlockAllOrientations()
#得到当前屏幕的信息
getOrientation((err, orientation) => {})
getSpecificOrientation((err, specificOrientation) => {})
3、添加、移除监听
Orientation.addOrientationListener((orientation)=>{
});
Orientation.addSpecificOrientationListener((specificOrientation)=>{
});
removeOrientationListener((orientation)=> {
});
removeSpecificOrientationListener((specificOrientation)=> {
});
4、代码示例
import React, {
Component} from 'react';
import {
Button, StyleSheet, Text, View} from 'react-native';
import Orientation from