From 2444c54654807eb5a42d0cf67fe86a69fbb5a8a1 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 28 Jul 2017 02:57:35 -0700 Subject: [PATCH] Fix crash for unsupported device orientation events Reviewed By: mmmulani Differential Revision: D5507716 fbshipit-source-id: 061a3060a5ea216028b1fbae81256d17db7f4b2f --- React/Modules/RCTUIManager.m | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index e33be2c51bd..24c80780462 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -206,7 +206,10 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation) degrees = @90; isLandscape = YES; break; - default: + case UIDeviceOrientationFaceDown: + case UIDeviceOrientationFaceUp: + case UIDeviceOrientationUnknown: + // Unsupported return nil; } return @{ @@ -218,11 +221,15 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation) - (void)namedOrientationDidChange { - UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; + NSDictionary *orientationEvent = deviceOrientationEventBody([UIDevice currentDevice].orientation); + if (!orientationEvent) { + return; + } + #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" [_bridge.eventDispatcher sendDeviceEventWithName:@"namedOrientationDidChange" - body:deviceOrientationEventBody(deviceOrientation)]; + body:orientationEvent]; #pragma clang diagnostic pop } #endif