Skip to content

Commit 0023d5c

Browse files
committed
add event for window dimension change on active
When the app becomes active, check to see if the window size has changed. If so, send a device event with update dimensions.
1 parent bf0ae93 commit 0023d5c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

React/Modules/RCTDeviceInfo.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
@implementation RCTDeviceInfo {
1717
#if !TARGET_OS_TV
1818
UIInterfaceOrientation _currentInterfaceOrientation;
19+
NSDictionary *_currentInterfaceDimensions;
1920
#endif
2021
}
2122

@@ -48,6 +49,13 @@ - (void)setBridge:(RCTBridge *)bridge
4849
selector:@selector(interfaceOrientationDidChange)
4950
name:UIApplicationDidChangeStatusBarOrientationNotification
5051
object:nil];
52+
53+
_currentInterfaceDimensions = RCTExportedDimensions(_bridge);
54+
55+
[[NSNotificationCenter defaultCenter] addObserver:self
56+
selector:@selector(interfaceFrameDidChange)
57+
name:UIApplicationDidBecomeActiveNotification
58+
object:nil];
5159
#endif
5260
}
5361

@@ -160,6 +168,31 @@ - (void)_interfaceOrientationDidChange
160168
_currentInterfaceOrientation = nextOrientation;
161169
}
162170

171+
172+
- (void)interfaceFrameDidChange
173+
{
174+
__weak typeof(self) weakSelf = self;
175+
RCTExecuteOnMainQueue(^{
176+
[weakSelf _interfaceFrameDidChange];
177+
});
178+
}
179+
180+
181+
- (void)_interfaceFrameDidChange
182+
{
183+
NSDictionary *nextInterfaceDimensions = RCTExportedDimensions(_bridge);
184+
185+
if (!([nextInterfaceDimensions isEqual:_currentInterfaceDimensions])) {
186+
#pragma clang diagnostic push
187+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
188+
[_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions"
189+
body:RCTExportedDimensions(_bridge)];
190+
#pragma clang diagnostic pop
191+
}
192+
193+
_currentInterfaceDimensions = nextInterfaceDimensions;
194+
}
195+
163196
#endif // TARGET_OS_TV
164197

165198

0 commit comments

Comments
 (0)