|
16 | 16 | @implementation RCTDeviceInfo {
|
17 | 17 | #if !TARGET_OS_TV
|
18 | 18 | UIInterfaceOrientation _currentInterfaceOrientation;
|
| 19 | + NSDictionary *_currentInterfaceDimensions; |
19 | 20 | #endif
|
20 | 21 | }
|
21 | 22 |
|
@@ -48,6 +49,13 @@ - (void)setBridge:(RCTBridge *)bridge
|
48 | 49 | selector:@selector(interfaceOrientationDidChange)
|
49 | 50 | name:UIApplicationDidChangeStatusBarOrientationNotification
|
50 | 51 | object:nil];
|
| 52 | + |
| 53 | + _currentInterfaceDimensions = RCTExportedDimensions(_bridge); |
| 54 | + |
| 55 | + [[NSNotificationCenter defaultCenter] addObserver:self |
| 56 | + selector:@selector(interfaceFrameDidChange) |
| 57 | + name:UIApplicationDidBecomeActiveNotification |
| 58 | + object:nil]; |
51 | 59 | #endif
|
52 | 60 | }
|
53 | 61 |
|
@@ -77,16 +85,23 @@ static BOOL RCTIsIPhoneX() {
|
77 | 85 | RCTAssertMainQueue();
|
78 | 86 |
|
79 | 87 | RCTDimensions dimensions = RCTGetDimensions(bridge.accessibilityManager.multiplier);
|
80 |
| - typeof (dimensions.window) window = dimensions.window; // Window and Screen are considered equal for iOS. |
81 |
| - NSDictionary<NSString *, NSNumber *> *dims = @{ |
| 88 | + typeof (dimensions.window) window = dimensions.window; |
| 89 | + NSDictionary<NSString *, NSNumber *> *dimsWindow = @{ |
82 | 90 | @"width": @(window.width),
|
83 | 91 | @"height": @(window.height),
|
84 | 92 | @"scale": @(window.scale),
|
85 | 93 | @"fontScale": @(window.fontScale)
|
86 | 94 | };
|
| 95 | + typeof (dimensions.screen) screen = dimensions.screen; |
| 96 | + NSDictionary<NSString *, NSNumber *> *dimsScreen = @{ |
| 97 | + @"width": @(screen.width), |
| 98 | + @"height": @(screen.height), |
| 99 | + @"scale": @(screen.scale), |
| 100 | + @"fontScale": @(screen.fontScale) |
| 101 | + }; |
87 | 102 | return @{
|
88 |
| - @"window": dims, |
89 |
| - @"screen": dims |
| 103 | + @"window": dimsWindow, |
| 104 | + @"screen": dimsScreen |
90 | 105 | };
|
91 | 106 | }
|
92 | 107 |
|
@@ -163,6 +178,31 @@ - (void)_interfaceOrientationDidChange
|
163 | 178 | _currentInterfaceOrientation = nextOrientation;
|
164 | 179 | }
|
165 | 180 |
|
| 181 | + |
| 182 | +- (void)interfaceFrameDidChange |
| 183 | +{ |
| 184 | + __weak typeof(self) weakSelf = self; |
| 185 | + RCTExecuteOnMainQueue(^{ |
| 186 | + [weakSelf _interfaceFrameDidChange]; |
| 187 | + }); |
| 188 | +} |
| 189 | + |
| 190 | + |
| 191 | +- (void)_interfaceFrameDidChange |
| 192 | +{ |
| 193 | + NSDictionary *nextInterfaceDimensions = RCTExportedDimensions(_bridge); |
| 194 | + |
| 195 | + if (!([nextInterfaceDimensions isEqual:_currentInterfaceDimensions])) { |
| 196 | +#pragma clang diagnostic push |
| 197 | +#pragma clang diagnostic ignored "-Wdeprecated-declarations" |
| 198 | + [_bridge.eventDispatcher sendDeviceEventWithName:@"didUpdateDimensions" |
| 199 | + body:nextInterfaceDimensions]; |
| 200 | +#pragma clang diagnostic pop |
| 201 | + } |
| 202 | + |
| 203 | + _currentInterfaceDimensions = nextInterfaceDimensions; |
| 204 | +} |
| 205 | + |
166 | 206 | #endif // TARGET_OS_TV
|
167 | 207 |
|
168 | 208 |
|
|
0 commit comments