From 858e95b2aa737b9557cccf4839a925ee1871e311 Mon Sep 17 00:00:00 2001 From: Mehdi Mulani Date: Thu, 22 Sep 2016 12:46:29 -0700 Subject: [PATCH] Warn when displaying a modal with unsupported interface orientations Summary: In dev mode, this removes all iOS crashes from specifying the incorrect interface orientations. It also includes okay-ish instructions for how to fix the problem. Reviewed By: fkgozali Differential Revision: D3904998 fbshipit-source-id: 699599fa77fd87e6615436250e38944e577e75a0 --- React/Views/RCTModalHostViewController.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/React/Views/RCTModalHostViewController.m b/React/Views/RCTModalHostViewController.m index 2a1c94f88fa..b50f660e169 100644 --- a/React/Views/RCTModalHostViewController.m +++ b/React/Views/RCTModalHostViewController.m @@ -9,6 +9,7 @@ #import "RCTModalHostViewController.h" +#import "RCTLog.h" #import "RCTModalHostView.h" @implementation RCTModalHostViewController @@ -50,4 +51,21 @@ return _preferredStatusBarHidden; } +#if RCT_DEV +- (UIInterfaceOrientationMask)supportedInterfaceOrientations +{ + UIInterfaceOrientationMask appSupportedOrientationsMask = [[UIApplication sharedApplication] supportedInterfaceOrientationsForWindow:[[UIApplication sharedApplication] keyWindow]]; + if (!(_supportedInterfaceOrientations & appSupportedOrientationsMask)) { + RCTLogError(@"Modal was presented with 0x%x orientations mask but the application only supports 0x%x." + @"Add more interface orientations to your app's Info.plist to fix this." + @"NOTE: This will crash in non-dev mode.", + (unsigned)_supportedInterfaceOrientations, + (unsigned)appSupportedOrientationsMask); + return UIInterfaceOrientationMaskAll; + } + + return _supportedInterfaceOrientations; +} +#endif + @end