diff --git a/React/Modules/RCTDeviceInfo.m b/React/Modules/RCTDeviceInfo.m index 0e4ffa7e7aa42b..f607508156d592 100644 --- a/React/Modules/RCTDeviceInfo.m +++ b/React/Modules/RCTDeviceInfo.m @@ -16,6 +16,7 @@ @implementation RCTDeviceInfo { #if !TARGET_OS_TV UIInterfaceOrientation _currentInterfaceOrientation; + NSDictionary *_currentInterfaceDimensions; #endif } @@ -48,6 +49,13 @@ - (void)setBridge:(RCTBridge *)bridge selector:@selector(interfaceOrientationDidChange) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil]; + + _currentInterfaceDimensions = RCTExportedDimensions(_bridge); + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(interfaceFrameDidChange) + name:UIApplicationDidBecomeActiveNotification + object:nil]; #endif } @@ -165,6 +173,31 @@ - (void)_interfaceOrientationDidChange _currentInterfaceOrientation = nextOrientation; } + +- (void)interfaceFrameDidChange +{ + __weak typeof(self) weakSelf = self; + RCTExecuteOnMainQueue(^{ + [weakSelf _interfaceFrameDidChange]; + }); +} + + +- (void)_interfaceFrameDidChange +{ + NSDictionary *nextInterfaceDimensions = RCTExportedDimensions(_bridge); + + if (!([nextInterfaceDimensions isEqual:_currentInterfaceDimensions])) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + [_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions" + body:RCTExportedDimensions(_bridge)]; +#pragma clang diagnostic pop + } + + _currentInterfaceDimensions = nextInterfaceDimensions; +} + #endif // TARGET_OS_TV