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

时间:2018-07-05 10:31:35

标签: react-native react-native-navigation

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

我正在将startSingleScreenApp与方向为“纵向”的appStyle一起使用以强制使用纵向屏幕。我只想让其中一个推屏使用“自动”

我尝试了以下方法:

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

我也尝试过:

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

我什至使用以下命令推到屏幕上

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

甚至可以动态更改它吗?

1 个答案:

答案 0 :(得分:2)

可以通过使用“反应本机定向”来实现。它将侦听React Native应用程序中的设备方向更改,并以编程方式在每个屏幕上设置首选方向。它适用于Android和iOS。请在下面的链接中获取更多详细信息:

     <?php foreach ($itinerary['outbound']['flights'] as $flight ){
     echo count($flight['flights']);
     }?>

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

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();

您可以在共享链接中找到详细的说明/指南。您可以根据需要添加逻辑。希望对您有帮助。

相关问题