React native 需要反应本机定向实现示例

React native 需要反应本机定向实现示例,react-native,React Native,我是新来的。我在为ios实施定向方面有问题。我试着用反应本族语。我已经阅读了文档,但无论如何都做不到。请不要用诸如“lockToPortrait()、lockToLandscape()或getOrientation(function(err,orientation)”之类的方法回答,我已经读过了。任何人只要用一段工作代码来回答就足够了 感谢var-Orientation=require('react-native-Orientation'); 类YourApp扩展组件{ componentDid

我是新来的。我在为ios实施定向方面有问题。我试着用反应本族语。我已经阅读了文档,但无论如何都做不到。请不要用诸如“lockToPortrait()、lockToLandscape()或getOrientation(function(err,orientation)”之类的方法回答,我已经读过了。任何人只要用一段工作代码来回答就足够了

感谢

var-Orientation=require('react-native-Orientation');
类YourApp扩展组件{
componentDidMount(){
lockToPortrait();
}
render(){
}
}
AppRegistry.registerComponent('YourApp',()=>YourApp);
对我来说很好。

import React,{PureComponent}来自'React';
进口{
看法
文本,
尺寸
}从“反应本机”;
从“反应本机方向”导入方向;
常数{
宽度:设备屏幕宽度,
高度:设备Creenheight
}=Dimensions.get('window');
设aspectRatio=设备屏幕宽度/设备屏幕宽度;
导出默认类Home扩展PureComponent{
建造师(道具){
超级(道具);
}
render(){
返回(
A如果不让此屏幕旋转
)
}//渲染结束
componentDidMount(){
if(设备屏幕宽度>设备屏幕宽度){
方向。锁定到Landscape();
}否则{
lockToPortrait();
}
//这将解除以前对所有方向的所有锁定
//方向。解锁Allorientations();
Orientation.addOrientationListener(此.\u OrientationIDChange);
}
_方向IDChange=(方向)=>{
如果(方向==‘横向’){
//做一些景观布局
}否则{
//做一些肖像布局
}
}

}
添加此项,因为上述任何一项都不能在react native中完成,而无需导入具有维度的库。addEventListener

下面是一个类的示例,可以启动该类在应用程序中删除和添加状态栏

import { Dimensions } from "react-native";

class OrientationChanger {
  constructor() {
    this.update();

    Dimensions.addEventListener("change", () => {
      this.updateOrientation();
    });
  }

  update() {
    if (Dimensions.get("window").width < Dimensions.get("window").height) {
      StatusBar.setHidden(false); // "portrait"
    } else {
      StatusBar.setHidden(true); // "landscape"
    }
  }
}

export default OrientationChanger;
从“react native”导入{Dimensions};
类定向转换器{
构造函数(){
这个.update();
维度。addEventListener(“更改”,()=>{
this.updateOrientation();
});
}
更新(){
if(尺寸获取(“窗口”).宽度<尺寸获取(“窗口”).高度){
StatusBar.setHidden(false);/“肖像”
}否则{
StatusBar.setHidden(true);/“横向”
}
}
}
导出默认方向转换器;

关于如何做到这一点,在线上确实有很多示例和教程。真的吗?关于方向的内容在哪里?通常只有关于react native的内容
import { Dimensions } from "react-native";

class OrientationChanger {
  constructor() {
    this.update();

    Dimensions.addEventListener("change", () => {
      this.updateOrientation();
    });
  }

  update() {
    if (Dimensions.get("window").width < Dimensions.get("window").height) {
      StatusBar.setHidden(false); // "portrait"
    } else {
      StatusBar.setHidden(true); // "landscape"
    }
  }
}

export default OrientationChanger;