Skip to content

Commit

Permalink
add event for window dimension change on active
Browse files Browse the repository at this point in the history
When the app becomes active, check to see if the window size has changed. If so, send a device event with update dimensions.
  • Loading branch information
rdonnelly committed Sep 29, 2018
1 parent 95ba4d5 commit 0c93de2
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions React/Modules/RCTDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@implementation RCTDeviceInfo {
#if !TARGET_OS_TV
UIInterfaceOrientation _currentInterfaceOrientation;
NSDictionary *_currentInterfaceDimensions;
#endif
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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


Expand Down

0 comments on commit 0c93de2

Please sign in to comment.