首页 文章

如何动态设置推送屏幕的方向 - React-Native-Navigation

提问于
浏览
0

我想知道如何使用react-native-navigation动态更改推送屏幕的方向 .

我正在使用startSingleScreenApp和一个方向的appStyle:'portrait'来强制纵向屏幕 . 我希望只有一个推动的屏幕使用'auto'

我尝试过以下方法:

static navigatorStyle = {
   drawUnderTabBar: true,
   orientation: 'auto'
};

我也尝试过:

componentWillMount() {
   this.props.navigator.setStyle({
      orientation: 'auto'
   });
};

我甚至用以下方式推到了屏幕:

...
navigatorStyle: {
  orientation:'auto'
}
...

甚至可以动态改变它吗?

1 回答

  • 1

    它可以通过使用"React Native Orientation"来实现 . 它将在React Native应用程序中监听设备方向更改,并以编程方式在每个屏幕上设置首选方向 . 它适用于Android和iOS . 请在下面链接了解更多详情:

    https://github.com/yamill/react-native-orientation
    

    您可以按如下方式使用它:

    import Orientation from 'react-native-orientation';
    
    // this locks the view to Portrait Mode. Need to add this in your screens 
     componentDidMount function
    Orientation.lockToPortrait();
    

    要么

    // this locks the view to Landscape Mode. Need to add this in your screens 
     componentDidMount function
     Orientation.lockToLandscape();
    

    您可以在共享链接中找到详细的说明/指南 . 您可以根据需要相应地添加逻辑 . 希望它会对你有所帮助 .

相关问题