支持的方向与应用程序没有共同的方向,并且 [RCTModalHostViewController shouldAutorotate] 返回 YES

Tal*_*ani 3 landscape popover ios react-native

我在 iOS 上有本机反应的应用程序,我通过执行以下操作将其锁定在横向模式:

componentDidMount() {
Orientation.lockToLandscape()
}
Run Code Online (Sandbox Code Playgroud)

我添加了一个弹出窗口,但是当我按下它时,我收到了这个错误:

 Exception thrown while executing UI block:
 Supported orientations has no common orientation with the application,
 and [RCTModalHostViewController shouldAutorotate] is returning YES
Run Code Online (Sandbox Code Playgroud)

在 app.delegate 上我添加了这个功能:

 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
while ([[UIDevice currentDevice] isGeneratingDeviceOrientationNotifications]) {
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
 }

 return [Orientation getOrientation];
   }
Run Code Online (Sandbox Code Playgroud)

在肖像上这个错误没有发生

怎么解决。。。谢谢

小智 7

我找到了这个问题的根本原因。这发生在模态窗口中。我的视频在模态窗口中打开,当我从纵向更改为横向时,出现此错误。

解决方案:

<Modal
  visible={true}
  supportedOrientations={['portrait', 'landscape']}
>
Run Code Online (Sandbox Code Playgroud)