React Native 集成 react-native-orientation(横竖屏插件)以及代码示例

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 将返回以下值之一:
 *
 * LANDSCAPE
 * PORTRAIT
 * PORTRAITUPSIDEDOWN
 * UNKNOWN
 */
 Orientation.addOrientationListener((orientation)=>{
   });
 /**
   * specificOrientation 将返回以下值之一:
   *
   * LANDSCAPE-LEFT
   * LANDSCAPE-RIGHT
   * PORTRAIT
   * PORTRAITUPSIDEDOWN
   * UNKNOWN
   */
 Orientation.addSpecificOrientationListener((specificOrientation)=>{
   });

 //移除监听
 removeOrientationListener((orientation)=> {
   };
 removeSpecificOrientationListener((specificOrientation)=> {
   };

4、代码示例

import React, {
   Component} from 'react';
import {
   Button, StyleSheet, Text, View} from 'react-native';
import Orientation from 'react-native-orientation';


expor
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值